RetroFed Forum
Your home away from modern life.
We Have Named Arguments at Home
Post Reply
AuthorMessage
esa discuss.tchncs.de syklemil@discuss.tchncs.de
Joined: 2024-12-16
Quote

See also the discussion for Klabnik's Arguing about arguments

49   Original
FizzyOrange programming.dev FizzyOrange@programming.dev
Joined: 2023-09-24
#2 · (edited) Quote Reply

I agree - Structs are kind of a nicer solution here. Especially because it's pretty common to pass a whole set of options through the call stack.

In Python land you end up with functions with 30 arguments and when they want to pass them anywhere they give up and use kwargs which are completely awful and should almost never be used.

12
BB_C programming.dev BB_C@programming.dev
Joined: 2023-07-06
#3 · Quote Reply

Remember that this has no runtime cost and is fully type-safe.

For the sake of maximal accuracy, enum size overhead can become relevant sometimes. But a work-around exists (boxing the huge variant), and with or without boxing, the performance would still beat whatever other languages have to offer.

Otherwise, good post (I would have to say that since it mostly rehashes points I made in previous comments 😉).

4
TehPers beehaw.org TehPers@beehaw.org
Joined: 2023-06-21
#4 · Quote Reply

I agree - Structs are kind of a nicer solution here. Especially because it's pretty common to pass a whole set of options through the call stack. In Python land you end up with functions with 30 arguments and when they want to pass them anywhere they give up and use kwargs which are completely awful and should almost never be used.

In Python land you end up with functions with 30 arguments and when they want to pass them anywhere they give up and use kwargs which are completely awful and should almost never be used.

Unpack[T] exists, but nobody uses it sadly. Also, it's probably better to just use a dataclass or something instead anyway, but nobody does.

5
lad programming.dev sukhmel@programming.dev
Joined: 2023-07-03
#5 · Quote Reply

This one:

fn resize(width: u32, height: u32) {}
fn offset(dx: u32, dy: u32) {}

let f: fn(u32, u32) = if resizing { resize } else { offset };

gets rewritten to something non-equivalent:

struct Size {
    width: u32,
    height: u32,
}

fn resize(size: Size) {}

// No more arguing about arguments
let f: fn(Size) = resize;

But I would say that the original idea of applying wildly different functions depending on a flag shouldn't be easily achievable, because it's a bad idea a lot of times.

3
flying_sheep lemmy.ml flying_sheep@lemmy.ml
Joined: 2023-09-09
#6 · (edited) Quote Reply

In Python land you end up with functions with 30 arguments and when they want to pass them anywhere they give up and use kwargs which are completely awful and should almost never be used. Unpack[T] exists, but nobody uses it sadly. Also, it's probably better to just use a dataclass or something instead anyway, but nobody does.

We are migrating to this (https://scverse.org/)

But that's mostly because yours truly keeps pushing API design improvements

3
TehPers beehaw.org TehPers@beehaw.org
Joined: 2023-06-21
#7 · Quote Reply

We are migrating to this (https://scverse.org/) But that's mostly because yours truly keeps pushing API design improvements

Their docs page just flat out doesn't work on mobile, but based on the high level descriptions of the packages, these look like something I'd install on a project without asking and write in the AGENTS.md that it's forbidden from using the more popular libraries in favor of those. (Our DS people, in general, can't and won't write code for shit, so it's the only way to get them to use a new library.)

1
flying_sheep lemmy.ml flying_sheep@lemmy.ml
Joined: 2023-09-09
#8 · Quote Reply

Their docs page just flat out doesn't work on mobile, but based on the high level descriptions of the packages, these look like something I'd install on a project without asking and write in the AGENTS.md that it's forbidden from using the more popular libraries in favor of those. (Our DS people, in general, can't and won't write code for shit, so it's the only way to get them to use a new library.)

I think we helped improve that in our field since as I said, I've been making pleasant APIs for like 8 years there. But I know the struggle.

1
Post Reply
Back to top