4 ms·
Does Go have a way to insist "No, my type doesn't have a default value" ? The behaviour for the primitive types is at least more rational than C++ (in C++ prim
by tialaramex 4y ago
Does Go have a way to insist "No, my type doesn't have a default value" ?
The behaviour for the primitive types is at least more rational than C++ (in C++ primitive variables are just uninitialized by default and if read that's Undefined Behaviour, you lose, too bad) but just because my "Position" type has two integers inside it, does not mean that them both being zero constitutes a valid position :/
- CameronNemo 4y agoI don't know how insistent this method is, but you cab create a pointer to a Position, then check if that pointer is nil.
- tialaramex 4y agoThat's pretty unsatisfactory, for the burden of heap allocation your reward is now "null" Positions exist instead of the useless default :/