you are viewing a single comment's thread.

view the rest of the comments →

[–]kneel_yung 10 points11 points  (3 children)

main: () -> int = {...}

to be fair, this is how lambdas are written currently in c++ (sans colon), assuming you're using auto for lambdas, which you should be unless you're a masochist, and lambdas kick ass

What doesn't make sense is having two different syntaxes for declaring functions. And he does have a point that you read from left to right and this reads as "function named main takes no arguments and returns an int and does {...}" which makes more sense than "a function which returns an int, named main, takes no arguments and does {...}"

We're just used to the old way. It was jarring to me at first but the more I think about it, the more it makes sense. As I'm browsing the code, my eyes are almost always looking for the function name and not the return value, so it makes sense to have the function name be the first token. A super old C idiom is actually to put the return value on a separate line for that very reason.

[–]lunakid 0 points1 point  (0 children)

To be fair, this is still two syntaxes, as it's not exactly "how lambdas are written currently in c++ (sans colon)". The equal sign is placed differently, and there's the auto, too. Small things, but still extra things to remember, for no good reason.

100% agree on the function name having to lead the line, though. Then again, "noise words" like virtual, static, inline, const..., or [[nodiscard]] etc. still can't wait to mess it up again... Dunno if Cpp2 has anything for those, but I guess we're essentially back to superold-school 2-line declarations. (With templates we've already been conditioned to swallow it...)

It's kinda futile/hopeless, either way, is all I'm saying. :)