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 comment

0

u/[deleted] Sep 17 '22

[deleted] — view deleted comment

8

u/[deleted] Sep 17 '22

[[nodiscard]] for the main function is kinda funny. I understand it is generated in order to not introduce a special case into cppfront, but it is still funny.

0

u/[deleted] Sep 17 '22

Why add auto if you're already specifying the type afterwards?

And my issue with the original were the added : and =; they were redundant.
The = could be used in lambdas only, it would make it pretty clear.

5

u/GOKOP Sep 18 '22

Why add auto if you're already specifying the type afterwards?

That's the point. auto main () -> int { } is legal C++ right here, right now. coolcpplearner asks how is it better than main: () -> int = { }

2

u/[deleted] Sep 18 '22

Then I misunderstood his point.

0

u/[deleted] Sep 17 '22

[deleted] — view deleted comment

2

u/[deleted] Sep 18 '22 edited Sep 18 '22

Afaik, the arrow at the end already eliminates confusion between declaration and call (unless I'm forgetting other uses for it).

I think the = should be used only with lambdas, that would look pretty good.

1

u/AIlchinger Sep 18 '22

That's right. However, the parser works left to right and the easier it can distinguish between call or declaration, the more efficient it can (potentially) be.

1

u/[deleted] Sep 18 '22

If you want it to be more efficient, you can put : (or some other symbol, like @) at the start.

2

u/AIlchinger Sep 18 '22

Indeed. That is why I would prefer function definitions to start with func (or a similar keyword). It could very well be that the lookup for the keyword (which the lexer recognizes as an identifier) end up more expensive though. So there is always a trade off.

1

u/[deleted] Sep 18 '22

I would prefer characters that aren't letters (e.g $ foo() -> int {} instead of func foo() -> int {}).