Hacker News new | ask | show | jobs
by tialaramex 1587 days ago
> I forgot to deal with division by zero in these math expressions. It is impossible for the compiler to detect such errors in the program.

I'm sure there's a general class of problem where it really is impossible, but you haven't found it.

All you needed to prevent this is dependent types, which Go doesn't have. With dependent types the compiler sees a = b / c and it immediately can conclude that c's type is non-zero, since if it was zero that's a divide-by-zero error. Having refined the type to non-zero, an attempt earlier to load it with a value despite not being sure if that value is zero will fail. The buggy qjson won't compile.