Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Any division either works and returns a result, or doesn't work and doesn't return a result. This is similar to any other function that maybe returns a result (returns an Option<T>/Maybe<T> or even Result<T, E>).

Perhaps it's not a good design to have division as an operator a programming language? Just like

Maybe<int> i = ParseInt("foo")

one should also do this for division:

Maybe<int> q = Div(n, d)

Is there any language that does this (returns an option for default division?)

Obviously, this is also the case for ALL other operations on finite number types because of overflow. But overflow is MUCH rarer than division by zero issues, at least in my experience.



That's interesting. In my career, I've rarely encounted division by zero. I've encountered over and underflow considerably more. Different experiences, different points of view.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: