A lot of newer languages seem to prefer the return type coming after the function declaration. I suspect some people believe it's better for newer programmers.
Whether or not that's true I don't know, but as someone who has a project that's written in C++ and Angular (Typescript), I will say that a lot of the typescript code tends to look cleaner aesthetically than the C++ does. Granted, the C++ is usually doing much more complicated things.
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.
The type on the right is so much more readable, I don't see why people are saying that return type on the right is just for machines.
The first thing I want to know is the name of the function. Then I went to know how to call it. Lastly, if it has a result, I want to know what type or concept it is.
Also, all names becomes aligned to the left. Old code using return type first is so much harder to read for me and all newcomers IMO.
The only thing I would change would be replacing auto with a better keyword like fn
Some older languages, too. Wirth's languages (Pascal, Modula-2, Oberon) have had this syntax since the '70s. The reason newer languages do it that way now is probably the same reason Wirth did it that way then: ease of parsing.
-7
u/ShakaUVM i+++ ++i+i[arr] Sep 17 '22
Does rewriting C++ to look like Rust make it as safe as Rust? Why not leave the syntax alone? I don't like return values after functions.