DEV Community

Discussion on: Code Folding in Android Studio

Collapse
 
shashiprasadkushwaha profile image
Shashi Prasad Kushwaha

//region ${ Your Comment }
....
....
//endregion

This way of "Code folding" is best way to fold as:

  • Can fold any method,
  • Fold statements within any method, or any loop (ex. if,else,for) in case you have many statements inside any method/loop.
  • In the top of classes we define many Variables and if you have very big class there will more-n-more variables added day-by-day as class grows, it will good if you group all the definition in one-or-more 'region'.
  • The best use I found as if you review code of many developers in various projects and there is too many things to remember with requirements. Then, its a good practice to "Group all related methods in One 'region/endregion' with a good description. Its really helpful for next developer/reviewer/lead/manager to change/modify the code where it helps as not to wander/lost in whole file and scroll here-n-there/top-to-bottom and lose something in between.
  • Well, many of us use method separator(in Android Studio) and defining a rule for everybody/team as to use, line gap/space to grouping the similar statements within code block(method/loop) is not helpful and tough to consider/follow, in that case, this 'region/endregion' rule comes very handy.

You can use this in Visual Studio for C# as well.

And, Thanks Nate : for gathering all these Tips/hacks at one place.