←back to thread

611 points LorenDB | 1 comments | | HN request time: 0s | source
Show context
GardenLetter27 ◴[] No.43908148[source]
It's a shame Rust doesn't have keyword arguments or named tuples to make handling some of these things easier without Args/Options structs boilerplate.
replies(5): >>43908333 #>>43908500 #>>43908653 #>>43912118 #>>43913516 #
jsat ◴[] No.43908653[source]
Had the same thought... It's backwards that any language isn't using named parameters at this point.
replies(1): >>43909426 #
Ygg2 ◴[] No.43909426[source]
Named parameters do come with a large footgun. Renaming your parameters is a breaking change.

Especially if you're coming from different langs.

replies(3): >>43912194 #>>43913869 #>>43938686 #
1. _flux ◴[] No.43938686{3}[source]
E.g. OCaml has the ability to separate argument name and variable name for named arguments: let foo ~argument:variable = variable + variable

In fact, I think OCaml has one of the best labeled argument system around there. The only downside is that it doesn't always interact well with currying, but perhaps languages without currying could just copy all the rest.

Just to elaborate a bit, in OCaml you can have functions like:

    let foo ~a ?b c =
      let b = match b with
        | None -> 42
        | Some x -> x
      in a + b + c
And you can then call this like foo ~a:1 ~b:42 55 or foo ~a:2 ?b:None 55. But then forwarding those optional parameters works like:

    let bar ~a ?b c =
      foo ~a ?b c
and the optional parameter b will be forwarded as an optional parameter.

Given Rust's historical relations with OCaml I'm slightly disappointed that it doesn't have the same labeled and optional argument system.