<p>For those of you in the Visual Studio environment, how do you feel about wrapping any of your code in #regions?  (or if any other IDE has something similar...)</p>

[{'answer_id': 5923, 'author': 'Teifion', 'author_id': 1384652, 'author_profile': 'https://Stackoverflow.com/users/1384652', 'pm_score': 2, 'selected': False, 'text': '<p>I use <a href="http://macromates.com/" rel="nofollow noreferrer">Textmate</a> (Mac only) which has Code folding and I find it really useful for folding functions, I know what my "getGet" function does, I don\'t need it taking up 10 lines of oh so valuable screen space.</p>\n\n<p>I never use it to hide a for loop, if statement or similar unless showing the code to someone else where I will hide code they have seen to avoid showing the same code twice.</p>\n'}, {'answer_id': 5929, 'author': 'Pat', 'author_id': 36, 'author_profile': 'https://Stackoverflow.com/users/36', 'pm_score': 4, 'selected': False, 'text': '<p>This was talked about on <a href="https://blog.codinghorror.com/the-problem-with-code-folding/" rel="nofollow noreferrer">Coding Horror</a>.</p>\n\n<p>My personal belief is that is that they are useful, but like anything in excess can be too much. </p>\n\n<p>I use it to order my code blocks into:\n<br>Enumerations\n<br>Declarations\n<br>Constructors\n<br>Methods\n<br>Event Handlers\n<br>Properties</p>\n'}, {'answer_id': 5930, 'author': 'Brian Childress', 'author_id': 721, 'author_profile': 'https://Stackoverflow.com/users/721', 'pm_score': 1, 'selected': False, 'text': '<p>I personally use #Regions all the time. I find that it helps me to keep things like properties, declarations, etc separated from each other.</p>\n\n<p>This is probably a good answer, too!</p>\n\n<p><a href="https://blog.codinghorror.com/the-problem-with-code-folding/" rel="nofollow noreferrer">Coding Horror</a></p>\n\n<p>Edit: Dang, Pat beat me to this!</p>\n'}, {'answer_id': 5953, 'author': 'Greg Hurlman', 'author_id': 35, 'author_profile': 'https://Stackoverflow.com/users/35', 'pm_score': 3, 'selected': False, 'text': "<p>While I understand the problem that Jeff, et. al. have with regions, what I <em>don't</em> understand is why hitting <kbd>CTRL</kbd>+<kbd>M</kbd>,<kbd>CTRL</kbd>+<kbd>L</kbd> to expand all regions in a file is so difficult to deal with.</p>\n"}, {'answer_id': 5954, 'author': 'Adam V', 'author_id': 517, 'author_profile': 'https://Stackoverflow.com/users/517', 'pm_score': 0, 'selected': False, 'text': "<p>I prefer #regions myself, but an old coworker couldn't stand to have things hidden. I understood his point once I worked on a page with 7 #regions, at least 3 of which had been auto-generated and had the same name, but in general I think they're a useful way of splitting things up and keeping everything less cluttered.</p>\n"}, {'answer_id': 5962, 'author': 'Jon Limjap', 'author_id': 372, 'author_profile': 'https://Stackoverflow.com/users/372', 'pm_score': 2, 'selected': False, 'text': '<p>I prefer partial classes as opposed to regions.</p>\n\n<p>Extensive use of regions by others also give me the impression that someone, somewhere, is violating the Single Responsibility Principle and is trying to do too many things with one object.</p>\n'}, {'answer_id': 5971, 'author': 'Tom', 'author_id': 20, 'author_profile': 'https://Stackoverflow.com/users/20', 'pm_score': 2, 'selected': False, 'text': "<p>I'm not a fan of partial classes - I try to develop my classes such that each class has a very clear, single issue for which it's responsible. To that end, I don't believe that something with a clear responsibility should be split across multiple files. That's why I don't like partial classes.</p>\n\n<p>With that said, I'm on the fence about regions. For the most part, I don't use them; however, I work with code every day that includes regions - some people go really heavy on them (folding up private methods into a region and then each method folded into its own region), and some people go light on them (folding up enums, folding up attributes, etc). My general rule of thumb, as of now, is that I only put code in regions if (a) the data is likely to remain static or will not be touched very often (like enums), or (b) if there are methods that are implemented out of necessity because of subclassing or abstract method implementation, but, again, won't be touched very often.</p>\n"}, {'answer_id': 5972, 'author': 'Joseph Daigle', 'author_id': 507, 'author_profile': 'https://Stackoverflow.com/users/507', 'pm_score': 3, 'selected': False, 'text': '<p>Sometimes you might find yourself working on a team where #regions are encouraged or required. If you\'re like me and you can\'t stand messing around with folded code you can turn off outlining for C#:</p>\n\n<ol>\n<li>Options -> Text Editor -> C# -> Advanced Tab</li>\n<li>Uncheck "Enter outlining mode when files open"</li>\n</ol>\n'}, {'answer_id': 5990, 'author': 'EndangeredMassa', 'author_id': 106, 'author_profile': 'https://Stackoverflow.com/users/106', 'pm_score': 3, 'selected': False, 'text': "<p>I use #Region to hide ugly and useless automatically generated code, which really belongs in the automatically generated part of the partial class. But, when working with old projects or upgraded projects, you don't always have that luxury.</p>\n\n<p>As for other types of folding, I fold Functions all the time. If you name the function well, you will never have to look inside unless you're testing something or (re-)writing it.</p>\n"}, {'answer_id': 6287, 'author': 'Kev', 'author_id': 419, 'author_profile': 'https://Stackoverflow.com/users/419', 'pm_score': 2, 'selected': False, 'text': '<p>@<a href="https://stackoverflow.com/questions/5916/how-do-you-feel-about-code-folding#5971">Tom</a></p>\n\n<p>Partial classes are provided so that you can separate tool auto-generated code from any customisations you may need to make after the code gen has done its bit. This means your code stays intact after you re-run the codegen and doesn\'t get overwritten. This is a good thing. </p>\n'}, {'answer_id': 6295, 'author': 'Brandon Wood', 'author_id': 423, 'author_profile': 'https://Stackoverflow.com/users/423', 'pm_score': 0, 'selected': False, 'text': "<p>I really don't have a problem with using #region to organize code.  Personally, I'll usually setup different regions for things like properties, event handlers, and public/private methods.</p>\n"}, {'answer_id': 7752, 'author': 'Adam Lerman', 'author_id': 673, 'author_profile': 'https://Stackoverflow.com/users/673', 'pm_score': 0, 'selected': False, 'text': '<p>Eclipse does some of this in Java (or PHP with plugins) on its own. Allows you to fold functions and such. I tend to like it. If I know what a function does and I am not working on it, I dont need to look at it.</p>\n'}, {'answer_id': 7767, 'author': 'Lars Mæhlum', 'author_id': 960, 'author_profile': 'https://Stackoverflow.com/users/960', 'pm_score': 6, 'selected': True, 'text': '<p>9 out of 10 times, code folding means that you have failed to use the <a href="http://en.wikipedia.org/wiki/Separation_of_concerns" rel="noreferrer">SoC principle</a> for what its worth.<br />\nI more or less feel the same thing about partial classes. If you have a piece of code you think is too big you need to chop it up in manageable (and reusable) parts, not hide or split it up.<br />It will bite you the next time someone needs to change it, and cannot see the logic hidden in a 250 line monster of a method.<br />\n<br />\nWhenever you can, pull some code out of the main class, and into a helper or factory class.\n<br /></p>\n\n<pre><code>foreach (var item in Items)\n{\n    //.. 100 lines of validation and data logic..\n}\n</code></pre>\n\n<p>is not as readable as</p>\n\n<pre><code>foreach (var item in Items)\n{\n    if (ValidatorClass.Validate(item))\n        RepositoryClass.Update(item);\n}\n</code></pre>\n\n<p><br />\n<br />\nMy $0.02 anyways.</p>\n'}, {'answer_id': 9049, 'author': 'Serhat Ozgel', 'author_id': 31505, 'author_profile': 'https://Stackoverflow.com/users/31505', 'pm_score': 2, 'selected': False, 'text': "<p>Regions must never be used inside methods. They may be used to group methods but this must be handled with extreme caution so that the reader of the code does not go insane. There is no point in folding methods by their modifiers. But sometimes folding may increase readability. For e.g. grouping some methods that you use for working around some issues when using an external library and you won't want to visit too often may be helpful. But the coder must always seek for solutions like wrapping the library with appropriate classes in this particular example. When all else fails, use folding for improving readibility.</p>\n"}, {'answer_id': 9053, 'author': 'Thomas Owens', 'author_id': 572, 'author_profile': 'https://Stackoverflow.com/users/572', 'pm_score': 1, 'selected': False, 'text': "<p>I think that it's a useful tool, when used properly. In many cases, I feel that methods and enumerations and other things that are often folded should be little black boxes. Unless you must look at them for some reason, their contents don't matter and should be as hidden as possible. However, I never fold private methods, comments, or inner classes. Methods and enums are really the only things I fold.</p>\n"}, {'answer_id': 9063, 'author': 'Mun', 'author_id': 775, 'author_profile': 'https://Stackoverflow.com/users/775', 'pm_score': 1, 'selected': False, 'text': '<p>My approach is similar to a few others here, using regions to organize code blocks into constructors, properties, events, etc.</p>\n\n<p>There\'s an excellent set of VS.NET macros by Roland Weigelt available from his blog entry, <a href="http://weblogs.asp.net/rweigelt/archive/2003/07/06/9741.aspx" rel="nofollow noreferrer">Better Keyboard Support for #region ... #endregion</a>.  I\'ve been using these for years, mapping ctrl+. to collapse the current region and ctrl++ to expand it.  Find that it works a lot better that the default VS.NET functionality which folds/unfolds everything.</p>\n'}, {'answer_id': 14568, 'author': 'rjzii', 'author_id': 1185, 'author_profile': 'https://Stackoverflow.com/users/1185', 'pm_score': 1, 'selected': False, 'text': '<p>The <a href="https://blog.codinghorror.com/the-problem-with-code-folding/" rel="nofollow noreferrer">Coding Horror</a> article actual got me thinking about this as well.</p>\n\n<p>Generally, I large classes I will put a region around the member variables, constants, and properties to reduce the amount of text I have to scroll through and leave everything else outside of a region. On forms I will generally group things into "member variables, constants, and properties", form functions, and event handlers. Once again, this is more so I don\'t have to scroll through a lot of text when I just want to review some event handlers.</p>\n'}, {'answer_id': 25984, 'author': 'dmckee --- ex-moderator kitten', 'author_id': 2509, 'author_profile': 'https://Stackoverflow.com/users/2509', 'pm_score': 0, 'selected': False, 'text': "<p>Emacs has a folding minor mode, but I only fire it up occasionally. Mostly when I'm working on some monstrosity inherited from another physicist who evidently had less instruction or took less care about his/her coding practices. </p>\n"}, {'answer_id': 26003, 'author': 'Tundey', 'author_id': 1453, 'author_profile': 'https://Stackoverflow.com/users/1453', 'pm_score': 2, 'selected': False, 'text': "<p>This is just one of those silly discussions that lead to nowhere. If you like regions, use them. If you don't, configure your editor to turn them off. There, everybody is happy.</p>\n"}, {'answer_id': 33023, 'author': 'Scott Dorman', 'author_id': 1559, 'author_profile': 'https://Stackoverflow.com/users/1559', 'pm_score': 0, 'selected': False, 'text': '<p>Using regions (or otherwise folding code) <strong>should</strong> have nothing to do with code smells (or hiding them) or any other idea of hiding code you don\'t want people to "easily" see.</p>\n\n<p>Regions and code folding is really all about providing a way to easily group sections of code that can be collapsed/folded/hidden to minimize the amount of extraneous "noise" around what you are currently working on. If you set things up correctly (meaning actually name your regions something useful, like the name of the method contained) then you can collapse everything except for the function you are currently editing and still maintain some level of context without having to actually see the other code lines.</p>\n\n<p>There probably should be some best practice type guidelines around these ideas, but I use regions extensively to provide a standard structure to my code files (I group events, class-wide fields, private properties/methods, public properties/methods). Each method or property also has a region, where the region name is the method/property name. If I have a bunch of overloaded methods, the region name is the full signature and then that entire group is wrapped in a region that is just the function name.</p>\n'}, {'answer_id': 217785, 'author': 'Daniel Earwicker', 'author_id': 27423, 'author_profile': 'https://Stackoverflow.com/users/27423', 'pm_score': 2, 'selected': False, 'text': '<p>Region folding would be fine if I didn\'t have to manually maintain region groupings based on features of my code that are intrinsic to the language. For example, the compiler already knows it\'s a constructor. The IDE\'s code model already knows it\'s a constructor. But if I want to see a view of the code where the constructors are grouped together, for some reason I have to restate the fact that these things are constructors, by physically placing them together and then putting a group around them. The same goes for any other way of slicing up a class/struct/interface. What if I change my mind and want to see the public/protected/private stuff separated out into groups first, and then grouped by member kind?</p>\n<p>Using regions to mark out public properties (for example) is as bad as entering a redundant comment that adds nothing to what is already discernible from the code itself.</p>\n<p>Anyway, to avoid having to use regions for that purpose, I wrote a free, open source Visual Studio 2008 IDE add-in called Ora. It provides a grouped view automatically, making it far less necessary to maintain physical grouping or to use regions. <a href="http://www.codeplex.com/ora" rel="nofollow noreferrer">You may find it useful</a>.</p>\n'}, {'answer_id': 296577, 'author': 'Mykroft', 'author_id': 2191, 'author_profile': 'https://Stackoverflow.com/users/2191', 'pm_score': 2, 'selected': False, 'text': "<p>I generally find that when dealing with code like Events in C# where there's about 10 lines of code that are actually just part of an event declaration (the EventArgs class the delegate declaration and the event declaration) Putting a region around them and then folding them out of the way makes it a little more readable. </p>\n"}, {'answer_id': 9030438, 'author': 'Piotr Perak', 'author_id': 679340, 'author_profile': 'https://Stackoverflow.com/users/679340', 'pm_score': 0, 'selected': False, 'text': '<p>I personally hate regions. The only code that should be in regions in my opinion is generated code.\nWhen I open file I always start with Ctrl+M+O. This folds to method level. When you have regions you see nothing but region names.</p>\n<p>Before checking in I group methods/fields logically so that it looks ok after Ctrl+M+O.\nIf you need regions you have to much lines in your class. I also find that this is very common.</p>\n<h1>region ThisLooksLikeWellOrganizedCodeBecauseIUseRegions</h1>\n<p>// total garbage, no structure here</p>\n<h1>endregion</h1>\n'}, {'answer_id': 14829202, 'author': 'Lezzer', 'author_id': 1326137, 'author_profile': 'https://Stackoverflow.com/users/1326137', 'pm_score': 0, 'selected': False, 'text': "<p>Enumerations</p>\n\n<p>Properties</p>\n\n<p>.ctors</p>\n\n<p>Methods</p>\n\n<p>Event Handlers</p>\n\n<p>That's all I use regions for.  I had no idea you could use them inside of methods.</p>\n\n<p>Sounds like a terrible idea :)</p>\n"}]
['https://Stackoverflow.com/questions/5916', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/396/']