5 ms·
Can we please keep using parens for function invocation? Leaving them out hurts readability.
by stuartaxelowen 10y ago
Can we please keep using parens for function invocation? Leaving them out hurts readability.
- bjz_ 10y agoThe difference between curried langs like OCaml and Haskell and languages like Ruby and Elixir are that the leaving out of parens actually means something, ie. all functions take one argument. If you wanted parens whilst maintaining the same semantics, you would end up having to do write: `add(2)(3)`
- stuartaxelowen 10y agoIndeed, but leaving out the parens makes more work for humans. What does `a b c` mean? `a(b)(c)`? `a(b(c))`? If the only thing that is gained by leaving out the parens is brevity, I don't think its worth it.
- reycharles 10y agoIt would be `(a(b))(c)`. Interestingly, you're already leaving out parens for brevity.
- deno 10y agoBut it’s not `a b c`. Rather it’s something like `verb noun noun`. Which is much less ambiguous. In a language with currying semantics [(((a(b))(c))(d)] the only logical explicit syntax sugar would be LISP-like, so (v n n), (v (v2 n)). That’s imo way worse — you end up with lots of useless junk)))))))) in anything non-trivial.
- stuartaxelowen 10y agoWhat about `verb noun verb noun`? Is the second verb a parameter or is it being invoked on the noun?
- thedufer 10y agoIt's a parameter. The rule isn't complicated - functions are left-associative. That's all you have to remember.
- evincarofautumn 10y agoIt’s no different than having to know the associativity of an operator. Does “a - b - c” mean “(a - b) - c” or “a - (b - c)”? The former, for no reason other than a long history of convention. Same goes for function application. And you could make the same argument about languages that require parentheses for function calls: what does “a(b)(c)” mean? “(a(b))(c)” or “a((b)(c))”? What’s gained is that the syntax mirrors the semantics. If you have a function “f : int -> bool -> int”, then “f 5” has type “bool -> int” and “f 5 true” has type “int”. It’s not like in Forth where you can’t tell from the syntax how many arguments a function takes. That said, I do think right-associative function application may be more intuitive—I like having it in Perl, for example.
- eru 10y agoYou get right-associative function application (in Haskell) by putting $ in between your functions. (And if you are using composition instead, it associates in both directions.)
- rixed 10y agoMore work for humans used to something else. At this point it's worth reminding that ML syntax was originally designed to make programs more palatable to maths students...
- jordwalke 10y agoPlease take a look at the FAQ which describes the best way to move forward with evolving the syntax. It helps to know your personal technical background and where you're coming from, as well. I do like your idea, but you can currently use parens - it's just that they aren't required by the parser when the argument is clearly one item (like an integer constant etc). Then at that point, it's just a matter of configuring the source formatter to always include them.
- stuartaxelowen 10y agoMy background is in Python, Scala, Java, C, and Ruby. My reaction is based on the monstrous DSLs I've seen in Scala and Ruby (because the language lets them), where the clever syntax actually hid the important features of the interface. Every time you get to "wait what is this actually doing" and you have to learn another tiny language instead of just writing functions that return a `Future[HttpResponse]` and be done with it. Don't let my complains about syntax deter you, this looks like a very exciting project!
- jordwalke 10y agoThanks stuartaxelowen, the feedback is actually really valuable one way or another.
- eru 10y agoThat's a valid complaint for new untested syntax that people came up with yesterday. The paren-less function invocation has been around and tried for ages in the ML-family. (The main downside is that variadic functions are hard to express this way. For fixed arity this is a clear win, also makes partial application nicer to read.)
- ufo 10y agoMaking function invocations with (foo x y) instead of foo(x,y) is pretty common in functional languages like Ocaml, LISP and Haskell. When so much of your code is function calls, all those commas and parenthesis start cluttering things.