Jeremy D. Miller -- The Shade Tree Developer

Sponsors

The Lounge

Wicked Cool Jobs

Syndication

News

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
"#region/#endregion" Tags Smell Bad
Ranting ahead...

I'm unilaterally declaring overuse of the "#region / #endregion" blocks in VS.NET a code smell. When I first started playing with VS.NET in 2001 I thought this feature was going to be the best thing since sliced bread. Boy, was I wrong. It seems like every time I expand an innocuous looking region out spills a big bag of entirely unrelated code.

Much like the excessive comments code smell, the existence of a large code region generally implies that the code in the region really should be in a different method or even a different class. The region block is no substitute for good factoring. The region block is often used as just a bit of perfume sprayed over smelly code.

If you want what I would call a bad example, go take a look at the source code of the original application blocks from Microsoft Patterns and Practices. Instead of factoring functionality, they wrote more or less procedural code segregated by region blocks that were nested 4-5 layers deep. From what I understand, the code style was mandated by their internal QA code standards. The result is thoroughly unreadable code. Finding the code that does anything is like playing a game of hide and go seek in a thick forest.

The .Net community's tendency to take anything written or published from MS as the gospel without any kind of critical analysis is a huge pet peeve of mine. The original application blocks were a good example. The code was rotten and they were reportedly buggy in spots -- but I saw nary a word of criticism anywhere.

Posted Mon, Jun 27 2005 6:23 PM by Jeremy D. Miller

[Advertisement]

Comments

Cal wrote re: "#region/#endregion" Tags Smell Bad
on Tue, Oct 30 2007 5:56 PM

I personally think they should be banned. I work with a few people that love to use them as "comments". I hate having to work around them to see the code. Their response is that the region tag "comments" should tell me what I need to know and that all I have to do is open the tag if I want to see the code. Little do they know that I'm quite comfortable reading the matrix and they've just thrown a monkey wrench my abilities to do so easily.

Ditch the region tags people!

Derik Whittaker wrote Overuse of #Regions
on Tue, Jan 15 2008 8:57 AM

Before I get started, I personally am a fan of using #regions in my code.  I think it cleans up

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Devlicio.us