this post was submitted on 05 Sep 2024
55 points (92.3% liked)

Programming

17313 readers
95 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
[–] [email protected] 10 points 1 month ago* (last edited 1 month ago) (10 children)

The items don't seem concise and always clear. But seems like a good, inspiring resource for things to consider.

If it is expected that a method might fail, then it should fail, either by throwing an Exception or, if not - it should return a special case None/Null type object of the desired class (following the Null Object Pattern), not null itself.

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.

[–] [email protected] 2 points 1 month ago (7 children)

I’ve never heard of evading null with a Null object.

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.

[–] [email protected] 4 points 1 month ago* (last edited 1 month ago) (4 children)

with this in mind

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?

[–] [email protected] 5 points 1 month ago* (last edited 1 month ago)

Languages that make use of references rather than pointers don’t have this Dualism.

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 using Option or similar. And nullptr_t doesn't help with this at all.

load more comments (3 replies)
load more comments (5 replies)
load more comments (7 replies)