[OT] Generative C++

Joakim via Digitalmars-d digitalmars-d at puremagic.com
Mon Jul 31 05:41:56 PDT 2017


On Friday, 28 July 2017 at 07:49:02 UTC, Yuxuan Shui wrote:
> Someone made an interesting proposal to C++: 
> https://herbsutter.files.wordpress.com/2017/07/p0707r1.pdf
>
> Thoughts?

Thanks for mentioning this: I just watched the video linked from 
his blog post, but didn't read the paper.

It's an elegant design, but strikes me as a bad idea for the 
language. This is the seductive kind of architecture produced by 
architecture astronauts, because it solves real needs, ie 
interface, value, etc. as "keywords," but generalizes it in such 
a way that it's very customizable (as opposed to architecture 
that shuffles codes around and solves no real need).

To start off, this basically will lead to a ton of metaclass 
"keywords" added to every codebase, which simplifies how much 
code is written but still requires the programmer to understand 
how the underlying metaclass works.  It balkanizes the language 
further, because every codebase will have their own metaclasses, 
possibly even naming the exact same metaclass implementation 
differently.  You could work around the syntax problem of a 
keyword explosion a bit by making coders type 
"MetaClass::interface" instead of just "interface", but that 
still leaves the other issues.

The job of language designers like Sutter is to find abstractions 
that would make programmers' lives easier and bake them into the 
language.  Sometimes, the way people use these abstractions is so 
varied that you need what he calls "encapsulated abstractions" or 
"user-written extensions" like functions, classes, or modules, on 
one of his last slides with 7 mins. to go.

Other times, there are some really common ways to use the 
abstraction and you're better off adding the most common 
customization of that abstraction to the language with a 
particular keyword, and saying you can't do all those other niche 
customizations.  That is the job of the language designer, and it 
is as important what he excludes as much as what he includes.

I think he'd be better off just adding keywords like "interface" 
for the metaclasses he thinks are really common, rather than 
allowing programmers to define it any way they want.  However, 
this is an empirical question: how widely do C++ programmers need 
to customize their "meta-classes" as they're implemented now, and 
is it worth the additional keywords that noobs would see 
sprinkled all over codebases and get confused by?  I don't write 
C++, so I can't definitely answer this question, but my guess is 
that it isn't worth it.

If he's right that C++ use is so balkanized, this will simplify 
some code but further balkanize the language.  That might be 
worth it for them, but rather than simplifying the language, it 
makes it more powerful and more complex, heading higher up into 
the hills rather than the lower ground he claims to be heading 
for.


More information about the Digitalmars-d mailing list