Heh, I think I’m beginning to get the smackdown model, some interesting comments have emerged here.
I’ve used regions in moderation in the past with some success, though I could take or leave it. As usual though, my opinions suffer from never having to have maintained a large project.
One place I used to use regions all the time was for properties, to wrap up the boilerplate getter and setter code. Fortunately that problem has largely been solved with automatic properties (and hopefully we’ll see automatic backing variables in the next version of C#).
Several people have expressed a disbelief that you need to manually specify regions for code folding. The truth of the matter is that VS does quite a bit of automatic folding, though not to the granularity of most other editors. You can fold using directives, namespaces, comments (including XML comments), classes and methods (I might have missed some) but not things like conditionals and loops. Personally I’ve never had a need to fold at the level of individual conditionals and loops (if you do, it probably needs to be refactored) but I can’t see it would be something terrible difficult to add to the IDE and it most likely has already been considered, so I wonder why it hasn’t.
I hate it when you implement the interface in Visual studio and it auto-adds regions around the generated code. And when you add the interface and click it again, you get yet another region. Bad.
You can turn that off in Options-Text Editor-[Language]-Advanced-Advanced. I do think it’s the wrong default though.
Errr… I use regions in the VB.NET Express IDE and it does NOT automatically fold them closed every time I open up a file.
I think it may remember them in the user options file of the project, which tends not to be distributed or source controlled.
So Jeff, do you use XMLDoc comments? I’ve used them for a library I wrote that I thought might end up being public and I hate them. They clutter up the code so much. Do you think it’s bad form to stick with standard comments for internal projects where you don’t really need a help document?
I find XMLDoc comments incredibly useful, even for internal/personal projects. Remember if your using Intellisense the XMLDoc comments come up in the tooltips which, if you’ve not touched the project in a while can be extremely useful in remembering what a particular method does or one of it’s bizarre edge cases. You can collapse up XMLDoc comments, though annoyingly there isn’t an option to collapse them all at once.
If the code would fold with one click to give you a nice clean definition, that would perhaps make it worthwhile. But it doesn’t. Particularly if you have regions within your class.
Forgive me if I misunderstood but you can collapse to definitions (Context Menu-Outlining-Collapse to Definitions). It doesn’t show just the public interface (Object Browser is good for that) but it makes it easier to see. Of course it doesn’t play well with regions, as someone else pointed out.
This is analogous to menus, treeviews, toolbars, etc in UI design. You can use these organizational tools to make things easier to use and find, or you can create a mess.
Of course, Jeff has stated that he hates trees too