Hacker News new | ask | show | jobs
by xigoi 589 days ago
This doesn’t answer the question why Zig doesn’t have default argument values.
1 comments

Default argument variables create variadic functions.

Arity N when you supply a value

Arity N-1 when you use the default

How does this create variadic functions? The arity is the same, since the function signature defines the exact amount of arguments. The compiler just passes the omitted ones for you.
Okay, but why could a static language not have variadic functions?
That's their design choice.

I can think of a few reasons

- makes function calling simpler

- faster compilation

- less symbol mangling

- makes grepping for function implementation easier

If for some reason you think you absolutely can't live without variadic functions, maybe don't use zig.