Stop Doing One Liners
Fewer lines of code aren’t always better
I was debugging this method the other day:
Here are some issues I found with this one liner:
Viewing the return value is inconvenient
Instead of just being able to hover over a variable, I had to highlight everything after return
and add it to the watch window.
Updating the return value during testing is impossible
Since IdMap.Contains<Deposit>(dto.DepositID)
isn’t a variable, I wasn’t able to update the return value in Visual Studio’s Immediate window, like I sometimes need to do.
Make other developers’, and your life easier, use two lines!
Had the code been written like this, it would have been MUCH easier to debug:
Summary of comments from Reddit
I discussed this topic on Reddit and most people were against it.
Here’s a summary of their points, and my responses:
You can use the Autos window to view function return values
You can also do that with a variable as well. By having a variable, you’re providing the option to developers to hover their cursor over the variable to view the value if they want to.
The autos window can be flooded with other variables that you don’t care about. Having to sift through, or scroll, to find your variable, is not ideal.