zeocrash
zeocrash

Reputation: 665

"Folding" long sections of code in Visual Studio 2008

I have lengthy functions in VB.NET (VS2008) and I'd like to shrink them down. I know about the #region directives, but they don't work inside functions.

I was wondering if anyone knew of any plugins for visual studio 2008 that would allow me to fold if statements, loops and try catch statements. I've found a couple of plugins for Visual Studio 2005 but none for Visual Studio 2008.

Upvotes: 1

Views: 2430

Answers (4)

George Stocker
George Stocker

Reputation: 57877

You may want to read Martin Fowler's book called Refactoring: Improving the Design of Existing Code, as well as Code Complete: 2nd Edition.

refactoring book http://ecx.images-amazon.com/images/I/21ZceZ5jBTL._SL160_PIsitb-sticker-arrow-dp,TopRight,12,-18_SH30_OU01_AA115_.jpgcode complete book

If you're having functions and subroutines that long, it means there are larger complexity forces at work that need refactoring.

Update:

I just finished the book Clean Code by "Uncle" Bob Martin, and I have to say that it belongs right next to the other two in the 'Must Read' category.

Clean Code

Upvotes: 11

zeocrash
zeocrash

Reputation: 665

Ok so i finally found a tool to fold code inside subs and functions. it's not ideal as you have to specify the regions to be folded but it joes the job. the piece of software is called smartoutline. once you get past the broken installer.

http://submain.com/products/smartoutline.aspx

the installer has some issues with admin privileges, so to install it you need to create a shortcut to windows installer specifying the msi as a parameter and then run it as administrator

Upvotes: 1

Mitch Wheat
Mitch Wheat

Reputation: 300549

For many, regions are a subjective thing.

I actively dislike anything that hides meaning. If you find you are "writing lengthy functions" try to refactor functionality into separate objects and methods. In the long run, it makes code easier to understand and to maintain.

Hiding code in regions is a bad idea, IMO.

Upvotes: 2

Joel Martinez
Joel Martinez

Reputation: 47749

"i'm writing some lengthy functions in VB.net 2008" == Code Smell

Don't treat the symptom, fix the cause and componentize your methods.

Upvotes: 3

Related Questions