Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are Traits good or bad?

This is an open-ended question, but I would like to solicit some opinions from the SO community on Traits; do you think Traits in Squeak/Pharo are a good thing, or should you stay away from them and use composition and delegation instead? I ask because while I know how to use them (thanks to the Pharo book), I am not really sure how acceptable it is to use them or where it is OK to use them and where it isn't.

like image 628
giuseppe Avatar asked Jul 12 '10 05:07

giuseppe


1 Answers

I do not like traits because they introduce strong dependencies into code. These dependencies can be obvious (a class that imports a trait, a trait that expects methods), but also very subtle (a trait that shadows super methods/instance variables). Furthermore there is no adequate tool support for traits.

In my experience delegation gives a much better and more reusable design in a dynamically typed object-oriented language like Smalltalk.

like image 51
Lukas Renggli Avatar answered Sep 22 '22 02:09

Lukas Renggli