4 ms·
I don't understand what parsing has to do with elegance in this context. There are some 'best practices' but I don't see the different syntax support as a bug.
by atmosx 11y ago
I don't understand what parsing has to do with elegance in this context. There are some 'best practices' but I don't see the different syntax support as a bug. I feel that it's a trademark of a modern language.
Let's take rust as a counter example. IMHO this is ugly:
fn foo() {...}
To make it elegant I should be able to remove the parenthesis because there's no argument inside:
fn foo {...}
But this will come up with an error: "expected one of `(` or `<`, found `{` ...", which is fine. It's easy to parse, but it is not elegant IMHO.
Elegance != easy parsing.
- kibwen 11y agoIt's not just about making parsing easy (which is usually motivated by the promise of better tooling), it's about making costs explicit. `foo.bar` with no trailing parentheses is always a field access in Rust, and a field access is basically the fastest thing one can do: take a known offset from a memory location. In comparison, `foo.bar()` has a relatively tremendous cost, depending on various factors. It's for this same reason that Rust requires you to write `(foo.bar)()` if you want to call a function stored in a struct. This isn't a tradeoff worth making in all languages. But it is a tradeoff, and not a rejection of elegance.
- waj 11y ago`foo.bar` is always a call in Crystal. If `bar` is just an accessor, then the method will be inlined and there is no extra cost compared to make an explicit field access.