Re:The Evil Within the Comparison Functions
by dyarosla on Sunday February 18, 2018 @09:46PM
(#16410394)
Moreover, you could also allow for something like passing a structure of parameters.
clamp({min:2, max:5, x:3})
^parameters can be rearranged as you see fit
There! Now the programmer can decide what’s the way they want to call the function that makes the most sense to them.
Re:The Evil Within the Comparison Functions
by dvlsg on Monday February 19, 2018 @03:24PM
(#16415431)
If you use named arguments, can't you typically rearrange the order?
Don't get me wrong, I use destructured arguments in js and it works fine, but I thought named arguments in other languages solve that particular issue as well.
Re:The Evil Within the Comparison Functions
by joshvm on Sunday February 18, 2018 @10:04PM
(#16410469)
In languages like Python where you can have keyword args (typically with defaults), these options must come after the first argument, e.g. clamp(x, min=0, max=inf). Then you can do what you like with the order. And often it's good to specify the keyword for your own sanity later, when you have no idea what the third argument to some obscure Numpy call is. Or if you're using something like matplotlib and there are so many kwargs that it's better to specify.
Although in this case min/max probably shouldn't have defaults, I think clamp(min, x, max) would be a bit weird in Python?
clamp(x:3, min:1, max:5)
Oh look! No mental strain required to think about what the function does nor what the order should be to minimize mistakes; it’s clear as day!
I wish more languages adopted the option to do this.