3 ms·
I think regions are super useful. Even within the context of a class, I create regions for various types of code, e.g., constructors, private fields, etc... I
by kenjackson 11y ago
I think regions are super useful. Even within the context of a class, I create regions for various types of code, e.g., constructors, private fields, etc...
I'm not sure how regions change how you create your class hierarchies and such. One of the first things I do when I inherit a project, is I add regions to it. I'm not changing the class hierarchies, but I am making it a lot easier to navigate within Visual Studio.
- Someone1234 11y agoI don't see how hiding large chunks of code behind a drop-down is making it "easier to navigate in Visual Studio." If anything it is now much harder. Plus you're now burying how long your class is and the individual methods within. So a class or method that would otherwise be inappropriately long now looks a reasonable length. If you feel like the code is so long that it needs regions, then refactor the code, don't hide the mess under the bed.
- walking 11y agoI can't speak for the gp, but they were talking about inheriting a project/legacy code. If I end up needing to go through legacy code, and there are a lot of gnarly, long methods/blocks, I'll usually add comments and regions to it as I go along. I'll use comments if I just want to note something, and a region if I want to note something about a region of code. It's my rough map. Being able to tell Visual Studio to arbitrarily collapse an area is handy for sketching it. The long term goal is to refactor, but it's handy as a way to quickly outline things.
- kenjackson 11y agoPoint me to some of your code and I bet it would benefit from well placed regions.
- dpark 11y agoUgh. Every time I inherit code that someone has peppered with regions, I delete then. It's a bunch of extra noise if you expand all regions, and if they're collapsed it's harder to see the overall structure of the code, and some functionality (specifically undo/redo, but others also) gets gimpy when collapsed regions are involved, making it hard to see what is changing. I find regions to be useful 1% of the time, simply pointless 10% of the time, and hiding crappy code the other 89% of the time. When I open up code and see a bunch of regions, I immediately assume that the file contains way too much unrelated functionality and that the code is poorly written. This assumption is very rarely wrong.
- jameshart 11y agoca82a6d - kenjackson - 10 files changed, 34 insertions: "Added some regions" 085bb3b - dpark - 10 files changed, 34 deletions: "Removed regions" a11bef0 - kenjackson - 10 files changed, 34 insertions: "Added some regions" 2432f8e - dpark - 10 files changed, 34 deletions: "Removed regions" cbe6306 - kenjackson - 10 files changed, 34 insertions: "Added some regions" e7e1bef - dpark - 10 files changed, 34 deletions: "Removed regions" ....
- sverrirs 11y agogold, pure gold :D
- kenjackson 11y agoIn fairness though that assumption is almost always true regardless.