Not logged in
Log in now
Create an account
Subscribe to LWN
LWN.net Weekly Edition for May 23, 2013
An "enum" for Python 3
An unexpected perf feature
LWN.net Weekly Edition for May 16, 2013
A look at the PyPy 2.0 release
But please, answer me one question: what is PHP actually better at than the alternatives I've pointed out? Because I can't think of anything.
PHP 5.4.0 released
Posted Mar 3, 2012 11:19 UTC (Sat) by ggiunta (guest, #30983)
1. It's easy
2. It's powerful
3. It's fast enough for most tasks
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.
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...)
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)
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.
Posted Mar 4, 2012 12:59 UTC (Sun) by DG (subscriber, #16978)
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.
Posted Mar 4, 2012 15:41 UTC (Sun) by anselm (subscriber, #2796)
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.
Posted Mar 4, 2012 17:45 UTC (Sun) by man_ls (subscriber, #15091)
Posted Mar 4, 2012 16:26 UTC (Sun) by HelloWorld (guest, #56129)
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.
Posted Mar 5, 2012 9:07 UTC (Mon) by ggiunta (guest, #30983)
But to each its own, I guess
Posted Mar 5, 2012 12:40 UTC (Mon) by HelloWorld (guest, #56129)
Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds