this post was submitted on 05 Sep 2024
55 points (92.3% liked)
Programming
17313 readers
72 users here now
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities [email protected]
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
The items don't seem concise and always clear. But seems like a good, inspiring resource for things to consider.
I've never heard of evading null with a Null object. Seems like a bad idea to me. Maybe it could work in some language, but generally I would say prefer result typing. Introducing a result type wrapping or extending the result value type is complexity I would be very evasive to introduce if the language doesn't already support result wrapper/state types.
This is quite standard, and in fact it's even a safety feature. C++ introduced nullptr defined as an instance of std::nullptr_t explicitly with this in mind.
https://en.cppreference.com/w/cpp/language/nullptr
This approach is also quite basic in monadic types.
With what in mind? Evading
NULL
?Languages that make use of references rather than pointers don't have this Dualism. C# has nullable references and nullability analysis, and
null
as a keyword.What does your reasoning mean in that context?
It's not about references vs pointers. You could easily have a language that allowed "null references" (edit: too much C++; of course many languages allow null references, e.g. Javascript) or one that properly separated null pointers out in the type system.
I agree with your point though, using a special
Null
value is usually worse than usingOption
or similar. Andnullptr_t
doesn't help with this at all.Not sure I follow you...
Depends on your perspective. It's convenient to lean on type checking to avoid a whole class of bugs. You can see this either as avoiding NULL or use your type system to flag misuses.
C#'s
null
keyword matches the monadic approach I mentioned earlier. Nullable types work as aMaybe
monad. It's the same concept shoehorned differently due to the different paths taken by these languages.as far as I know, C# don't have proper ergonomic monadic bind as in F# (computation expression), Haskell (do expression), and Ocaml (let*), but I could be wrong.
Correct.