Re:Microfeatures I'd like to see in more languages
by krapp on Thursday January 05, 2023 @05:43PM
(#34267998)
Omitting parens in a function signature when calling with one or no arguments.
[ Parent
| on HN ]
Re:Microfeatures I'd like to see in more languages
by dragonwriter on Thursday January 05, 2023 @05:46PM
(#34268039)
This means you can’t reference the function itself by name without some kind of quoting construct or other circumlocution; also, while the no-arg case might make sense as a special case, if you allow the one arg case, you might as well admit the general case.
Re:Microfeatures I'd like to see in more languages
by krapp on Thursday January 05, 2023 @06:50PM
(#34268757)
The single argument case works fine for Lua but maybe the no argument case woudn't. Having to supply only the empty argument list seems counterintuitive, though.
Variable sigils would work but that would be even more annoying.
Re:Microfeatures I'd like to see in more languages
by jlokier on Thursday January 05, 2023 @07:03PM
(#34268906)
The general case adds ambiguity which makes it more of a design choice, rather than an obviously good generalisation.
In the general case of 2 or more comma-separated arguments, is "func a, b" a call with two arguments, or a tuple containing a call with one argument? Feel the same about "x = (func a, b)"? What about when this appears in list syntax like "[x, y, func a, b]", or the argument list of another function like "obj.method(x, y, func a, b)"?
They are easily solvable with a design decision about precedence, but arguably the syntax is a little confusing or worth a warning in all but simple cases.
Re:Microfeatures I'd like to see in more languages
by sanderjd on Thursday January 05, 2023 @10:19PM
(#34270528)
This is my least favorite example of this kind of thing. This creates so much unnecessary confusion.
Re:Microfeatures I'd like to see in more languages
by dima_vm on Friday January 06, 2023 @06:49PM
(#34283100)
Kotlin has it, but only if the function accepts the function argument, e.g.
`foo({println("hello")})` is the same as `foo {println("hello")}` (larger example in my other comment above).
You can also make it on no-args function, if it's a method (attached to a type). Utilizing @get(), like that: `3.mph` and have somewhere else defined
val Double.mph: Speed
get() = Speed.mph(this)