3 ms·
Although it doesn't have constructors, Go has zero values. I can't find a reference, but I believe this is so that you can create arrays with any element type a
by skybrian 7y ago
Although it doesn't have constructors, Go has zero values. I can't find a reference, but I believe this is so that you can create arrays with any element type and they can be automatically initialized?
Naturally, if pointers must have a zero value (like any other type), nil is a logical choice.
The pervasive support for zero values (or not) seems like a pretty fundamental design choice with far-reaching consequences. It works okay when there is a logical use for a zero value (as encouraged in Go) and is awkward otherwise.
If you don't have zero values, you end up with something like Rust's array initialization syntax:
https://www.joshmcguigan.com/blog/array-initialization-rust/ https://www.joshmcguigan.com/blog/array-initialization-rust/