A Different Way: Traits in PHP
lucasoman.blogspot.comPerhaps if you need traits, you're doing it wrong. Does PHP really need all the added complexity of this? Does it really help solve the problem or did you just add a new maintenance nightmare?
Honestly, what did you expect? The link was called "Traits in PHP." The article described the initial constraint as being "stuck in PHP." This wasn't an article arguing that it's a good idea to do it, but more of an exercise.
So your questions, does PHP really need all the added complexity of this?
That doesn't matter. If you don't need it, don't use it.
Does it really help solve the problem, or did you just add a new maintenance nightmare?
This question is a false dichotomy. First, it wasn't trying to solve any other problem then getting traits to work. So yeah, it solved that problem. Second, new code always adds new maintenance concerns. Whether or not it's a nightmare depends on the quality of code, which seems to be above par in this case.
As Nycto pointed out in this thread, there is a "Traits" patch which seems preferable to this code. It's likely that OP didn't realize it existed and did reinvent the wheel. But still, in terms of an exercise in PHP, I found it quite cool.
I completely agree. If Traits are something you really need, you're using the wrong language. If you need a screw driver, get a screw driver. Don't try to use the claw of a hammer. Developing with something like this will only increase the spaghetti factor. If you are a stickler for code re-use, my suggestion is to favor Composition over Inheritance.
It's also worth noting that PHP will most likely be adding Traits into the core language at some point. A patch has been available since 2008:
http://wiki.php.net/rfc/traits
Hell, if you really need traits (you don't), apply the patch. Just don't mutilate your code base.
This article has spent an hour or two on the front page with no discussion. I've always wondered what that means; perhaps in this situation, it means that YC's active commenters aren't active PHP developers?
Regardless, I think this is a pretty cool idea. It seems like a lot of effort to emulate what's (arguably) a missing language feature, but for those of us who are stuck in PHP for one reason or another, it's an interesting development.
Yeah, it sounds kinda nice to me. But that' because I'm stuck with PHP for the time being. I'm tired of fighting the language though, so creating these kinds of hacks just becomes more of an intellectual exercise.
And I think you're right that YC's commenters are by and large not PHP developers. I've only known a couple of real hackers that work in PHP, and even they didn't work in it by choice. Though it makes me a little sad to say this because PHP was the first language I learned (hooray sentiment!), I hope PHP dies off soon. It has matured in recent years, but unfortunately not in any new directions. I'm gonna go out on a limb and say that the vast majority of PHP programmers are idiots who couldn't code their way out of a paper bag, and the better PHP hackers tend to be enterprise-y, as that's the direction PHP is headed nowadays.
I tend to agree, but I'll fully admit, I'm a PHP hacker and I've been hacking in it since around 1999 or so. I didn't see this as much of a hack (read parts of the paper associated with it) as much as a way to do some cooler things in 5.3.
I consider myself a pretty good PHP programmer, but you're right, most of them out there don't deserve the title "programmer". I'm so disgusted by 99% of the open source PHP crap out there.
That said, I do look forward to learning new languages and new ways to develop on the web (what I really love doing).
That's the situation I find myself in: a developer stuck with PHP.
In response to the first bit, a friend observed that Warnock applies.