zlacker

[return to "Nimony (Nim 3.0) Design Principles"]
1. esafak+uTb[view] [source] 2025-12-05 14:08:33
>>andsoi+(OP)
> "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.

◧◩
2. elcrit+zYb[view] [source] 2025-12-05 14:33:52
>>esafak+uTb
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.

◧◩◪
3. ux2664+bbc[view] [source] 2025-12-05 15:30:32
>>elcrit+zYb
Both of these things respectively are just pattern matches and monads, just not user-definable ones.
◧◩◪◨
4. xigoi+zjf[view] [source] 2025-12-06 16:40:17
>>ux2664+bbc
On the other hand, it’s more ergonomic and readable because you don’t need to declare a new name.

  if name != nil:
    echo name
versus

  case name
  of Some(unwrappedName):
    echo unwrappedName
[go to top]