Stupid Question 44: Should I use regions in my code?
People like to organize and section of things, but should be even do that in code?
Let me start by saying that I don’t use regions in my code, I never did in the beginning and got used to not having regions. But many developers use regions, and I remember having a discussion with some fellow student when we were doing a group project as I was annoyed with the regions and he was annoyed for me not using them. During my internship I had the pleasure of working with a code base that was disastrous, code behind files spanning thousands and thousands of lines. Regions weren’t a bad thing there, especially since we had no time to refactor and had to find a way to live with the code. Today, I am very happy without regions and don’t mind a bit of a scroll if the code gets a little bit longer (although I do try to avoid that). SO my answer is:
I don’t use regions, I dislike them just as much as I dislike comments. With that said, sometimes a comment does serve a purpose, and sometimes regions can serve a purpose. But regions are best avoided if I can avoid them. With that said, sometime I probably will use them. But I shouldn’t need them (90% of the time- in an ideal world LOL), they probably will only make sense to me, and they give (for me) the impression of trying to ‘hide’ code. They fold it away. Like chucking stuff under the bed when cleaning, you can still pull it out, but it would be better if you had cleaned up properly instead, I’ve seen that a lot.
This is my thinking, based on what I’ve picked up from devs around me, and also heavily based on ‘feelings’. But I am very keen to hear what others think! And in particular when it is a good idea to use regions :)
Last modified on 2012-09-14