rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

[RFC] Optionally labeled arguments

Open mks-h opened this issue 1 year ago • 7 comments

Hi! I'm new to the language, and I like it so far. However, one thing I don't particularly like is the differentiation between regular and labeled arguments. I might be missing some cool concept behind it, because to me it looks backwards, and more importantly — limiting.

To be on the same page — while in JavaScript you cannot provide an argument by using its name, you can still see the name in your LSP, at least usually. In ReScript, however, separation between parameters and arguments is even stronger — LSP only provides the type of the parameter, and the shape/ordering of all parameters.

Screenshot of JavaScript/TypeScript LSP

A screenshot of LSP providing names of arguments

With regular parameters, users are forced into the JS behavior of only being able to specify arguments in the exact order. Alternatively, some or all parameters can be labeled, in which case users of the function will be forced into the opposite behavior — they're required to use the label, and cannot use ordering.

I find this behavior unnecessarily limiting, as there is no practical or run-time difference between the two ways of providing arguments. Yet the exact way to do this is forced by the definition of the function (at which point you can only guess the way the function will be used).

Instead, it would be more logical to be able to choose the preferred way of providing arguments at the call site, where it matters. This way I'm not limited to the preference or a generic decision of the person defining the function (even if it's me one week ago).

The only semi-practical difference I see, is that all arguments' names will be exposed by LSP, so developers might need to be a little more mindful of them.

Setting argument using its name, despite it not being "labeled"

P.S. Squiggly lines at the call site don't look like an absolute necessity, but they're probably a great shortcut for LSP to know from the first character to look for parameter names, and not just any identifier — I'd keep them.

mks-h avatar Feb 22 '24 00:02 mks-h