Do not introduce the curse of #regions to HTML
In VS2013.4RC you have announced #region support for HTML: http://blogs.msdn.com/b/webdev/archive/2014/10/16/announcing-new-web-features-in-visual-studio-2013-update-4-rc.aspx
I understand that removing #regions from C#, as previously suggested and declined, would be unreasonable at this late stage (https://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2678342--region-directive-considered-harmful-was-get-rid).
Let's not introduce this curse to new languages though.
Regions are a way for mediocre teams to hide ****** code behind a roll-up. They are not a productivity extension. They do not help lift the breadth developers forward.
Thanks for the feedback. Though a bit controversial, this feature has been requested for a long time by many Visual Studio users and will therefore stay in Visual Studio 2015.
Sr. Program Manager
Visual Studio Web Team
Lucas Arcega commented
Keep it simple bro! Don't like regions? Ignore Then!
@Jordan: I don't see a flame war in the discussion of methodology.
However, as for #regions usefulness in HTML, it is the same usefulness in any large code-base: Folding similar code together, so that it doesn't clutter up the text editor. And it has the same failure possibility in any large code-base: Hiding code smells in the hopes that they won't be examined.
However, the former is programmer effectiveness, and the latter is bad programming. Any code or IDE feature can be used to write bad code. That a code feature can be used to write bad code as well as good, does not mean the feature is bad. It may mean the feature could be improved, and I, personally, would be interested in useful improvements in #regions.
However, my posts have been reactionary. If this has resulted in negatives in the discussion, I apologize.
Jordan Tucker commented
This topic has turned into a flame war regarding #regions in general instead of a discussion regarding their usefulness in HTML.
In C# the use of #region diminished with the introduction of the partial key word. Personally, I think regions are "okay" in large C# files, but I'd rather see multiple files that use the partial key word.
Use cases for HTML should be presented in defense of #regions in HTML. HTML by design is hierarchically structured, so #regions would just seem to add unnecessary code, especially when edited in an IDE or text editor that doesn't support #regions.
@Jiggaboo: Your statement readsd "Most people say they use regions to organize code. Therefore, your code is bad because you use regions to hide it."
Your second statement does not follow from your first. You seem to be conflating a large code file with large method bodies, or inflated classes. The two are not the same.
This is an error I see some programmers make time and again: Assuming that your particular use case is everyone's use-case, and how one particular type of program is organized, is how all programs are organized.
There is no useful way in C# to, for example, split a standard game programming Matrix4x4 struct into multiple sub-classes, and said data structure would not be useful if it were not a struct. Further, there are many other cases where sub-classes are not optimal.
Lastly, too many sub-classes is its own code smell; when you have to visit six different sub-classes to figure out how a simple function works, something has gone wrong.
tl;dr? Your assumption is unwarranted.
See how regions are used at http://clipflair.codeplex.com which is a big code base. I usually divide the code in Constants, Fields, Initialization, Cleanup, Properties, Methods, Events with subregions in them e.g per DependencyProperty etc.
Without regions code is too hard to maintain/browse
In fact they should show up in document outline pane
In some cases I choose to group aspects of code in regions like Load/Save, etc.
There is extension that provides regions for XAML too via special comments and so exists for netbeans jsp, so why not for HTML?
You must have had a bad experience with someone elses code. I've seen fine examples of small files using regions. Code organization is fine. And its great for focusing.
#region offhanded comment
ignore this guy, please
Most of people here say that they use regions to organize large files/classes. That's the point! You create this awful code and hide it inside regions. And then someone has to work with this.
#Region's are awesome... Why would anyone want to remove a feature like this?
The people that say it lets programmers hide bad code, how hard is it to unfold it? Just Ctrl-M + L and all regions are open. I would argue that the bad programmer is probably more the guy who gets stomped by an organizational feature.
Regions are excellent tools to organize code and focus your attention on the code you are working on. My only gripe with them is that personally I think they should be indented with the code. Just less disruptive when reading code...
Mark Jones commented
1) #region is highly useful for organizing well-structured code. As a seasoned developer (30+ years), I find they help me greatly in maintaining and/or digesting large, complex classes. Using 'partial' has its place, but my go-to mechanism has been #region since it was introduced.
2) Mr. 'Tatham Oddie''s suggestion fits his online handle -- it's really odd. It would have helped a lot if he had provided some logical rationale. His mania about this is incomprehensible.
Tom Allen commented
I love regions. They are a handy way to view large files.
An alternate would be to create "dynamic regions", where every bracketed control construct could be collapsed. It's very handy to use ctrl-M + ctrl-L to toggle expansion, so keep that ability. Thx!
I always thought that the discussion about regions was neither right nor wrong. I thought it was simply insane. What I didn't realize was that regions work differently in C# (which I use only a little) and VB (which I use a lot). Regions in VB are harmless, and the criticisms raised about regions don't apply. Regions in C# can cause all kinds of mischief. Starting with the next version of VS, VB will move to adopt the C# model of regions, in which case I will no longer see the discussion as insane, and will move slightly to the side of feeling that they are harmful. Not decisively so, though, because they can be used harmlessly.
The difference between VB and C#, up until they converge with VS2015, is that VB didn't allow regions in methods. This meant that in VB, a region was no more than an organizational tool much like multiple files, or the ability to collapse methods. Sure, you could go overboard and have folders inside folders inside folders, but that is true of any file system, and we all know people who go nuts with this in one way or the other (such as people with large monitors that are absolutely packed to capacity with icons). What you couldn't use regions for, in VB, was to hide code within methods. When you expanded a method, you saw the whole thing, with no means to hide part of the code. In C#, when you expand a method...some of it might remain hidden.
Frankly, if you feel the temptation to put a region within a method, I would say that you should examine the origin of that feeling. It may well be a good indication that the method should be refactored, because it has become sufficiently complex as to not fit comfortably within a single brain at a single debugging session. Using regions outside of methods just means that you are moderately organized, and nothing more.
Right click on page. Select outlining->Stop outlining.
Even faster, hit ctrl M+P.
Personally, I'd find writing, for example, Matrix4x4 code a more tedious without regions. You're complaining about something a lot of coders use legitimately, for it's actual purpose, which is to organize code.
Ross Dickinson commented
No one's forcing you to use regions.
I AM OZ! THE GREAT AND POWERFUL! THOU SHALT NOT USE REGIONS WITHIN THE LAND OF OZ.
I am Dorothy. The meek and mild. I like using regions when...
BE SILENT, WHIPPER SNAPPER! THE GREAT OZ HAS SPOKEN!
Jiminy crickets! I guess you better what is good for me than I do.
David Lean commented
I disagree with this idea.
I love regions. They are a very convenient way to get the code I'm not currently working on, out of the way.
Similar to split screen. But persists until I'm done working on that feature, I can "split" in multiple places.
Luis Esteban Valencia Muñoz. commented
disagee with this idea, its not about ****** teams hiding crapy code its about good teams organizing the code well using regions, if you dont like a feature, you are not forced to use it.
Region definitely helps reading large files and in html would be amazing
Are you mad? (speaking of removing #region from C#)
Sometimes the file is too large to get an overview, even when all methods are closed. Then #region's are an irreplaceable aid to hide the code you currently don't care about.
What I dislike in C# #region is that it is indented with the code. In VB the #Region is always on column 1. Please, do it this way, as #region is not a part of code, and therefore should stay aside.
Florian S. commented
I don't see regions as a beginner's feature, and if people are using them to hide bad code, it's just an abuse of the concept.
I use regions a lot for structuring my code, to separate properties, events, methods, separate private from public APIs when appropriate etc. Especially when objects get large I like the ability they give you to hide certain sections you're currently not interested in, and I don't see anything wrong with that. Maybe "#region" is a bad name choice, "#section" would better describe their role in structuring code, but it's too late for that.