dneaves ,

After some slight frustration with the “Monadic” (Haskell/Elm) approach to null when learning Elm, I actually fully embrace it now:


<span style="color:#323232;">unNullString : Maybe String -> String
</span><span style="color:#323232;">unNullString nullable = 
</span><span style="color:#323232;">    case nullable of
</span><span style="color:#323232;">        Just str ->
</span><span style="color:#323232;">            str
</span><span style="color:#323232;">        Nothing ->
</span><span style="color:#323232;">            ""
</span>
  • A) Now I try to avoid nullables when possible, because handling it everywhere is often more annoying than just expecting the type (even in non-monadic languages like Python)
  • B) This is theoretically a better practice anyway. Why have a nullable string when you can just have an empty string? Or a nullable array/list/object/dict/etc when you can just have an empty one? Why have a nullable quantity of items when you can just have 0? If you really, really think you need a nullable bool, you don’t: just make a data (Haskell)/type (Elm)/enum (others) at this point. Most other things could just become an data/type/enum as well.

We null things for no reason, too often. Usually laziness.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • wartaberita
  • random
  • uselessserver093
  • Food
  • aaaaaaacccccccce
  • [email protected]
  • test
  • CafeMeta
  • testmag
  • MUD
  • RhythmGameZone
  • RSS
  • dabs
  • KbinCafe
  • Ask_kbincafe
  • TheResearchGuardian
  • oklahoma
  • Testmaggi
  • Socialism
  • SuperSentai
  • KamenRider
  • feritale
  • All magazines