1 Comment Ooooh The Pain – Regions in C#

  1. The CoatTails-Riding Developer

    Equating region folding and OO misunderstands the best practices use for this feature in Visual Studio. I agree with you that logic that can be encapsulated into a class or method should not be instead used in regions. If anything in the region could operate on it’s own, a developer should consider of placing this logic in another class or method. Your argument has merit on these principles.

    Just because someone tries to screw in a nail with a hammer doesn’t mean the hammer is defective. Just means a moron is trying to use it. That goes the same way with code folding.
    I will go out on a limb here and say what i consider Best Practices:
    1) Separating code out into parts of the class. This would be separating your properties ,events, methods, back end store variables, etc so that you can find them as needed when you do use your little mouse wheel.
    2) Folding out procedural code that is needed but muddles the high level reading of the class. Yes, this is a fine line. No this doesn’t mean you hide away the crap code. This means that the coder is the judge of what really needs another class. Does a 4 liner chunk of code need a whole new class (new address)? If it is used only once, fold it maybe. If you need that functionality later in another class, or during re-factoring you find a better way, promote it to a class, but not really before. Improper class creation (i.e. a bucket full of one line classes) is just as bad (IMHO) as what Atwood is complaining about.

    By the way, all sorts of IDE ‘s have this feature… someone must think it is a good idea. http://bit.ly/j8Ot65


Leave A Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>