A Perspective on D from game industry

c0de517e via Digitalmars-d digitalmars-d at puremagic.com
Wed Jun 18 09:34:40 PDT 2014


> You're talking about compile-time codegen? Like D's ctRegex 
> perhaps?
>
> 	import std.regex;
>
> 	// Statically generates a regex engine that matches the given
> 	// expression.
> 	auto r = ctRegex!`(a+b(cd*)+)?z`;

Looks nifty. As I said it's not that I want to ban a given 
technique from ever being used.

> This is a strawman argument. A template *can* be instantiated 
> with base
> class (or interface) arguments, and then you get *both* 
> compile-time
> *and* runtime polymorphism from the same template, i.e., the 
> best of
> both worlds.

Which benefits? Given that if I call an inline function with a 
type that derives from an interface, the compiler knows the 
concrete type and doesn't need to go through the interface 
indirection, the performance of the "dynamic" approach is the 
same as the "static", so why would you need the static at all?

But in C++ both approaches are actually very weak attempts at 
emulating better polymorphism. Templates are a loose, complex 
copy'n'paste engine that has no constraints on the types you 
instance them with. Interfaces give you the constraints, but 
forcing you to go through classes.

See some alternatives
- http://www.haskell.org/tutorial/classes.html
- http://caml.inria.fr/pub/docs/oreilly-book/html/book-ora018.html


More information about the Digitalmars-d mailing list