www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - template mixins vs. string mixins

reply Trass3r <un known.com> writes:
In the past template mixins were a neat special usecase of templates. Now  
with the "mixin template()" syntax they've become a separate thing because  
you can add special code for handling them, e.g. allowing them to add  
constructors to classes.

The question is: what is their right to exist? Is there anything you can  
do with them you can't with string mixins (or vice versa)?
Nov 06 2010
next sibling parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
Trass3r <un known.com> wrote:

 In the past template mixins were a neat special usecase of templates.  
 Now with the "mixin template()" syntax they've become a separate thing  
 because you can add special code for handling them, e.g. allowing them  
 to add constructors to classes.

 The question is: what is their right to exist? Is there anything you can  
 do with them you can't with string mixins (or vice versa)?

String mixins are, strictly speaking, more powerful than template mixins. However, the syntax is unwieldy in comparison. -- Simen
Nov 06 2010
prev sibling parent reply Don <nospam nospam.com> writes:
Trass3r wrote:
 In the past template mixins were a neat special usecase of templates. 
 Now with the "mixin template()" syntax they've become a separate thing 
 because you can add special code for handling them, e.g. allowing them 
 to add constructors to classes.
 
 The question is: what is their right to exist? Is there anything you can 
 do with them you can't with string mixins (or vice versa)?

I've personally never seen a use for template mixins.
Nov 06 2010
next sibling parent div0 <div0 sourceforge.net> writes:
On 06/11/2010 10:13, Don wrote:
 Trass3r wrote:
 In the past template mixins were a neat special usecase of templates.
 Now with the "mixin template()" syntax they've become a separate thing
 because you can add special code for handling them, e.g. allowing them
 to add constructors to classes.

 The question is: what is their right to exist? Is there anything you
 can do with them you can't with string mixins (or vice versa)?

I've personally never seen a use for template mixins.

They are handly for boiler plate code that you sometimes just can't avoid. When you do that stuff template mixins are nicer to work with than string mixins, but I keep hitting forward reference bugs with them in newer versions of DMD so they've become less useful. -- My enormous talent is exceeded only by my outrageous laziness. http://www.ssTk.co.uk
Nov 06 2010
prev sibling next sibling parent Jacob Carlborg <doob me.com> writes:
On 2010-11-06 11:13, Don wrote:
 Trass3r wrote:
 In the past template mixins were a neat special usecase of templates.
 Now with the "mixin template()" syntax they've become a separate thing
 because you can add special code for handling them, e.g. allowing them
 to add constructors to classes.

 The question is: what is their right to exist? Is there anything you
 can do with them you can't with string mixins (or vice versa)?

I've personally never seen a use for template mixins.

They can be used as a form of attributes/annotations. They can also be used for simulating multiple inheritance. Extract the content of a class into a template and write an interface for the class. -- /Jacob Carlborg
Nov 06 2010
prev sibling parent Trass3r <un known.com> writes:
 They are handly for boiler plate code that you sometimes just can't  
 avoid.

 When you do that stuff template mixins are nicer to work with than  
 string mixins

Yeah, mixin string generation functions are just cumbersome and unreadable.
Nov 06 2010