A Perspective on D from game industry

Rikki Cattermole via Digitalmars-d digitalmars-d at puremagic.com
Mon Jun 16 21:16:43 PDT 2014


On 17/06/2014 3:05 a.m., H. S. Teoh via Digitalmars-d wrote:
> On Mon, Jun 16, 2014 at 12:44:05PM +0000, via Digitalmars-d wrote:
>> On Monday, 16 June 2014 at 11:49:11 UTC, Rikki Cattermole wrote:
>>> I would go that far, when combining string mixins,
>>
>> As far as I can tell string mixins have the same bad properties that
>> macros have. It makes automatic translation very difficult and makes
>> reasoning about code more difficult. It is a cheap and effective
>> solution, but without any trace of beauty... A design blunder IMHO.
>
> Actually, IIRC, string mixins were never designed to be nice -- they
> started as a kind of temporary last-resort kludge that got put in, in
> lieu of a true AST macro system, with the view that it would meet the
> current metaprogramming needs until the latter, ostensibly superior,
> solution came along.  Unfortunately, AST macros never happened, and
> string mixins kinda took hold in the D codebase, so that's what we have
> now.
>
> I would personally avoid using string mixins unless there's absolutely
> no other way to achieve what you want -- they're a kind of last-resort
> nuclear warhead that you don't bring out unless all the other guns fail
> to win the battle.

I have a rule about string mixins which I believe to be a good one to 
follow:
If using string mixins, don't expose it to client code unless they 
explicitly want it.
Basically what this means is, use something to wrap it like a mixin 
template but don't just say hey call this function and use it as a 
string mixin!
Its a little nicer. Also the explicit getting of the string is important 
for debugging. Sometimes its needed for the more complex cases in edge 
cases/broken functionality. I use it during development (a simple pragma 
msg inside the mixin template for example).

But in saying this, some of this could be handled by opDispatch. Its 
just a shame that both approaches currently aren't handled for 
auto-completion by any IDE's. I would expect the string mixin would be 
one day.

> Having said that, though, proper use of string mixins with CTFE and
> templates ('scuse me, *compile-time arguments* ;)) can be extremely
> powerful, and one of the things that make D metaprogramming so awesome.
>
>
> T
 >


More information about the Digitalmars-d mailing list