3 ms·
Regardless of what happens in the language, this needs to be handled. In python for instance, the developer needs to be prepared to catch a divide by zero exce
by whalesalad 2y ago
Regardless of what happens in the language, this needs to be handled.
In python for instance, the developer needs to be prepared to catch a divide by zero exception.
In gleam, the same consideration is required but the implementation will just differ.
I don't actually see an issue here. It's a potential gotcha, but once you are aware of this feature of the language, it's no different than any other.
- miki123211 2y agoNo. In Python and languages with similar behavior, a division by 0 will immediately crash your program with a pretty stack trace, showing you exactly where the problem is and how the program got there. In languages where division by 0 produces infinity, NaN, 0 or similar, your calculation just returns a nonsensical result. Zero is even worse than inf or NaN, as you may not even realize that there was an error in the first place, as the result of your calculation is a number and not a strange-looking value.
- lolinder 2y ago> In python for instance, the developer needs to be prepared to catch a divide by zero exception. > In gleam, the same consideration is required but the implementation will just differ. These aren't remotely the same. If a developer fails to catch an exception or a NaN then the program either crashes or returns an obviously wrong result. If a developer fails to guard against a zero returned from division then they get a number out that's wrong in subtle ways that may not be obvious until the wrong numbers are already in use somehow. The question isn't whether you can work around the error, it's how likely you are to notice that you screwed something up before it's too late.
- beanjuiceII 2y agoI'm with you on this for sure, seems dangerous to just use 0 how will anyone know something is going wrong?
- throwawaymaths 2y agoNo it's fine. The 0 will just propagate to other divide by zeros and you'll always have an answer, so it's all good.