News for hackers. Stuff that matters.
Re:Be wary of functions which take several parameters of the... by toyg on Thursday September 26, 2019 @07:59PM (#21087015)
or as Python:

   shutil.copy(src='foo', dst='bar')
That's straight out of stdlib, btw.
Re:Be wary of functions which take several parameters of the... by echelon on Thursday September 26, 2019 @08:05PM (#21087051)
Those are keyword args and are not specific to just Python. :)

The parent post outlines many techniques, including this. Some are more apt than others depending on your language of choice.

I would argue that there's another option of passing a strongly typed struct for args, and that the JavaScript and Ruby solution of dicts falls between this and kwargs.

I'm fond of properly designed fluent APIs, myself.

While on the subject of homogenous argument types, especially bad are the APIs that not only accept the same types, but have order semantics that differ between functions within the same library. PHP used to be a notoriously bad example of this with respect to their needle and haystack search parameters. (I think they fixed it?)

Re:Be wary of functions which take several parameters of the... by toyg on Thursday September 26, 2019 @08:38PM (#21087303)
Yeah, I was just showing that in Python keyword arguments are first-class in every respect, which is not that common.

The "JS solution" for example is not a solution, but only a convention: the actual interface is just expecting an object, and there is no explicit check on the validity of such object or its contents. That is nowhere near "strongly typed", if anything it's weaker than average.

Re:Be wary of functions which take several parameters of the... by thelazydogsback on Thursday September 26, 2019 @08:56PM (#21087431)
> The "JS solution" for example is not a solution, but only a convention: the actual interface is just expecting an object,

Well if it uses de-structuring syntax, then it can be type-checked.

Re:Be wary of functions which take several parameters of the... by tomjakubowski on Thursday September 26, 2019 @09:59PM (#21087715)
De-structuring syntax isn't required, this is just as easily type-checked:

    interface CopyArgs {
        src: string;
        dst: string;
    }

    function copy(args: CopyArgs) {
        exec(["cp", args.src, args.dst])
    }
Re:Be wary of functions which take several parameters of the... by thelazydogsback on Friday September 27, 2019 @12:13AM (#21088342)
Sure, if you want to get all interfacy - but pretty soon it'll be Java :)
Re:Be wary of functions which take several parameters of the... by davedx on Friday September 27, 2019 @07:16AM (#21090613)
Hah I thought that initially, but TypeScript interfaces are simpler (and usually co-sited) compared to their OO cousins. I find them a pleasure to use.
Re:Be wary of functions which take several parameters of the... by RobertKerans on Friday September 27, 2019 @01:52AM (#21088851)
It can, manually (as it can for a non-destructured object), but it has no typing guarantees - the function will still happily be interpreted and run as long as _any_ object is given as an argument.
Re:Be wary of functions which take several parameters of the... by ambicapter on Friday September 27, 2019 @01:02AM (#21088602)
> (I think they fixed it?)

No, they put out a conf talk that stated that there _was_ a logic to it, you just needed it to be explained to you.

Re:Be wary of functions which take several parameters of the... by timw4mail on Friday September 27, 2019 @09:08AM (#21091496)
Really, most of the relevant PHP functions are just thin wrappers around the C functions with the same name.

But nobody talks about how nonsensical C function names are.

Re:Be wary of functions which take several parameters of the... by Waterluvian on Thursday September 26, 2019 @11:25PM (#21088130)
I love this part of Python. I can choose to include the argument names if I think they tell a more clear story.