How should this be done? (1.0)

Michael Coupland mcoupland at gmail.com
Tue Feb 5 21:54:28 PST 2008


Correct me if I'm wrong, but I think it has several of the same problems 
that a normal macro has. Compiler errors in the heredoc string will be 
reported on the wrong line (presumably debuggers would have similar 
problems) and if you want to parameterize your mixin you run the risk of 
textual duplication. There's also the annoyance that text editors may 
fail to properly format the text (having an editor that doesn't 
recognize my heredoc syntax is helpful in this case.)

Derek Parnell wrote:
> On Mon, 04 Feb 2008 21:49:50 -0800, Michael Coupland wrote:
> 
>> I considered a heredoc string and doing a proper textual 
>> mixin, but that feels like overkill...
> 
> What is 'overkill' about this ...
> 
> const char[] CommonCalculations =
> r"
>       bool commonBool1;
>       bool commonBool2;
>  	
>       {
>           int LocalVal = SomeFn();
>           commonBool1 = SomeOtherFunc();
>           commonBool2 = AThirdFunction(LocalVal,commonBool1);
>       }
> "
> . . .
> 
> {
>  	mixin (CommonCalculations);
> 	// do stuff here with commonBool1 and commonBool2
> }
> 
> 


More information about the Digitalmars-d-learn mailing list