3 ms·
Golang default type values go brrrrrrr.
by CameronNemo 3y ago
Golang default type values go brrrrrrr.
- tialaramex 3y agoDoes 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 3y 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 3y agoThat's pretty unsatisfactory, for the burden of heap allocation your reward is now "null" Positions exist instead of the useless default :/