Odin
Odin copied to clipboard
Add support for mixed named and unnamed arguments
I feel mixed named and unnamed argument support would be a great addition to odin and would make odin code much easier to read, write and maintain. The specific case I'm thinking of is a function where you have many arguments but many of those arguments are optional, for example, take a slider widget in an immediate mode UI:
slider :: proc(label: string, value: ^f64, range: [2]f64, step := f64(0), power := f64(1), units := "", format := "%v", style := "")
The most minimal use of this function with all its optional arguments as defaults would look as follows:
slider("My Slider", &val, { 0, 100 })
nice and readable! But let's say we wanted all the default options besides the style, the call would now have to be one of the following:
slider("My Slider", &val, { 0, 100 }, 0, 1, "", "%v", "#my_style")
// or
slider(label = "My Slider", value = &val, range = { 0, 100 }, style = "#my_style")
The first option means copying the optional argument values -- this is bad in the case that the optional argument values change as in this case we always want them to just be the default; in addition to this it adds a lot of noise. The second example adds noise and verbosity to the call, additionally it requires one to remember the parameter name of each argument passed when writing the call to the function. Support for mixed would allow for the following:
slider("My Slider", &val, { 0, 100 }, style = "#my_style")
A much better option than the two existing ones.
This is a feature I would most definitely love too.
To add it requires redoing the entire procedure handling code from scratch since at the moment, it has two branches, one for ordered and one for named, which is how compound literals effectively work.