2 ms·
Unfortunately most languages make this very difficult to avoid even when you are trying
by klysm 4y ago
Unfortunately most languages make this very difficult to avoid even when you are trying
- CameronNemo 4y agoGolang default type values go brrrrrrr.
- tialaramex 4y 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 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 :/