This! There’s also a longstanding open issue on rust to allow a similar way to pass keyword/named arguments. IMO every modern language should have something like this. Makes all the difference when reading code.
Inlay hints from your editor are a good help, but this should be built into the language.
Right cause the boolean isn’t a named type. If you have two possible states that can be represented with a boolean, or an enum of the two possible states which embeds more info into the callsite
I use keyword arguments in Python to minimize this pain. Instead of
create_user("Bob", True, False)it’s
JavaScript makes that more cumbersome with the object thing , but it’s better than nothing.
C# uses
CreateUser(name: "Bob", admin: true, sendEmail: false)This! There’s also a longstanding open issue on rust to allow a similar way to pass keyword/named arguments. IMO every modern language should have something like this. Makes all the difference when reading code.
Inlay hints from your editor are a good help, but this should be built into the language.
Rust doesn’t need this as much because it has enums so you can just do
create_user(user, Role::Admin, Notify::None).you can have a better data structure in any language, but rarely someone will bother doing that for booleans
Right cause the boolean isn’t a named type. If you have two possible states that can be represented with a boolean, or an enum of the two possible states which embeds more info into the callsite
Thank you for posting this comment. I came here to write the exact same thing and now I don’t have to!
👍
zig uses anonymous structs for the same effect
doWork(.{ .flurbify = true, .flurbification_intensity = 1001, });You could use jsdoc comments.