News for hackers. Stuff that matters.
Re:Stackable Traits Pattern in Scala by jbooth on Tuesday February 16, 2016 @10:14AM (#11110310)
Not really, at all. Order the traits differently and you can get different behavior. Inherit one subtrait vs another and you can get different behavior. You can reason about all of this, but I'm not that smart, so I prefer composition.

Composition locks away the behavior you want so that you know exactly what you're getting.

Re:Stackable Traits Pattern in Scala by twic on Tuesday February 16, 2016 @02:53PM (#11112663)
I don't get it. If you're decorating, then ordering the decorators differently gets you different behaviour. It's exactly the same.

Indeed, you could write a straightforward mechanical method to convert any trait stacking into a decoration.

Re:Stackable Traits Pattern in Scala by jbooth on Tuesday February 16, 2016 @10:31PM (#11115053)
Yeah -- I'm arguing for composition because it's harder to screw up, at the cost of being less pretty. The manner and order in which composed objects are delegated to is crystal clear if you're wiring them yourself (or with your IDE). I've seen some messy, confusing code involving traits and just slapping 'with Thingy' 10 times in a row. The phrase 'emergent behavior' is how I would best describe it.