Robert's blog
Robert Važan

ReSharper considered harmful

More specifically, ReSharper default formatter is considered harmful. It turns neat, clean code into bloated, verbose mess.

I urge you to stop using ReSharper. Not only it hurts your own productivity, it's a terrible impediment for everyone working on the same source code. ReSharper is basically a covert obfuscator working on source code level. It's indispensable tool of every software saboteur.

Did you know that big monitors help productivity? And do you know why is that? Yes, more information on screen. You can navigate with eyes much faster than with keystrokes. ReSharper guys apparently found all that information distressing and decided to introduce some whitespace.

Many of us are doing data-driven WPF apps where a lot of code consists of really simple property getters that merely contain an expression combining data from other properties. The whole property definition including the getter fits snugly on a single line. Whole view model can fit on single screen. You can understand it at a glance.

Run that through ReSharper and you will get 500 lines of incomprehensible mess. It will put every single curly brace on new line. No one-liners. A property with getter and setter, however trivial, will be expanded to 12-13 lines, 6 for curly braces, 2 for get/set keywords, 2 for the trivial getter/setter body, 1 for property name and type, and 1-2 empty lines separating properties and possibly getter from setter.

public TradeConditionRowViewModel PrimaryCondition
{
    get
    {
        if (Data != null)
        {
            return new TradeConditionRowViewModel(Data.PrimaryCondition, true);
        }
        return null;
    }
}

Yes, that one property will be easier on your eyes, but the view model as a whole now resembles large mirror maze. Every screen looks simpler, but there are more screens to process. It's like going from 24" monitor to 4" phone. It's ostrich head in sand. Let's pretend all those other screens do not exist and enjoy this simple one.

I am really fond of anonymous methods in C# and the fine art of meta-programming they support. I write really long anonymous methods in many places. I format them like for loops with anonymous method in place of the for loop body. It's really clever and neat.

ReSharper authors apparently thought that anonymous methods are unthinkable magic not to be touched by average programmer. ReSharper will devilishly indent all curly braces up to the level where "() =>" appeared on previous line, which is often over 80 characters deep, because anonymous methods tend to be meta-method's last parameter. Ditto for property intializers.

ConditionPanelResource resource = Gateway.Instance.Get(new ConditionPanelQuery
                                                                        {
                                                                            PrimaryIndicatorInstanceId = PrimaryIndicatorId.Value.Value
                                                                        });

ReSharper will then cram the whole anonymous method in a narrow strip somewhere between columns 100 and 140. Since most lines do not fit in that space, it will break every statement over 4-10 lines with one token per line. That surely improves readability, ReSharper devs thought. Ever heard of word wrap in VS code editor? It makes religious wars over line length unnecessary.

And who in their right mind could have thought that removing System.Linq namespace is a good idea? If you open a file with namespaces optimized by this tool, you will notice that IntelliSense suddenly stopped working for LINQ queries and no Enumerable extension methods show up. You have to go up to the top of the file and add that namespace manually again.

C# 3.0 brought us var keyword, which moved C# closer to brevity of functional, dynamic languages while keeping the old-fashioned type system happy. ReSharper guys couldn't stand the hacker heresy and implemented automatic translation of var keyword into actual type, adding sufficient boilerplate to make the code look "professional" and "enterprise" worthy. Couldn't they just switch to java?

I know you can configure ReSharper to do things differently, but most people don't do it. The tool comes with disastrous defaults, encouraging malpractice on mass scale. Some people try to fight back and configure the tool, but that configuration is hard to sync among developers and it eventually gets lost after some upgrade or hardware change. People stop trying after some time.

Oh, yeah, ReSharper provides cure to some of the diseases it causes. Messy code? We have got clever code navigation! Missing namespaces? We have advanced auto-complete! Code impossible to edit? Let's reformat everything again! Smart marketing creates problems before offering solutions. It's like addiction. It hurts you, but you cannot quit. It's like infection. Once one developer is infected, all team members are at constant risk.

Please, please, please, stop using ReSharper now. You are causing grief to everyone around you. Grief? What grief? Well, I don't know about you, but I don't want to look at my code through 4" screen. That's seriously painful. Once you teach developers that boilerplate is good, artificial complexity spreads everywhere like plague.

Stop ReSharper now. Refuse to buy licenses. Revert changesets infected with ReSharper malaise. Implement coding standards incompatible with ReSharper. Sandbox offenders into isolated modules and have them eat their own crap. Do whatever it takes. Use your imagination. Form a war front shielding hard-working Hobbits from the evil ReSharper.