Hacker News new | ask | show | jobs
by drcode 591 days ago
Zig believes that all code needs to be explicit, to prevent surprises- You never want code that "just executes on its own" in places you may not expect it. Therefore, if you want default arguments, you have to perform some action to indicate this.
3 comments

Except it's not entirely explicit. It allows the type name of the object being constructed to be elided.

Per the article, this is the explicit form:

    var gpa = std.heap.GeneralPurposeAllocator(std.heap.GeneralPurposeAllocatorConfig{}){};
I don’t think type elision make the codes execution less explicit. Nothing else could go there
That's a textbook definition of "implicit", as in not directly specified, but assumed.

The fact that unacceptable parameter would fail compile time validation does not make it any more readable.

Consider this:

    var foo = OpaqueTypeName(.{}){};
What is the . eliding?

You don't know. I don't know. It's impossible to tell because the type is opaque to our understanding.

i don't get this argument. what is code that "just executes on its own"? how is it more difficult to differentiate what a function does with vs without arguments compared to one that takes arguments with values vs arguments without values?
explicit about branching and allocations, not so for types. we've recently got .decl() syntax, which is even more implicit than .{}