News for hackers. Stuff that matters.
Re:D-style Mixins in C# by p0nce on Thursday August 30, 2012 @04:18PM (#4456527)
D "string mixins" allow to insert any string as code, usually the result of a compile-time computation.

Some use cases:

- make repetitive code shorter [1]. Think the C preprocessor but after the parsing stage.

- operator overloading is a single template function parameterized by a compile-time string. This more or less requires using string mixins [2].

- [edit] raleks's comment has better examples [3].

Overall string mixins feel a bit dirty but you get used to it. D also has "template mixins" which do not escape parsing prior instantiation.

D mixins are neither like Scala mixins nor Ruby mixins.

[1] https://github.com/p0nce/gfm/blob/master/math/easing.d#L64.

[2] https://github.com/Dav1dde/gl3n/blob/master/gl3n/linalg.d#L2...

[3] http://news.ycombinator.com/item?id=4456422

There are no comments on this comment yet.