Do you think #regions and other non used code is good or bad.

I see more and more poeple using 5 to 10 Region Placements and a lot of

comment code at the top of there scripts..

Me I find it meaningless and just overused. I think if you have stuff needs written about your code include a credits.txt or some kind of readme and leave code free of all the garbage..

I do understand using regions in some code that is over 1000 some lines or to block out those properties but im seeing it being used on less then 2 lines of code.

All feedback needs to be friendly and kept on topic please. just wanting to see what ever one else thought. Any fighting starts ill just ask a mod to lock or delete thread.
 
Does it really matter? You can minimize and maximize regions of code in any good IDE. Also, people will use templates or code re factoring which will add the header automatically.

Code comments are absolutely necessary and help people a great amount when they come across a new implementation or feature of dotnet they may not have come across before.

It does not affect the performance of the code in the end of the day.
 
If you use an IDE such as Visual Studios, using regions can add another layer of organization for explaining code. They can be overused for sure. But if a region has only one or two lines of code in it then I would prefer to use a single comment to include any info a region would.
 
I use IDE but I have seen lot code hidden in such small areas . Me personal I do like regions it helps a lot with large segments of code like baseweapon example I went though and put more region code in to look at it better. But I figured this great coding topic.
 
My take on using Regions in scripts:

I believe this is especially helpful when you're altering existing base code (like modifying Playermobile, Basecreature, etc). Lets say you go through this HUGE modification process spanning multiple files (it has happened with some of the things I've tested). What if that system winds up not working and you have to remove it? You can do quick searches for the region names and comment those edited sections out until you can get it fixed or obviously just delete it.

On the flip side, if you're releasing a mod you created and it involves base files edits, region markings can be crucial to locating the proper places to make the edits. Of course commented lines work just as well, but if you're going to do that, why not use a Region?
 
I love regions...makes it much easier searching through code while debugging. You can just collapse the parts that you know have nothing to do with the current issue. Especially helpful in files with lots of lines!
 
Regions should be used when it maximizes readability IMO.

I don't agree with regions that contains so little code, like almost all of the Mondain's Legacy and Stygian Abyss mods, it's annoying to have to expand them every time to find 1 to 10 lines of code, but on the on the hand, when performing merges, they can really help keep track of what you are doing.

Funny story behind regions, IIRC, they were never really intended for developers to use, they were automatically generated by Visual Studio's WinForms UI code generator, to allow developers to hide the WinForms boilerplate code, so they could focus more on the functionality of the UI. Developers ended up adopting and using the technique until it became mainstream.
(Citation needed, trying to find the article on that one)

https://msdn.microsoft.com/en-us/library/9a1ybwek.aspx said:
#region lets you specify a block of code that you can expand or collapse when using the outlining feature of the Visual Studio Code Editor. In longer code files, it is convenient to be able to collapse or hide one or more regions so that you can focus on the part of the file that you are currently working on. The following example shows how to define a region:

For more information - and this is quite an extensive topic - you may revise "(code) folding".
 
Regions suck. The original intention and creation of regions was to hide Designer code from creating Windows Forms back in .Net 1.0 before partial classes existed. Regions and whats in them are always organized incorrectly. People use them to organize logic (events, business logic, ui logic), or by accessibility (private, public, internal). This is terrible and only works if you were the one who wrote the code. Speaking as a software engineer, regions tend to be very contextual to the person who wrote the code because they know the code and know whats inside each region. As an outside developer, I have no idea what you made public, private, etc. And I do not care to see structure like UI logic vs Business logic. When I open a code file, I want to see code, Organization can still be used structurally, but I do not want to have to use a command to open all the regions every single time I open a file (and I open 1000 files a day, our code-base is currently 350K lines of code, with 2.5 million in a separate solution). Regions make sense for single developers, who know they own organizational habits, but once that code is shared its very frustrating.
 
Last edited:
I will add that the only time I feel regions are appropriate are when trying to hide large amounts of data in your code that doesn't change. An example of this would be something like this:

