views:

591

answers:

1
+2  Q: 

Mixins vs. Traits

What is the difference between Mixins and Traits?

According to Wikipedia, Ruby Modules are sort of like traits. How so?

+1  A: 

These pages explain the difference in the D Programming language.

http://www.digitalmars.com/d/2.0/mixin.html

http://www.digitalmars.com/d/2.0/traits.html

Mixins in this context are code generated on the fly, and then inserted at that point in code during compilation. Quite handy for simple DSLs.

Traits are compile-time external values (rather than code generated from an external source). The difference is subtle. Mixins add logic, Traits add data such as compile-time type information.

Don't know much about Ruby, but hope this helps somewhat.

Aiden Bell