Mixins vs. Traits

前端 未结 2 896
梦毁少年i
梦毁少年i 2020-12-02 04:11

What is the difference between Mixins and Traits?

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

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 04:53

    These pages explain the difference in the D Programming language.

    http://dlang.org/mixin.html

    http://dlang.org/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.

提交回复
热议问题