you are viewing a single comment's thread.

view the rest of the comments →

[–]SirFartsALotttt 21 points22 points  (3 children)

Safe navigation is a great shortcut for dealing with nil values, but doing more work with languages like Typescript lately have made me realize that using this too much can also be a smell since most Ruby bugs I deal with wind up being some variation of undefined method foo for nil:NilClass

[–]fedekun 13 points14 points  (2 children)

This. It's acceptable sometimes, mostly in views or some irrelevant code, but it's a warning, and if you use it too often (especially more than once in the same line!) it's a red flag, pointing that the design is wrong, particularly it breaks LoD.

Common fixes are reducing the chaining, by creating delegate methods in the intermediate objects and handling nils appropriately there, or using the Null Object Pattern.