On Monday, 29 April 2024 at 17:52:12 UTC, monkyyy wrote:
>On Monday, 29 April 2024 at 14:58:00 UTC, bachmeier wrote:
>Setting x to 0 is no better for correctness than setting it to a random number. Either way, you're pretending the compiler knows what it should be, and that's impossible.
>no better
trade offs and downsides do not imply relativism
"different countrys use different drinking ages, lol laws have no right answers, better legalize cannibalism"
This misses the point. You don't use drinking ages to determine the "correct" age at which drinking should be allowed to start. A computer program should produce the correct answer every time it runs. Having variables initialized to a particular value is better than nothing, but better than that is if double x;
fails to compile and you explicitly set it to what you need.
0 is correct for sum, 1 is correct for products, random numbers are even ok; yes so there tradeoffs between any of these; but nan is a black hole specifically designed to break everything
It's no more of a black hole than 0 or 1. It can be used to represent missing data, which is just as valid as 0 or 1. Does that mean it's a good choice for initialization of a double? I don't think so, but that does not justify using 0.