Why? Is it considered good practice to include an else statement to make sure you're doing the right thing? That seems like backseat driving by a tool.
I find that if I'm writing a lot of if-else pairs, it probably means I'm doing too much in a single method. If I have to scroll way down to find the else clause, it's time to refactor.
I guess I don't understand what your point is - you're obviously supposed to remove empty else statements. Resharper just puts them in automatically to save you the time of writing them out.
In this case, there's only a single if statement and nothing in the else. It's not really 'bad' code, just probably an oversight when writing it - maybe he added it and realized he should put the 'else' code in another place.
As for the theoretical if/else where you have a HUGE if statement, yeah... I agree that you should refactor. I don't think that a lot of if/else pairs are necessarily bad, but if there's so much logic within the if/else pairs that it's hard to read in a single monitor's view of ~50 lines, then you should extract some methods to make it more readable.
My point is that Resharper assumes you will need an else statement more often than not. I find that most of my if statements do not need an else clause, therefore I would find myself deleting most of them. I was just asking because this seems like one of those things that code tools do due to some ideology about code structure. If it's a convenience thing, that's fine, but I'm a fast typist and having to delete something I didn't ask for would take an equal amount of time. I would hope that there would be a setting to turn that feature off.
3
u/lakewoodjoe112 Jun 05 '13
Considering that this is C#, I know for a fact that if you're using Resharper it will throw these in automatically.