I just noticed that collapsing and expanding code regions does not exist in XS. It did exist in MonoDevelop. Is this feature gone forever? I really liked it and do use it.
Sender's remorse. I went into XS' preferences and I see that it's called "code folding" and I am able to turn that back on. Never mind.
On a related note, at Evolve I overheard a "discussion" between one of the XS devs and another attendee about this feature being disabled by default. Apparently the dev wanted it gone completely, and this was the compromise. Of course, the conversation quickly turned into a philosophical discussion about coding practices.
There was some internal disagreement about this decision - we know that code folding important to many experienced users. We'll definitely be revisiting this in future.
We wanted a new & better design for folding. We tried out some things, but couldn't get the new design to the level where we wanted it to be. So we reverted it to the old one (I improved the design 'a bit') - but we choose to disable it as default for now
I'm sure we'll see folding enabled in a future version - with a better design. This feature gets requested 'too often'.
Ok, I get the discussion about if it should be defaulted. My question is: How do I fold a select section of code, so I can use +/- to show or hide it?
Go into Xamarin preferences and enable code folding. Then use #region/#endregion to mark a section of code.
Thank you Dave, you were very helpful with your short answer!
My two cents: Yes, your code shouldn't have regions because your classes should be short and not require regions. But what if you're working with oh, I don't know, anyone other than yourself and they have long classes? Please do not remove code folding and regions from Xamarin Studio. This is essential for working with poorly written classes.
We won't remove code folding & regions . But we may enable folding as default again in future versions.
Even in well-written classes they are still immensely useful as a visual organiser. Especially if you have well-documented code bloating the vertical-space on the screen; collapsing them gives back precious screen real estate to those who already know what each method/property/class does and why.
Completely agree with @Le-royStaines.6222 even if you have a very well written code, sometimes is better if you use code folding to organize classes and to avoid seeing code you already know what it does.
Tools - Options - Genaral - Enable Code folding (check=true)
As in most situation also this coin has two sides.
If you want to make your code very independent of surrounding code and make it easy to reuse, you should try to refactor it not only to new functions, classes etc but also files. In this case you wouldn't need regions (and code folding) since your code will stay short and readable.
On the other hand this can easily be forced to be done to an absurdum since you wont have to option to use regions(and code folding) but you still want your code to be readable.
My suggestion is that you write some kind of built in reviewer that tells you to reconsider your code structure when it doesn't follow common recommendations for nicely write code e.g. too long methods, too many arguments etc and keep all the options of regions and folding.
Code folding is immensely useful when working with switch statement and if statements. Folding away code that is not being used at the moment can be really helpful, and make the code much easier to understand at a glance.
Xamarin Team should take this feature more seriously. I have thousands of lines of code organized in regions to work with. Collapsing should be on by default and regions should be visible in the document outline as well.
Xamarin Studio version: 5.9.3
Xamarin preferences --> Text editor --> General --> Enable Code folding = tick.
XS->Tools->Text Editor->General-> Check the following items: [ ] Enable code folding, Fold # regions by default
I may misunderstand the option, but I would like to "Fold # regions by default" when I press Ctrl+M|Ctrl+O (VS key binding for toggle definitions). When I do this, however, it does not fold the regions, rather, it leaves them expanded.
And my two cents on the "philosophical discussion" aspect: I shouldn't think limiting the popular functionality would be the right way to approach enforcing a coding-style viewpoint. Leave that for a team's code analysis, code review, coding standards, etc.
TypingFast + IntellisenseAwesomeness + VerboseSelfDocumentingCode + NamingThingsIsHard == CodeFoldingIsGood(especiallyWith: namedArguments, shouldBeOn: byDefault).
(Ok. Enough, silliness.)
@WilliamRaiford In Xamarin Studio on a Mac, Go to Edit > Folding to see the shortcuts.
@DaveH Thank you for your reply! It's always good to see a fellow keyboard enthusiast
Xamarin Inc., as a wholly-owned Microsoft subsidiary acting as a separate legal entity, adheres to the Microsoft Privacy Statement: Privacy & cookies