When you join a team, it's important to bend your preferences a little to accommodate the generally accepted coding practices of that team. Not everyone has to agree on every miniscule detail of the code, of course, but it's a good idea to dicuss it with your team and decide on overall approaches and philosophy beforehand. It promotes team harmony, and more than that, it's just common courtesy. As they say, when in Rome, do as the Romans do.
Finally someone who hates this useless #region crap. I have the same opinion - it drives me crazy when Iām looking at someoneās code and canāt see a thing. Linus Torvalds once wrote: if you need more than 3 levels of indentation, youāre screwed anyway. If you need to use #refion - see above
Like any new tool or technique, there is bound to be overuse and abuse until a consensus is attained about what constitutes a ābest practiceā. This discussion is part of the process of that consensus.
Personally, I admit to āhidingā my exception handling within regions. This allows the flow of the program to read unimpeded by exceptional occurrences.
I donāt have quite the problem with code folding you do ā I think that like most things in āprogrammingā it can be used sparingly and make things easier for someone else to follow/read, or can be way overused and make things more of a PITA (like the way I feel about you and your 'varāificationā¦ ;-).
In the end I find myself using less #regions and more bricks/patterns of whitespace (lines) between logical chunks of code.
When I first heard of XMLDoc I thought it could be kind of cool and helpful, but the actual usage of it really pisses me off. It creates unnecessary junk - which to me says I am a really bad programmer - good programmers donāt create unnecessary junk.
Whenever I come across someone whom is extremely opinionated about coding style and intent on telling everyone else how they should indent or how they should name their variables, it usually is to compensate for the fact that they canāt read code to save their lives.
Being able to sit down and read someone elseās code is a skill that takes time to develop. Unfortunately, people try to mask the fact they cannot with such annoying antics.
Wait until an engineer throws some FORTRAN 77 at you. Any non-modern Fortran code is guaranteed to look strange to a modern programmer. What is the coding prima donna going to do then? Tell them to redo it all in Java or F#?
oh perfectly written is a myth. Unless you write the whole thing your self, or you spend couple of years in the hiring process.
unfortunately, programmers, developers, team leads, who ever, write crap and at one point someone else have to foot the bill and maintain this crap. Region makes the process less painful.
I have to echo Darren and Mark on this - Regionerate + ReSharper = useful regions. I tend to leave them expanded all the time and just use them for code organization, not folding.
I know the purpose of your post is to make light of the article. However you are close to showing why Regions suk.
In the book analogy one thing is clear, you did not reorganize chapters the way that some bad programmers rearrange classes within regions.
Your comment is facetious when merely discussing books and chapters.
However if you then reorganized your chapters by Nouns or some other arbitrary way. Youāre comment would no longer be humorous, instead it explains why regions suk.
Imagine reading Harry Potter in some arbitrary order of chapters, first all indoor scenes then all outdoor scenesā¦(public/private)
Folding also adds another thing that has to be maintained. We used it in a few areas in Paint.NET at the beginning, and over time it just fell apart. I find that the automatic - and + in the margin in Visual Studio gives me enough control and granularity for letting me hide code when I need to.
For those that donāt like regions (or automatic outlining in general), VS has a preference to turn it off.
Tools Options Text Editor C# Advanced Outlining
Simply uncheck the Enter outlining mode when files open box, and this discussion is over.
I personally love regions, not for grouping like members (e.g. public properties, private methods), but for grouping like functionality in a class. Makes finding the part of the code you need to work on much easier.
I wish there was automatic blog-comments folding, so I didnāt need to scroll 50 screen to get to the form
Regarding actual folding, I believe it is a semi-smell that too much is going on in the same file. When you need to start folding, maybe itās time to refactor and reorganize your actual code.