3 ms·
After some experience with Go I realized that in quite a few cases it will be nice to have 1-based indexes. If one have a variable that is an index into an arra
by fpoling 6y ago
After some experience with Go I realized that in quite a few cases it will be nice to have 1-based indexes. If one have a variable that is an index into an array, then it is natural to initialize it to an invalid index like -1. But in Go everything is initialized by default to 0. So to get -1 one needs extra code.
With one-based indexes zero would be a very natural invalid value as an index similar to a null pointer.
- mjevans 6y agoExpress a slice of length 0, backed by a buffer of length 1024 elements.