The Problem With Code Folding


#1

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.


This is a companion discussion topic for the original blog entry at: http://www.codinghorror.com/blog/2008/07/the-problem-with-code-folding.html

#2

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 :slight_smile:


#3

@Non sequitur

Haha, Perfect


#4

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.


#5

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.


#6

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.

I saw this today:
’’’


#7

#region Comment

// Coding Standard: C# Philips Medical Systems - Software / SPI
// 4.2.5. Rec. 4@110: Use #region to group non-public members… 19

#endregion


#8

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#?


#9

region comment is very useful.

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.


#10

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.

http://www.rauchy.net/regionerate/
http://www.jetbrains.com/resharper/


#11

@Non sequitur

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)


#12

Are you seeking attention?


#13

This is a new language feature? hahahahahahahaha

// {{{ Rant

Vim has had code folding with markers like forever :slight_smile:

// }}}

/* vim: set foldmethod=marker: */


#14

I saw a badly named variable the other day - God variables suck.


#15

Another very good thought from codinghorror!


#16

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.


#17

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.


#18

I believe Eclipse, Geany, and Zend Studio offer automatic folding. With options on how to work it as well.


#19

I wish there was automatic blog-comments folding, so I didn’t need to scroll 50 screen to get to the form :wink:

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.


#20

Your project is now full of crappy code that you can’t see

I want to have this framed and put on the wall at work :slight_smile:

Daniel