Template Metaprogramming Made Easy (Huh?)

bearophile bearophileHUGS at lycos.com
Mon Sep 14 04:33:59 PDT 2009


Jeremie Pelletier:

>I haven't had to use the C heap whatsoever so far in D, could you give me an example of where you need it?<

1) I'm able to allocate a bigger single chunk of memory from the C heap, about 1.8 GB, while the GC heap of DMD on Windows allows only for a smaller chunk. In a program I've had to allocate a single chunk of memory.
2) I think the GC is faster at allocating small chunks of memory, while the C heap is faster at allocating large chunks.
3) GC-managed pointers have several restrictions (so much different that maybe I'd like them to be seen as a different type from the compiler, that requires a cast to be converted from/to C pointers. I don't know why this idea was not appreciated by D designers). One of them is that GC-managed pointers can't be tagged, you can't add one or two bits to GC-managed pointers, and such tags are useful when you want to implement certain data structures.


>Indeed, and sometimes it's way faster than that.<

But lot of people will judge D against more modern languages like C#, Scala 8or Java) and not against C.


>C++ isn't anymore complex than D2,<

I don't agree, see below.


>I can't think of many features C++ has over D2. I can name quite a few features D2 has over C++ :)<

Complexity and not-simplicity come from many things, like corner cases, rules against rules against rules, unsafe things that the compiler isn't able to catch in case of programmer errors, unnatural syntax, and not just from features. For example the Python 3+ language has many more features than pure C, yet Python3 is simpler than C :-)


>it still allows for dirty work to be done when you need it.<

The less dirty you make it the better it will be when you try to mantain/debug your D code :-)


>You don't need to code your application core in C and your application behavior in a scripting language on top of the C core. D allows you to write it all in one language with the same productivity, if not better productivity for not having to write the abstraction layer between C and scripting.<

While D is quite better than C, that of yours is a dream. In practice D isn't dynamic and for certain purposes D is not close to the "productivity" of Python :-) (Even just because in Python you can find tons of modules and bindings already done). There are ways to improve D still for such purposes. D can be more scalable as Scala :-)

Bye,
bearophile



More information about the Digitalmars-d mailing list