Reputation: 665
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
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_.jpg
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.
Upvotes: 11
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
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
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