4 ms·
Definitely just turn off the cop if you don't like it. But let's nitpick a bit. I find it interesting that the arguments made in the article are about the inte
by resonious 6y ago
Definitely just turn off the cop if you don't like it.
But let's nitpick a bit. I find it interesting that the arguments made in the article are about the intention of the programmer.
Perhaps an explicit nil does signal to me that the nil is intentional. But does that mean that all implicit nils are unimportant? For a skilled programmer like the OP, it probably does mean that! But how often do I actually know who wrote the code I'm reading? Of course I can git blame, but maybe the author left the org before I joined. What kind of programmer were they? Are implicit nils important or unimportant to them? Perhaps it's easy to argue that they should be unimportant. But in reality, I don't know what the author of a particular method was thinking while they were writing it. In fact even an explicit nil might be unimportant. Maybe somebody replaced a `raise SomethingError` line with `nil` to hot-fix an urgent bug.
I guess from my perspective as a long-time Ruby developer, all nils are important. It doesn't matter what the intention of the programmer was. Ruby is very expressive and very dynamic - anything can return nil and there are a hundred ways to do it. If your nil is intentional, write a test case for it. If you have no test suite in a Ruby project, then may God have mercy on your soul.
- boyakasha 6y agoThat's something to keep in mind, but it's not the whole picture. Just because it's not guaranteed to be true doesn't mean that it's unpredictable. Like, you can't guarantee that the file for a Rails controller exists in `app/controllers/`, but that doesn't mean that they are randomly scattered across every directory of the project. It also doesn't mean that every developer puts them in a different folder depending on their personality. Sometimes you need to read carefully to determine the exact behaviour, but you only need rules of thumb to quickly navigate around a project.