As a long-time (~12ys) Objective-C programmer and nowadays (almost) exclusive Swift & Rust programmer I’ve found myself to be more and more annoyed with mandatory(!) named parameters in Swift these days even though I used to be a huge proponent of named parameters in Objective-C.
Why? Because it penalizes properly named variables.
Whenever one names a variable, say, radius
and passes it to a function taking an argument radius
one ends up with
draw_circle(location: location, radius: radius, color: color)
Ugh. One would almost be better off with badly named variables:
draw_circle(location: l, radius: r, color: c)
in regards to readability and/or a 80 char limit, e.g.
In my experience in many cases the variables passed to a function have the same names as the arguments of said function, resulting in unwanted duplication. It penalizes properly named variables and makes it even convenient to do otherwise.
The main problem here is that swift makes argument names mandatory.
This being said I too would love to have opt-in (at declaration-time, preferably) named arguments.
From a Rust-user’s point of view I would prefer a flavor of the “Struct sugar” alternative with anonymous ad-hoc structs.
Declaration-site:
fn draw_circle({ location: Location, radius: Radius, color: Color }) {
println!("<location: {}, radius: {}, color: {}>", location, radius, color);
}
Call-site:
draw_circle({ location: location, radius: radius, color: color })
For a function either all its arguments would be named or none would. The naming decision would further more have to be made at declaration-, not call-site.
The general language (from user’s perspective) would thus remain pretty much as it is and named parameters be primarily used for argument-heavy edge-cases.