Talk on what a systems programming language needs to replace C

Walter Bright newshound2 at digitalmars.com
Wed Sep 4 23:13:21 UTC 2019


On 9/3/2019 3:37 PM, Laeeth Isharc wrote:
> But is it unfair to say D is missing an AST that's pleasant to work with?
> 
> I'm not sure whether it would be better to construct a parse tree or AST for 
> this purpose but eg with DPP my personal sense is it would be useful to have a 
> way to generate D code at a more abstract level than strings.
> 
> Anyway if you could translate C to D it surely wouldn't hurt.

This is essentially what AST macros are, a feature that has been repeatedly 
proposed for D. I've blocked it each time.

The trouble is, it is incredibly powerful. People find themselves unable to 
resist its siren call, and use it to invent their own language. They never 
bother to document this language. It winds up balkanizing the underlying 
language so they cannot share code or even talk to each other.

This doesn't happen overnight, it takes a few years. And then it's too late.

Some examples:

1. Lisp macros
2. Macro assemblers
3. C macro preprocessor
4. C++ expression templates

(3) is a bit of an interesting case. The C macros are very limited in 
capability, but that barely slowed down the rush to build crazy contraptions 
with it and embed them everywhere.

I've fallen into this trap myself with both (2) and (3). It took 10+ years of 
experience to finally realize what a bad idea it was, as it is an enemy of 
writing understandable, maintainable, reusable, and encapsulated code.

You don't hear much about C++ expression templates these days. For a few years 
they were quite the darling, until the scope of the horror became apparent.

Think of it like when the devil says you can have anything you want. It seems 
great for a while, but nothing good comes from it.


More information about the Digitalmars-d mailing list