PHP is not a comp-sci guru language. It's an engineer's language.
1. It's easy
2. It's powerful
3. It's fast enough for most tasks
About 1:
Developers moaned about language inconsistencies since about forever, but the fact is that this is not a big problem as some think it is.
Q: Is it find(haystack, needle), or find(needle, haystack)? A: I do not care. I can not remember syntax of all functions in the language anyway, not to mention frameworks, but the online documentation for that function is one click away. And if I'm using an IDE, I get a tooltip to tell me.
I can pick up most php libraries / frameworks out there, plug them in my app, and if I find a problem debug it and patch it in half an hour. This might be true for other languages, but definitely not Java or Perl.
Loose typing is actually a good choice 99% of the time when writing an app. When writing a framework/library it's probably the opposite. But how many developers are writing apps compared to frameworks?
Think about the function validatePassword(string $p1, string $p2) versus validatePassword($username, $password)
. Which one is typesafe? Which one is gonna be abused by the caller?
Heck, even the choice not to have private/protected/public members in classes (for php4) really makes sense in the context of an application. How many times are you going to subclass a class which is specific to the business-logic problem at hand? If you're not going to subclass, all the time you spend thinking about this particular aspect is wasted.
Making the language clean up for yourself at the end of every web page means that things like global variables, generally despised in other languages, are not a bad practice anymore. Purists yell when they see it, but it's only because they have not yet understood the scoping implication of the one-page-one-scrip approach.
About 2:
Want to hack a bit of script in an html page? super fast.
Want to code purely oop? can be done.
Like lambdas and closure? Can be done too (ok, not the best implementation out there, but still...)
About 3:
I like my hashes to be as simple as arrays. I rarely mix them up - depending on context (or the value of the variable at hand) I can figure out which one of the two is in use. So my array construct is slower than in any other known language. Thing is, for making websites the page speed is nowadays wasted mostly 1-in frontend rendering of all the js and css, and 2-in the db query or nosql fetch. Array manipulation is gonna be 0.1% of it.
Posted Mar 4, 2012 1:57 UTC (Sun) by tialaramex (subscriber, #21167)
[Link]
Whatever it is, it's not for engineers. Engineers care about maintenance, and PHP isn't maintainable.
PHP encourages spaghetti, encourages bad practices like using string concatenation instead of parameter binding, even encourages the "copy paste" approach to code-reuse. And so on through a litany of maintenance-hostile behaviours.
It has taken long painful years to beat the worst security mis-features out of PHP. It may be decades before the knock-on effects reach the many PHP "applications" (if piles of accumulated PHP may be so-called) that have grown up while such mis-features existed.
PHP 5.4.0 released
Posted Mar 4, 2012 12:59 UTC (Sun) by DG (subscriber, #16978)
[Link]
PHP is maintainable - if you set about it in the right way using good software engineering practices - code style guidelines, unit tests, reviews, CI etc.
I'm not sure why you think PHP encourages copy+paste coding more than any other language. If it does, it's probably because of it's low barrier to entry which results in some less skilled/proficient people writing it.
PHP 5.4.0 released
Posted Mar 4, 2012 15:41 UTC (Sun) by anselm (subscriber, #2796)
[Link]
PHP is maintainable - if you set about it in the right way using good software engineering practices - code style guidelines, unit tests, reviews, CI etc.
Anything is maintainable if you're investing enough care and effort. People are maintaining large assembly language programs, after all. The real question is whether maintaining something in PHP or assembly language is worth the trouble when there are lots of other approaches that let you achieve the same level of maintainability with less effort (while probably also improving all sorts of other quality metrics to boot). In the case of assembly language, most people have figured out for themselves what they prefer, which is why there are much fewer large assembly language programs around than there used to be.
Having said that, PHP is great. It is the best thing since the invention of sliced bread. Everybody should be using PHP all the time. It would make us Django people look so much more competent and efficient by comparison.
PHP 5.4.0 released
Posted Mar 4, 2012 17:45 UTC (Sun) by man_ls (subscriber, #15091)
[Link]
IME proper engineering is not harder to do in PHP than in other languages; and some things like, you know, serving web pages is actually easier. I have not worked with Python or Ruby frameworks though; only with Java frameworks which grow more byzantine by the year. But people are even suggesting Scala here, so I guess their tolerance for the bizarre must be quite high.
PHP 5.4.0 released
Posted Mar 4, 2012 16:26 UTC (Sun) by HelloWorld (guest, #56129)
[Link]
About 1: PHP isn't easier than Python. And no, weak typing is *not* a good idea, ever. It only makes things easier that are trivial to begin with, in the best case you save a few casts here and there. On the other hand, it encourages people to write code that'll work just fine as long as the input is what the programmer expected it to be, and fail catastropically when it's not.
About 2: embedding Python (or Ruby or Perl) is trivial using modules such as Spyce. And of course, Python has had lambdas, closures and proper OOP for way longer than PHP.
About 3: there's no sensible reason for mixing up arrays with dictionaries, they're simply different things. That doesn't imply that one is harder to use than the other (as can be seen in Python).
So sorry, but I don't buy those arguments. IMO, PHP does nothing better than the alternatives I've listed, and you haven't proven otherwise.
PHP 5.4.0 released
Posted Mar 5, 2012 9:07 UTC (Mon) by ggiunta (guest, #30983)
[Link]
And you have not proven in any way that "all the alternatives" you mentioned above are better than php, either - esp. Perl...
But to each its own, I guess
PHP 5.4.0 released
Posted Mar 5, 2012 12:40 UTC (Mon) by HelloWorld (guest, #56129)
[Link]
> And you have not proven in any way that "all the alternatives" you mentioned above are better than php, either - esp. Perl...
Perl has had *everything* for years that is "new" in PHP 5.4. Same thing with the 5.3 release. Plus it has proper Unicode support which PHP lacks to this day.
Also, I am not the one who started this discussion by asserting random stuff like PHP being irreplaceable, Kit is the one who should explain why he things this is so.