r/cpp • • Sep 17 '22

Cppfront: Herb Sutter's personal experimental C++ Syntax 2 -> Syntax 1 compiler

https://github.com/hsutter/cppfront
335 Upvotes

360 comments sorted by

View all comments

Show parent comments

-7

u/Ayjayz Sep 17 '22

Make the parsing harder, then. Code is for humans, and trading off programmer time for compilation complexity is not a smart trade.

16

u/schmerg-uk Sep 17 '22

The issue then becomes tooling - C++ is famously hard to parse and for 20+ years this has made linters and smart editors etc hard to write or easy to break.

Don't get me wrong - I'm also a big perl fan and perl's syntax was designed by a linguist so contains natural language principles that favour the human reader (once they get over the $ and @ stuff that makes sense once you see them as human linguistic constructs - see "Disambiguation by number, case and word order" and "Pronominalization" in the doc above) but in return, perl is hard to parse to the point where it has been proven that "only Perl (the executable) can parse perl (the language)".

I'm not saying you have to agree with the "natural language principles" or the trade-off that perl took, but I think it's useful to examine it as attempting to make the language for the human reader and recognise the issues this has.

-5

u/SkoomaDentist Antimodern C++, Embedded, Audio Sep 17 '22

C++ is famously hard to parse

That is true. Almost none of that is caused by function argument preceding the function name or other things people like. It could be fixed with minor changes that wouldn't bother anyone.

11

u/schmerg-uk Sep 17 '22

Almost none.. except for the "most vexing parse" and that it's not a context free grammar, so to convert the syntax to a context free grammar friendly form makes parsing simple and keeps the most important thing, the function name, first.

There's a reason why so many of languages move to this style and this old head* quite likes it but I understand YMMV

[ * - C programmer since 84, C++ since 91 - quoted not to claim some kind of authority and I'm by no means the details-expert or uber-fan of the modern language as I was the old, but of all the things that provoke "well THIS has just RUINED C++" I think "main: () -> int = { ... }" is one of the most innocuous ]

→ More replies (5)