55
Code Smells Catalog (luzkan.github.io)
you are viewing a single comment's thread
view the rest of the comments
[-] Kissaki@programming.dev 10 points 2 months ago* (last edited 2 months ago)

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.

[-] LemoineFairclough@sh.itjust.works 2 points 2 months ago

This might be educational: https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html

There are issues that the Optional class alleviates that are common enough to be documented: https://www.jetbrains.com/help/inspectopedia/ConditionalCanBeOptional.html (more detail is available at places like https://github.com/JetBrains/intellij-community/blob/a2d32ec64ed0fb37c7cc97856aa94cce95b17ee5/java/java-impl/src/inspectionDescriptions/ConditionalCanBeOptional.html (I believe this information used to be visible with the "inspectopedia" URLs but I don't see that today))

On the other hand, it seems there are some features / situations that require null to be present: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining https://www.jetbrains.com/help/inspectopedia/OptionalToIf.html

load more comments (9 replies)
this post was submitted on 05 Sep 2024
55 points (92.3% liked)

Programming

17351 readers
260 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 !webdev@programming.dev



founded 1 year ago
MODERATORS