Collapsing regions of code within a function

  • Thread starter Thread starter mpjones2
  • Start date Start date
M

mpjones2

I'm trying to organize some code I've written and was wondering if
anyone can provide any suggestions on an equivalent to #Region that
can be used within a function to collapse sections of code within the
visual studio editor. In essence I have a program where several
different calculations occur when a user clicks a button on the form.
Since some of these sections are rather lengthy, I'd like to better
organize them by being able to collapse sections individually. I like
using the #Region code to collapse sections, but it can't be used
within a function. I really appreciate any suggestions.

Thanks,
Matthew
 
I'm trying to organize some code I've written and was wondering if
anyone can provide any suggestions on an equivalent to #Region that
can be used within a function to collapse sections of code within the
visual studio editor. In essence I have a program where several
different calculations occur when a user clicks a button on the form.
Since some of these sections are rather lengthy, I'd like to better
organize them by being able to collapse sections individually. I like
using the #Region code to collapse sections, but it can't be used
within a function. I really appreciate any suggestions.

The #Region directive does not work within methods in VB.NEt (apparently
it does in C#)

I would suggest that if you feel the need to reorganise your method, then
perhaps you should carve it into several smaller ones.

This process is one of a number of similar concepts refered to as "refactoring".


Refactoring is the process of altering your code for better design/readability/speed
without (in the strictest interretation) changing the effect of said code.

You can look this term up online for a better definition.

The refactoring I suggest here is sometimes called "Extract Method"

There are a number of tools which can help to automate this process.

2 examples would be RefactorPro (www.Devexpress.com/Refactor) and Resharper
(www.Jetbrains.com)

I personally use RefactorPro and have found it to be very useful. I have
no particular opinion of resharper but those that use it say it is also very
good and I have no reason to doubt them. Often the choice between these 2
tools is one of style and taste and therefore very hard to justify.

If you would like further information please ask.

My apologies if anyone finds this reply too commercial, I did try to present
both sides but I'm obviously quite biased :)
 
Thanks for the reply. I imagined there was probably a better way to
organize my code and refactoring seems to be the way to go. Thanks
for the advice.
 
I'm trying to organize some code I've written and was wondering if
anyone can provide any suggestions on an equivalent to #Region that
can be used within a function to collapse sections of code within
the visual studio editor. In essence I have a program where several
different calculations occur when a user clicks a button on the
form. Since some of these sections are rather lengthy, I'd like to
better organize them by being able to collapse sections
individually. I like using the #Region code to collapse sections,
but it can't be used within a function. I really appreciate any
suggestions.

Sometimes adding obvious comments is sufficient, however not what you
are looking for.


Armin
 
Back
Top