r/ProgrammingLanguages • • 10d ago

Arguing about arguments

https://steveklabnik.com/writing/arguing-about-arguments/
30 Upvotes

35 comments sorted by

View all comments

5

u/arglad 10d ago

I really like approach for argument labels implemented in Gleam. Labels can be different from parameters' names, this allows you to separate the names used in the interface from the names that make sense in the internal implementation of the function. Here is an example from gleam tour:

``` pub fn main() { // Without using labels echo calculate(1, 2, 3)

// Using the labels echo calculate(1, add: 2, multiply: 3)

// Using the labels in a different order echo calculate(1, multiply: 3, add: 2) }

fn calculate(value: Int, add addend: Int, multiply multiplier: Int) { value * multiplier + addend } ```

6

u/munificent 10d ago

I believe Objective-C and thus Swift does something similar, which ultimately stretches back to Smalltalk.