| ▲ | edwcross 4 hours ago | |
OCaml has had labeled arguments for decades, so I assumed other languages would have added something similar by now. In C-style, it would be like:
Even though in OCaml's functional style it is actually like this:
Using the fact that a variable named exactly like a labeled argument is automatically assigned to it, we can make the call more concise (especially if reusing existing variables): | ||
| ▲ | Dagonfly 4 hours ago | parent | next [-] | |
It's the one thing I miss from Swift when I'm using literally any other language. Interal and external parameter names. I would love for Rust to adopt: | ||
| ▲ | jdiff 3 hours ago | parent | prev | next [-] | |
This is one of the things I've loved about Gleam, one local variable name and potentially an external label that callers can use to annotate themselves. For example, a function declaration may look like this:
And a call to this function may look like: | ||
| ▲ | eithed 4 hours ago | parent | prev | next [-] | |
Think the issue is not with named parameters per se, but with mixing domain logic = there are two different user creation flows, that should be doing two different things (or mostly different things), but are guarded with boolean flag. As author points out: "So I’ll usually just make it explicit: createAdminUser(user); createRegularUser(user); Now there’s not much left to interpret. To be fair, this isn’t always bad. Sometimes this is completely fine: toggleMenu(true); That’s clear enough. This tends to work when: - the meaning is obvious - the function is small and local - there’s only one flag " | ||
| ▲ | MathMonkeyMan 4 hours ago | parent | prev | next [-] | |
You can do this as a convention in javascript since 2015, but I haven't seen a library that does it: | ||
| ▲ | lostmsu 4 hours ago | parent | prev [-] | |
C# has that | ||