Re:Be wary of functions which take several parameters of the...
by anonytrary on Friday September 27, 2019 @01:33AM
(#21088751)
Named function parameters are nice, but you can accomplish something similar with only two more characters in some languages:
I can understand why this is considered a nice-to-have. The verbosity didn't really change.
[ Parent
| on HN ]
Re:Be wary of functions which take several parameters of the...
by thom on Friday September 27, 2019 @05:53AM
(#21090112)
And then you have to check that the map you're being given has all the correct keys with the correct typed values. And when you're looking at the code, you see:
function DrawRect(options) {...
Unless you're immediately destructuring it or whatever. I don't think it's _that_ straightforward to compare the two, unless I'm thinking of the wrong languages here.
Re:Be wary of functions which take several parameters of the...
by Too on Friday September 27, 2019 @10:46AM
(#21092551)
Typescript can specify required keys in a dictionary: function DrawRect(options: { at: Point2D, width: number, height:number}}
It will be checked compile time that all keys are provided (unless dict comes from serialized json or something).
Re:Be wary of functions which take several parameters of the...
by thom on Friday September 27, 2019 @04:43PM
(#21096092)
That's more verbose than just having arguments though, right?
Re:Be wary of functions which take several parameters of the...
by Too on Saturday September 28, 2019 @01:18AM
(#21098605)
Slightly more verbose but not much. Just having arguments takes you back to square one where you might mix up the order of width and height since nothing is forcing the caller to use named parameters. Perhaps it would be better to have some linter enforcing such things.
Re:Be wary of functions which take several parameters of the...
by thom on Sunday September 29, 2019 @06:52AM
(#21106311)
It doesn't take you back to square one in languages which enforce named parameters, which I thought we were talking about.
Re:Be wary of functions which take several parameters of the...
by kalleboo on Friday September 27, 2019 @02:53AM
(#21089169)
You can accomplish it in other languages, but will all the other library authors do so? Do the OS libraries do so?
Re:Be wary of functions which take several parameters of the...
by wruza on Friday September 27, 2019 @02:21AM
(#21089001)
Two more characters and one more allocation per each LoC.
Re:Be wary of functions which take several parameters of the...
by a13n on Friday September 27, 2019 @04:23AM
(#21089653)
Most of us are just writing crud apps anyway so one more allocation is extremely affordable
Re:Be wary of functions which take several parameters of the...
by lonelappde on Friday September 27, 2019 @02:03PM
(#21094541)
Maybe but this highly dynamic programming style is why Macs have always been so much slower than Windows on equivalent hardware.
Re:Be wary of functions which take several parameters of the...
by Scapeghost on Friday September 27, 2019 @02:47PM
(#21095048)
Where did that come from? Apart from games that were obviously optimized for Windows first then ported to macOS, has that claim been measured? Because macOS has always certainly FELT faster than Windows.
Re:Be wary of functions which take several parameters of the...
by anonytrary on Saturday September 28, 2019 @02:22AM
(#21098811)
As if my app stops working because of this?
Re:Be wary of functions which take several parameters of the...
by masklinn on Friday September 27, 2019 @07:21AM
(#21090636)
> I can understand why this is considered a nice-to-have.
Well typing is one good reason, maps usually are not statically typed with key:value pairs. That's more of a class / struct thing. And then the verbosity increases quite a bit.