Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you feel about code folding? [closed]

For those of you in the Visual Studio environment, how do you feel about wrapping any of your code in #regions? (or if any other IDE has something similar...)

like image 800
Bryan Denny Avatar asked Aug 08 '08 13:08

Bryan Denny


People also ask

How do you use code folding?

Code Folding collapses or "folds" the display of a block of code. To enable code folding, go to the Folding Preferences page, accessible from Window | Preferences | PHP | Editor | Code Folding . If Code Folding is enabled, minus signs will appear in the Annotation Bar next to code blocks which can be folded.

How do you fold in VS code?

Fold (Ctrl+Shift+[) folds the innermost uncollapsed region at the cursor. Unfold (Ctrl+Shift+]) unfolds the collapsed region at the cursor. Toggle Fold (Ctrl+K Ctrl+L) folds or unfolds the region at the cursor.

What is code folding IntelliJ?

IntelliJ IDEA folds or unfolds the current code fragment, for example, a single method. To collapse or expand all code fragments, press Ctrl+Shift+NumPad - / Ctrl+Shift+NumPad + .

How do you collapse codes in PyCharm?

Expand or collapse code elements To collapse or expand all code fragments, press Ctrl+Shift+NumPad - / Ctrl+Shift+NumPad + . PyCharm collapses or expands all fragments within the selection, or, if nothing is selected, all fragments in the current file, for example, all methods in a file.


3 Answers

9 out of 10 times, code folding means that you have failed to use the SoC principle for what its worth.
I more or less feel the same thing about partial classes. If you have a piece of code you think is too big you need to chop it up in manageable (and reusable) parts, not hide or split it up.
It will bite you the next time someone needs to change it, and cannot see the logic hidden in a 250 line monster of a method.

Whenever you can, pull some code out of the main class, and into a helper or factory class.

foreach (var item in Items)
{
    //.. 100 lines of validation and data logic..
}

is not as readable as

foreach (var item in Items)
{
    if (ValidatorClass.Validate(item))
        RepositoryClass.Update(item);
}



My $0.02 anyways.

like image 152
Lars Mæhlum Avatar answered Oct 25 '22 10:10

Lars Mæhlum


This was talked about on Coding Horror.

My personal belief is that is that they are useful, but like anything in excess can be too much.

I use it to order my code blocks into:
Enumerations
Declarations
Constructors
Methods
Event Handlers
Properties

like image 37
Pat Avatar answered Oct 25 '22 11:10

Pat


Sometimes you might find yourself working on a team where #regions are encouraged or required. If you're like me and you can't stand messing around with folded code you can turn off outlining for C#:

  1. Options -> Text Editor -> C# -> Advanced Tab
  2. Uncheck "Enter outlining mode when files open"
like image 43
Joseph Daigle Avatar answered Oct 25 '22 12:10

Joseph Daigle