mixin + CTFE, to big a hammer??

janderson askme at me.com
Fri Mar 2 19:16:44 PST 2007


Mikola Lysenko wrote:
> kris Wrote:
>> D mixin, in it's current guise, is about equivalent to crack-cocaine. 
>> Easily the worst thing that happened to the language, IMO.
>>
>> Just say no
> 
> At this point I am inclined to agree.
> 
> Initially, I was skeptical about mixins, but I was also intrigued by the potential meta programming improvements.  One important problem that I do not know how to solve without mixins is the creation of a set of patterned names.  As a case study think of the swizzle operators for a vector class.  You need functions like, x, yx, xyz, zyx, zzy etc.  These functions can be trivially enumerated by a computer program, which makes them good candidates for automatic generation.  The mixin statement is enormously helpful in simplifying this code.
> 
> However, there are simply too many hazards with the mixin statement.  Mixins are not lexically closed - you can very easily mess with names from the exterior scope.  They suffer many of the problems encountered in the C preprocessor.  Excessive use of mixins and metaprogramming causes compile times to balloon to ridiculous lengths, far exceeding even the horrors of C++.  The net effect is that they undo many of the advantages D once held.
> 
> My belief is that the basic problems with mixins result from their reliance on string manipulation for meta programming - rather than syntactic and structural concepts.  If we want to create mixin like behaviors (and I think that ultimately it is a good goal) they need to be presented in the logical context of a program manipulator - not a text processor.  The current mixin syntax needs to be aborted before we go any farther down this line of thought.  The longer it sticks around in the language, the harder it is going to be to kill. 
> 
> I vote it gets axed in the next release.
> 
> -Mik

I strongly disagree, we haven't even realized the full potential of 
mixins yet.  I hope they get ingained in D because people realize they 
are not the same as C++ macros.  They give D the potential to evolve far 
beyond anything that C++ could ever offer.

-Joel




More information about the Digitalmars-d-announce mailing list