Conversation started Jul 20, 2012 at 1:43.
user895378
Jul 20, 2012 01:43
@hakre And here comes the trait avalanche ...
user895378
The linked traits pdf really doesn't do anything for me.
user895378
My biggest issue is that traits undermine what you're trying to achieve in terms of object orientation. I'd say they're not entirely dissimilar to static class methods in that regard. And while they don't necessarily introduce state issues like static usages can, they do put you on the fast-track to class-based programming. I view traits like a static method scaled up to the level of class abstraction.
user895378
The only tangible benefit of traits (that I can see) is code re-use. Consider: this is the exact same
reason people use for static utility class methods.
user895378
But if you're employing sound OO principles you already have this benefit without traits. For example, adhering to the Single Responsibility Principle means you already have small, modular and fully re-usable units of code. This makes redeploying useful classes in different contexts a triviality: you simply inject your existing units of functionality directly into the classes that need them: it's code re-use without traits.
user895378
Further, there's no more transparent API than the one that asks for its dependencies directly in the constructor. When classes use composition there's no question about what they can do or which modular code units they use to do it.
user895378
Jul 20, 2012 01:44
The other reason I see people using to justify traits is, "My code is just too complex for single inheritance. If you saw the business logic I have to deal with you'd agree that traits are necessary."
user895378
Using traits in this situation is like buying a car to walk your dog: you're solving the wrong problem.
user895378
The real problem is the incomplete or undeveloped design of the code; that is the reason why the design is complex in the first place. I always know when I've hit on the right design because it's so simple it almost seems inadequate. That said, all design is an iterative process and you rarely hit on the right design the first time. If I think I need traits it's a sign to me that I haven't got the right design yet, and I keep working.
user895378
(the end)
 
Conversation ended Jul 20, 2012 at 1:45.