Saturday, July 31, 2010

C# regions

I really HATE regions in C# code. What they actually do is only hide the whole blocks of code. You don't see the entire class when you open it in the editor. What you get is the class's name and a bunch of silly blocks which you must click one after another in order to see what they hide... Even after that the code is messed with the f...ing #region ... #endregion there and here. What's the point in collapsing a class into +fields, +constructors, +properties and +methods blocks?!

However, there's a worse thing to do - "regioning" pieces of a single method (yes, I've seen such a horrible things twice or three times in my career). Just imagine a double nested switch 2000 lines of code length. Done? Well. Now surround each of "case" with "region". I've seen it in reality :(

My opinion is simple: regions cause worse code in general - big classes with tons of big methods.

Legacy code and vodka

Reading the excellent "The Art of Unit Testing" book by Roy Osherove, I found a brilliant thought:

"Finally, as a friend once said, a good bottle of vodka never hurts when
dealing with legacy code."

:)