Show HN: PHP does Meta Programming too
gist.github.com
gist.github.com
I guess the Java envy is strong. But why would I want to read and write ersatz Java, or ersatz Ruby, when I could use the real thing?
This is the perennial argument of the feature addict, but it isn't really true.
I suppose you can ignore core language features if you never read or fix any code but your own. But in a few years this new stuff is likely to start cropping up in the source code of Drupal modules and Wordpress themes and the PHP frameworks, and if that happens there will be little choice but to deal with it.
The bigger problem is PHP contributor resources. When you add a core feature, that feature needs to be supported forever. The time you spend supporting it is time you could have spent fixing other things. Worse, the effect is nonlinear: Each new feature potentially interacts with all existing features, increasing your surface area for bugs. In extreme cases, you approach an event horizon where you can no longer ship anything.
The painful thing about the latter effect is that it happens even if the new feature almost never gets used. One might end up doing 20% more QA and maintenance to support 0.1% of one's customers.
You are absolutely right in one sense: If one simply abandons PHP altogether one need never deal with it again. The thought has occurred to me. Pity about the hundreds of thousands of existing customers, though.
Not adding painfully needed features such as traits and closures (which got similar comments before that) just because it would make life harder for those who don't enjoy/want to code in php anymore would in my opinion be a bad thing.
As a bit of an exercise I went through and did the equivalent in Ruby (implement a class, test adding properties and methods) just to see how it'd look: https://gist.github.com/1183334 (Slimmed down versions of both came to 118 and 50 lines for PHP and Ruby respectively.)
I'm happy Traits are coming to PHP, but given I haven't yet been able to use any PHP 5.3 features in any production environment outside of hobby projects, I'm awfully glum about the prospect of being able to make use of them any time in the next couple of years.
good fun indeed, you still have to be aware of a lot of php quirks though to make your code secure.
My biggest beef with PHP is that there is such a chasm between the procedural style at the object oriented one. This is mostly caused by PHP adopting a static class model (a really odd choice for an otherwise highly dynamic language). On the plus side, this tends to cause fewer surprises than you see in languages with a more dynamic object model.
see my fork.
You are probably referring to the mountains of crappy PHP code? About the inconsistent order of 'haystack' and 'needle', or the lack of a common policy on whether or not to use a underscore as separator? Those are valid complaints, but no argument against improvement of the language. On the contrary, I would say.
It is fairly annoying to have any differences, but it's fairly easy to remember them.