I remember first time I saw the batman joke:
Array(16).join('wat' -1) + " Batman!" //outputs: "NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN Batman!"
It was hilarious. How could this even happen? As a joke it works very well but let’s have a look to the intent: 1.- Array(16) We set an array of 16 elements uninitialised(it contains 16 undefined)
2.- ‘wat’ -1 We subtract 1 from ‘wat’ What!!?? this expression happens to be NaN (not a number)
3.- Array(16).join(‘wat’ -1) We transform the array 16 undefined elements into a string splitting the elements by ‘wat’ - 1 (which is NaN)
4.- Array(16).join(‘wat’ -1) + “ Batman!” We concatenate the previous string to “ Batman!”
Here we have an elm program. It adds 0.1 to 0.2 and writes it to the screen.
import Html exposing (text) main = text (toString (0.1 + 0.2)) --outputs: 0.30000000000000004
(What!!?? 0.30000000000000004 !!?? Let’s make fun of elm all together!!) Hold on. What happened? The outcome of the operation doesn’t fit in the space available for a float number so some precision is lost and it produces this effect called overflow. This is common in many programming languages but not on all. Should we stop using elm because of this? No. Should we start an endless trip finding the perfect language? Maybe but not because of this. Should we use it for our banking application? Probably not, also elm is focused in building user interfaces.
In any case: Go and learn what you are using. What must be prevented. And what other alternatives work better on those edge cases. Then pick the best tool for that work.