Code:
#region Decompression Tree
static int[,] _huffmanDecompressionTree = new int[256, 2]
{
/*node*/ /*leaf0 leaf1*/
/* 0*/ { 2, 1},
/* 1*/ { 4, 3},
/* 2*/ { 0, 5},
/* 3*/ { 7, 6},
/* 4*/ { 9, 8},
/* 5*/ { 11, 10},
/* 6*/ { 13, 12},
/* 7*/ { 14, -256},
/* 8*/ { 16, 15},
/* 9*/ { 18, 17},
/* 10*/ { 20, 19},
/* 11*/ { 22, 21},
/* 12*/ { 23, -1},
/* 13*/ { 25, 24},
/* 14*/ { 27, 26},
/* 15*/ { 29, 28},
/* 16*/ { 31, 30},
/* 17*/ { 33, 32},
/* 18*/ { 35, 34},
/* 19*/ { 37, 36},
/* 20*/ { 39, 38},
/* 21*/ { -64, 40},
/* 22*/ { 42, 41},
/* 23*/ { 44, 43},
/* 24*/ { 45, -6},
/* 25*/ { 47, 46},
/* 26*/ { 49, 48},
/* 27*/ { 51, 50},
/* 28*/ { 52, -119},
/* 29*/ { 53, -32},
/* 30*/ { -14, 54},
/* 31*/ { -5, 55},
/* 32*/ { 57, 56},
/* 33*/ { 59, 58},
/* 34*/ { -2, 60},
/* 35*/ { 62, 61},
/* 36*/ { 64, 63},
/* 37*/ { 66, 65},
/* 38*/ { 68, 67},
/* 39*/ { 70, 69},
/* 40*/ { 72, 71},
/* 41*/ { 73, -51},
/* 42*/ { 75, 74},
/* 43*/ { 77, 76},
/* 44*/ {-111, -101},
/* 45*/ { -97, -4},
/* 46*/ { 79, 78},
/* 47*/ { 80, -110},
/* 48*/ {-116, 81},
/* 49*/ { 83, 82},
/* 50*/ {-255, 84},
/* 51*/ { 86, 85},
/* 52*/ { 88, 87},
/* 53*/ { 90, 89},
/* 54*/ { -10, -15},
/* 55*/ { 92, 91},
/* 56*/ { 93, -21},
/* 57*/ { 94, -117},
/* 58*/ { 96, 95},
/* 59*/ { 98, 97},
/* 60*/ { 100, 99},
/* 61*/ { 101, -114},
/* 62*/ { 102, -105},
/* 63*/ { 103, -26},
/* 64*/ { 105, 104},
/* 65*/ { 107, 106},
/* 66*/ { 109, 108},
/* 67*/ { 111, 110},
/* 68*/ { -3, 112},
/* 69*/ { -7, 113},
/* 70*/ {-131, 114},
/* 71*/ {-144, 115},
/* 72*/ { 117, 116},
/* 73*/ { 118, -20},
/* 74*/ { 120, 119},
/* 75*/ { 122, 121},
/* 76*/ { 124, 123},
/* 77*/ { 126, 125},
/* 78*/ { 128, 127},
/* 79*/ {-100, 129},
/* 80*/ { -8, 130},
/* 81*/ { 132, 131},
/* 82*/ { 134, 133},
/* 83*/ { 135, -120},
/* 84*/ { -31, 136},
/* 85*/ { 138, 137},
/* 86*/ {-234, -109},
/* 87*/ { 140, 139},
/* 88*/ { 142, 141},
/* 89*/ { 144, 143},
/* 90*/ { 145, -112},
/* 91*/ { 146, -19},
/* 92*/ { 148, 147},
/* 93*/ { -66, 149},
/* 94*/ {-145, 150},
/* 95*/ { -65, -13},
/* 96*/ { 152, 151},
/* 97*/ { 154, 153},
/* 98*/ { 155, -30},
/* 99*/ { 157, 156},
/* 100*/ { 158, -99},
/* 101*/ { 160, 159},
/* 102*/ { 162, 161},
/* 103*/ { 163, -23},
/* 104*/ { 164, -29},
/* 105*/ { 165, -11},
/* 106*/ {-115, 166},
/* 107*/ { 168, 167},
/* 108*/ { 170, 169},
/* 109*/ { 171, -16},
/* 110*/ { 172, -34},
/* 111*/ {-132, 173},
/* 112*/ {-108, 174},
/* 113*/ { -22, 175},
/* 114*/ { -9, 176},
/* 115*/ { -84, 177},
/* 116*/ { -37, -17},
/* 117*/ { 178, -28},
/* 118*/ { 180, 179},
/* 119*/ { 182, 181},
/* 120*/ { 184, 183},
/* 121*/ { 186, 185},
/* 122*/ {-104, 187},
/* 123*/ { -78, 188},
/* 124*/ { -61, 189},
/* 125*/ {-178, -79},
/* 126*/ {-134, -59},
/* 127*/ { -25, 190},
/* 128*/ { -18, -83},
/* 129*/ { -57, 191},
/* 130*/ { 192, -67},
/* 131*/ { 193, -98},
/* 132*/ { -68, -12},
/* 133*/ { 195, 194},
/* 134*/ {-128, -55},
/* 135*/ { -50, -24},
/* 136*/ { 196, -70},
/* 137*/ { -33, -94},
/* 138*/ {-129, 197},
/* 139*/ { 198, -74},
/* 140*/ { 199, -82},
/* 141*/ { -87, -56},
/* 142*/ { 200, -44},
/* 143*/ { 201, -248},
/* 144*/ { -81, -163},
/* 145*/ {-123, -52},
/* 146*/ {-113, 202},
/* 147*/ { -41, -48},
/* 148*/ { -40, -122},
/* 149*/ { -90, 203},
/* 150*/ { 204, -54},
/* 151*/ {-192, -86},
/* 152*/ { 206, 205},
/* 153*/ {-130, 207},
/* 154*/ { 208, -53},
/* 155*/ { -45, -133},
/* 156*/ { 210, 209},
/* 157*/ { -91, 211},
/* 158*/ { 213, 212},
/* 159*/ { -88, -106},
/* 160*/ { 215, 214},
/* 161*/ { 217, 216},
/* 162*/ { -49, 218},
/* 163*/ { 220, 219},
/* 164*/ { 222, 221},
/* 165*/ { 224, 223},
/* 166*/ { 226, 225},
/* 167*/ {-102, 227},
/* 168*/ { 228, -160},
/* 169*/ { 229, -46},
/* 170*/ { 230, -127},
/* 171*/ { 231, -103},
/* 172*/ { 233, 232},
/* 173*/ { 234, -60},
/* 174*/ { -76, 235},
/* 175*/ {-121, 236},
/* 176*/ { -73, 237},
/* 177*/ { 238, -149},
/* 178*/ {-107, 239},
/* 179*/ { 240, -35},
/* 180*/ { -27, -71},
/* 181*/ { 241, -69},
/* 182*/ { -77, -89},
/* 183*/ {-118, -62},
/* 184*/ { -85, -75},
/* 185*/ { -58, -72},
/* 186*/ { -80, -63},
/* 187*/ { -42, 242},
/* 188*/ {-157, -150},
/* 189*/ {-236, -139},
/* 190*/ {-243, -126},
/* 191*/ {-214, -142},
/* 192*/ {-206, -138},
/* 193*/ {-146, -240},
/* 194*/ {-147, -204},
/* 195*/ {-201, -152},
/* 196*/ {-207, -227},
/* 197*/ {-209, -154},
/* 198*/ {-254, -153},
/* 199*/ {-156, -176},
/* 200*/ {-210, -165},
/* 201*/ {-185, -172},
/* 202*/ {-170, -195},
/* 203*/ {-211, -232},
/* 204*/ {-239, -219},
/* 205*/ {-177, -200},
/* 206*/ {-212, -175},
/* 207*/ {-143, -244},
/* 208*/ {-171, -246},
/* 209*/ {-221, -203},
/* 210*/ {-181, -202},
/* 211*/ {-250, -173},
/* 212*/ {-164, -184},
/* 213*/ {-218, -193},
/* 214*/ {-220, -199},
/* 215*/ {-249, -190},
/* 216*/ {-217, -230},
/* 217*/ {-216, -169},
/* 218*/ {-197, -191},
/* 219*/ { 243, -47},
/* 220*/ { 245, 244},
/* 221*/ { 247, 246},
/* 222*/ {-159, -148},
/* 223*/ { 249, 248},
/* 224*/ { -93, -92},
/* 225*/ {-225, -96},
/* 226*/ { -95, -151},
/* 227*/ { 251, 250},
/* 228*/ { 252, -241},
/* 229*/ { -36, -161},
/* 230*/ { 254, 253},
/* 231*/ { -39, -135},
/* 232*/ {-124, -187},
/* 233*/ {-251, 255},
/* 234*/ {-238, -162},
/* 235*/ { -38, -242},
/* 236*/ {-125, -43},
/* 237*/ {-253, -215},
/* 238*/ {-208, -140},
/* 239*/ {-235, -137},
/* 240*/ {-237, -158},
/* 241*/ {-205, -136},
/* 242*/ {-141, -155},
/* 243*/ {-229, -228},
/* 244*/ {-168, -213},
/* 245*/ {-194, -224},
/* 246*/ {-226, -196},
/* 247*/ {-233, -183},
/* 248*/ {-167, -231},
/* 249*/ {-189, -174},
/* 250*/ {-166, -252},
/* 251*/ {-222, -198},
/* 252*/ {-179, -188},
/* 253*/ {-182, -223},
/* 254*/ {-186, -180},
/* 255*/ {-247, -245}
};
#endregion/[code]
 
I like what you all have to say this was a great topic. shows it can bring all programmers together. jeff I did something similar in baseweapon as your example

I went though and removed all the #region code to clean it up some, then went back in and Added #region code to say places that needed it.

Code:
        #region GetProperties
        public override void GetProperties(ObjectPropertyList list)
        {
            base.GetProperties(list);

also like

public enum spots that are very long.
 
I like what you all have to say this was a great topic. shows it can bring all programmers together. jeff I did something similar in baseweapon as your example

I went though and removed all the #region code to clean it up some, then went back in and Added #region code to say places that needed it.

Code:
        #region GetProperties
        public override void GetProperties(ObjectPropertyList list)
        {
            base.GetProperties(list);

also like

public enum spots that are very long.
See, #region GetProperties bugs me, why not just show the function? You effectively just made it more difficult to view the code. Code that probably needs changing since its a function. The entire point of opening a file with code in it, is to view the code ;)
 
VS also allows you to fold/unfold methods and classes in the same way you can with regions, via the little +/- box on the left, which is pretty neat.
 
yep also do you guys just hate it. when you open a #region and it looks like this

#region baby first steps
#region one step
#endregion
#region two setp
#endregion
#endregion

I have found so much code like that its like region inside region inside region. its endless LOL
 
Back