by mihaic · 1y ago · 0 comments
That all-consonant keyword always makes it seem like I'm reading Hungarian notation when reading Rust for instance. An other options I've seen for instance in Pony, "fun", is already an English word with a completely different meaning.
Even the "function" from Javascript seems fine to me.
Such small things as using __ __ in python and small inconveniences (lua's 1 instead of 0) really has a lot of people, what do I say.. yea, polarized on this matter.
What is inconvenient about it?
fun main() {
println("Hello, world!")
}
^ aligned here! \o/Unfortunately we keep designing languages for people using notepad.
Nowadays my editor even writes full blocks at a time.
Mind you, I'm not saying that your solution doesn't work. Just that it doesn't work for the GP.
auto my_function(int, double) -> int;
They probably want to use the same arrow signature and need something in place of auto as omitting it completely would complicate parsing.I agree, I hate fn. Also not a fan of func though.
In practice everybody just uses class, because who as the time to type the full keyword and signature declarations in C++ are already unwieldy as it is.
const add = (a: i32, b: i32): i32 => a + b;
...or any variation of the arrow-function idea...A "function" keyword often exists just to help the parser. C3, for example, to simply the parser of its language that's a superset of C, adds a "fn" keyword for this very purpose of disambiguation.
function add(a: i32, b: i32): i32 {
return a + b;
}
Than the example you provided and it is approximately the same length. I used to arrow functions everywhere in TS/JS and it made it difficult to read IME, and there was zero benefit. They are find for things like event handlers, promises chains etc. But I'd rather just use function when I don't have to worry about the value of this.