3 ms·
Even without Tony Hoare's Billion Dollar Mistake, this sort of nonsense is too easy. Do not define types which unnecessarily have a "default" value when you kno
by tialaramex 4y ago
Even without Tony Hoare's Billion Dollar Mistake, this sort of nonsense is too easy. Do not define types which unnecessarily have a "default" value when you know there is no meaningful default for the intended type.
This happens way too much for numeric values. "Not applicable" or "None" aren't the same thing as zero, but it is seen for other types too.
- rob74 4y agoYes, all the persons in various databases that are born on January 1st 1900 (or 1970) because their birth date is unknown will agree...
- rmilk 4y agoOr adding a middle name of “A” because some databases can’t handle that a person might not have a middle name or middle initial.
- fencepost 4y agoI'm still irritated about whatever bit or bits of sloppy coding ended up assigning 1/1/1970 as a birthdate for all contacts in my Google account that didn't have a birthdate specified. Combined with birthday notifications and more annoying alerts in older versions of Android or in the browser, it made for annoying New Years Day mornings with several hundred alerts.
- jdeibele 4y agoSide note: I use 1/1/70 by default when entering birthdays. Only if it's something that I expect to matter - financial or medical institution - do I enter my real birthday. Entering random dates is not a great idea because I seem to recall one site (Yahoo!, maybe?) insisting on me entering the correct birthday and I had no idea what I put in.
- CameronNemo 4y agoI usually do January 1 <sister's birth year> lol.
- klysm 4y agoUnfortunately 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 :/