

The Problem With Code Folding - bdfh42
http://www.codinghorror.com/blog/archives/001147.html

======
raganwald
The title of this post got my hopes WAY up: Code folding? Applying
catamorphisms to code? Way cool topic!!!

But no, it was about how one specific language and one specific editor have
some hints that play well together to hide and show blocks of code. Which is
interesting even if you don't use that editor and that language, because it
looks like another form of abstracting away some details.

So for the people who use these Miscrosoft-specific tools, how is the argument
against code folding different from the argument against extracting code into
its own method? It seems to me that if I take a bunch of code and put it in
its own method or class, I can move it out of sight, hiding its ugliness and
exposition from view.

Is code folding substantially different?

~~~
baha_man
'...it looks like another form of abstracting away some details...'

I think this is the main reason why I don't like it - it's an extra and
inferior way of organising code. Automatically generated boilerplate code in
ASP.NET is now hidden using partial classes, for example, which I think is an
improvement.

------
bdfh42
Now I like regions.

They force programmers (by that I mean other people of course - my code is
perfect ;) to at least apply some order to the code. If I want to review (say)
the update method for a form I do not want to have to search through a
mishmash of private declarations, methods servicing form control events,
locally declared classes etc. etc.

OK - Mr Atwood might have a point for really simple classes but when the code
runs to a screen or two a little order helps a lot.

~~~
cstejerean
ordering code is not the same as hiding code. Perfectly fine to throw in some
comments to provide hints to readers as to what this section does, but
providing hints to the editor and having the editor automatically HIDE the
code seems wrong.

------
pchristensen
Generally I either agree with or at least don't disagree with Atwood, but I
completely disagree with his point on #region. It's a useful tool to manage
long files, you can still search within it, it implies some kind of grouping
of methods, etc. Even though the regions are collapsed by default, there's a
little '+' next to is that took me about 3 seconds to figure out _the very
first time I used Visual Studio_.

Also, the complaints about code helping only one editor are disingenuous
considering how little .Net coding is done outside of Visual Studio.

------
ScottWhigham
Jeff's posts a year ago were so much more interesting than the past year's
have been. _sigh_

------
silentbicycle
For something similar in Emacs:

    
    
      (defun toggle-fold ()
        "Toggle current buffer's folding." (interactive)
        (if selective-display
          (set-selective-display nil)
          (set-selective-display language-fold-column)))
    

where language-fold-column is the column that function bodies (or methods
within a class, etc.) are indented to by default. I set the language-fold-
column variable in my language-mode hook.

I find this helpful when skimming a module -- it limits it to function
descriptions (docstring-like comments preceding the methods, if any) and the
function type (in the OCaml sense); the function bodies are replaced with
"...". With well-named functions ( _long sigh_ ), this is often sufficient.
Granted, it's based solely on indentation, but it works pretty well for
several languages.

------
nirmal
I have only successfully used code folding when I write HTML. It's nice to
finish a section of the page and close it and forget about it. I never use it
for CSS though. I can never remember where that margin or padding is being
added from :)

I wish TextMate had proper folding logic for Python.

~~~
stcredzero
Notepad++ does code folding for Python rather well, but it's Windows only.

------
cdr
If you don't like #regions, you don't have to collapse them.

I like them personally because they _aren't_ comments - they're comments that
imply structure. It sets the high-level structure of the file apart.

