logoalt Hacker News

esafaktoday at 2:08 PM3 repliesview on HN

> "Modern" languages try to avoid exceptions by using sum types and pattern matching plus lots of sugar to make this bearable. I personally dislike both exceptions and its emulation via sum types. ... I personally prefer to make the error state part of the objects: Streams can be in an error state, floats can be NaN and integers should be low(int) if they are invalid.

Special values like NaN are half-assed sum types. The latter give you compiler guarantees.


Replies

SJMGtoday at 5:21 PM

Not a defense of the poison value approach, but in this thread Araq (Nim's principal author) lays out his defense for exceptions.

https://forum.nim-lang.org/t/9596#63118

kace91today at 2:33 PM

I’d like to see their argument for it. I see no help in pushing NaN as a number through a code path corrupting all operations it is part of, and the same is true for the others.

show 2 replies
elcritchtoday at 2:33 PM

The compiler can still enforce checks, such as with nil checks for pointers.

In my opinion it’s overall cleaner if the compiler handles enforcing it when it can. Something like “ensure variable is initialized” can just be another compiler check.

Combined with an effects system that lets you control which errors to enforce checking on or not. Nim has a nice `forbids: IOException` that lets users do that.

show 2 replies