←back to thread

155 points samuell | 7 comments | | HN request time: 0.904s | source | bottom
Show context
mihaic ◴[] No.44747304[source]
It's become a pet peeve of mine, but for the love of God, if anyone with input in Carbon is scanning this, what can be done to use "func" instead of "fn" as a keyword?

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.

replies(12): >>44747518 #>>44747538 #>>44747604 #>>44747791 #>>44747854 #>>44747943 #>>44747960 #>>44747974 #>>44748106 #>>44748147 #>>44748268 #>>44748672 #
1. flohofwoe ◴[] No.44747538[source]
Tbh, I wonder why modern languages still have a function keyword at all, e.g.:

    const add = (a: i32, b: i32): i32 => a + b;
...or any variation of the arrow-function idea...
replies(6): >>44747952 #>>44748163 #>>44748587 #>>44750338 #>>44752027 #>>44752105 #
2. uncircle ◴[] No.44747952[source]
It's hard for a naive parser (one-token lookahead, for example), to tell after parsing `const add = (` if this defines a function or a variable.

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.

3. popcornricecake ◴[] No.44748163[source]
That looks like a variable that points to an anonymous function. For simple small functions here and there it may not matter, but if the entire call stack in a debugger is full of anonymous functions then it could be a problem.
4. kibwen ◴[] No.44748587[source]
It's the other way around. Modern languages and grammars use explicit leading keywords to clearly indicate what sort of context they're about to parse, rather than blindly forging ahead in a superposition while waiting for some future sequence of tokens to clarify what the context is.
5. klibertp ◴[] No.44750338[source]
You're assuming that named lambda is the same thing as a function, which often isn't true. Unless you mean that `=>` should be ambiguous depending on scope (lambda inside a function, a function in global scope)? That would also be a bit problematic, wouldn't it?
6. ◴[] No.44752027[source]
7. VikingMiner ◴[] No.44752105[source]
IMO it is far easier to read this:

    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.