dneaves@lemmy.worldtoProgramming@kbin.social•Programming Principles: Optionals Vs Null Or Undefined
1·
1 year agoAfter some slight frustration with the “Monadic” (Haskell/Elm) approach to null when learning Elm, I actually fully embrace it now:
unNullString : Maybe String -> String
unNullString nullable =
case nullable of
Just str ->
str
Nothing ->
""
- 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.
Of course. I don’t call Facebook Meta, and I don’t call Google Alphabet.
You can change your company’s name, or nest it in a shell, people still know who you are