|
I liked that term when I first heard it as opposite to Spaghetti code.
And there also was Lasagna as description for strictly layered code. Hmm, for application logic and data access you best use both Ravioli code which at the same time is Lasagna code. This is getting confusing and making me hungry
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
|
|
|
|
|
Ravioli with Rock Lobster sauce?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I usually write fusilli[^] code - it's really screwed up! 
|
|
|
|
|
Thanks for the new wrinkle on this subject.
Steve Wellens
|
|
|
|
|
+5
I make liberal use of regions but in such a way as to make navigation within the code easier for me to look at later. The usual things like methods, properties etc but in some cases, my comments are quite large and I enclose them in separate region tags. Some classes and methods I write do pretty complicated stuff which cannot be explained in single line comments.
SG
Aham Brahmasmi!
|
|
|
|
|
if you need to fold, maybe you have too much stuff in that one file.
|
|
|
|
|
Nobody said anything about needing to fold. I just think it makes it easier to code. Like comments, which are not strictly needed, but make coding easier.
Somebody in an online forum wrote: INTJs never really joke. They make a point. The joke is just a gift wrapper.
|
|
|
|
|
+1 for us dinosaurs
"mostly watching the human race is like watching dogs watch tv ... they see the pictures move but the meaning escapes them"
|
|
|
|
|
AspDotNetDev wrote: Folding is used to sweep code under the rung
I hope he means rug, I'd hate to have to carry a ladder to work.
I'm a boring class per file kind of guy but I work on a pretty big c++ code base so the granularity of header files and their use can have a big impact on build times.
I thought the regions were pretty cool in c#, what I disliked was the partial keyword and classes spread across multiple files.
|
|
|
|
|
If the darn paste functionality wasn't so munged up, I wouldn't have made that mistake.
And uses for the partial keyword by a developer seem rare, excluding their main use (splitting out code for the designer file).
Somebody in an online forum wrote: INTJs never really joke. They make a point. The joke is just a gift wrapper.
|
|
|
|
|
_Josh_ wrote: the partial keyword
I'm rather partial to it myself. I can write a Data Access Layer with separate files for each table. They give us back what C++ already had.
On the other hand, I don't agree with needing a keyword, all classes should be partial automatically.
|
|
|
|
|
Like any other tool, regions can be misused. The example Jeff cites is just such a misuse. I would guess it resulted from a source code template imposed by the local programming style. You've probably seen this before: lots of block comments (and regions in this case) with "fill-in-the-blank" spots, most of which are left blank.
When used properly regions help in the middle ground, when a class is large enough that some meta-organization beyond the methods themselves is useful. I tend to organize regions conceptually: initialization/termination, fundamental properties, public operations, internals.
If you have regions wrapping groups of regions (I've seen this on occasion), then that's an indication some serious refactoring is in order.
Software Zen: delete this;
|
|
|
|
|
I like regions, but seldom use them. I normally use them to help me arrange existing code to better understand it.
|
|
|
|
|
+5 here too.
when playing w/ C# in visual studio express and saw folding (about 5 years ago) i had to get a text editor w/ folding (settled on JEdit). The IBM Mainframe ISPF editor has an 'exclude line' feature for hiding what is currently noise, but lines must be hidden manually. So with Jedit set as 'fold per indent' all my todo lists look like Python scripts.
|
|
|
|
|
Having had to work on a codebase written by others using regions extensively, I can say with some certainty that they make it a pain in the arse to navigate through the code and find out what is happening. And if your file is long enough that you think you need them, there's probably some refactoring to be done – it's very easy to use regions to 'tidy up' your code and find that you just keep adding things because you never get the 'oh my I'm doing a lot of scrolling, time to refactor' reaction.
Being able to roll up methods and classes is nice (though I never do that either, I use the method selector or page up/down to navigate files), but I find that regions just hide things,
|
|
|
|
|
BobJanova wrote: there's probably some refactoring to be done
Really? Just keep in mind that there are classes which do a little more than pass around data from and to the database. Not everything is a web application. It's not really fair to suggest that somebody is probably sloppy just because he needs larger classes and needs to organize them a bit more.
BobJanova wrote: but I find that regions just hide things,
That's the idea. If you have dozens of members, properties, methods, events or whatever it's nice to have a way to make those things which you don't care about at the moment disappear. For example, in my control base class I mentioned before, I may want to see everything what has to do with rendering, and not the stuff for processing input.
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
|
|
|
|
|
Regions are a vital part of readable code...
I usually split them up into control events:
#Region [control name] Events ..
Then the allmighty allimportant underused keyboard shortcut: Ctrl+M Ctrl+O.
|
|
|
|
|
..And BTW...
I saw some screenshots of the next Visual Studio, and it seems that you can see all your functions, routines, regions(?), on the solution explorer. Don't know if any current versions have this. I'm still on VS2008 sp1... Can't wait to get an upgrade.
|
|
|
|
|
I love code folding. We have a complicated Web application with hundreds of pages that we are moving to a common .NET architecture, with base classes for different screen types (Criteria, List or Detail) . My developers all put the code in the same sections, so it makes it very helpful for debugging. The larger the development team the more benefit realized from standardization.
|
|
|
|
|
Regions suck, pure and simple. Except for a few rare exceptions, if I see a lot of regions, it's usually because the class contains too much and needs to be refactored. If your code is well organized, it's easy to find exactly what you're looking for in 2-3 seconds or less. Put all your private field declarations, your internals, your public methods, public properties and constructors in the same order, and you will be able to find everything really quickly.
This is my preferred order:
Constructors
Public properties
Public methods
Protected properties & methods
Internal properties & methods
Private methods
Private fields
Having ReSharper helps a lot too, if you're a .NET developer. Ctrl-Alt-F shows you all your declarations in a nice window with the ability to drag things around.
Why create housekeeping tasks with keeping regions neat and tidy? They don't add anything you can't get by just keeping your classes to a reasonable size and being a little bit organized.
|
|
|
|
|
+5 for:
-Put class members in the same order in every file (although my order is different).
-Ctrl-Alt-F. I was unaware of the File Structure window in R# - this pretty much rocks my day.
|
|
|
|
|
My biggest complaint of code folding, whether from regions or class level, is that I can't fold from the bottom. In order to fold, you have to go to the top of a region and click the button. When will Visual Studio allow me to fold from the end of a region or class? This would save very tedious scrolling!!!
Hogan
|
|
|
|
|
I'm ok with Regions when they're used to group functions, methods or properties.
Regions within a method or function should be disallowed. Far too many programmers use regions to denote what should be a separate function.
If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun
|
|
|
|
|
AspDotNetDev wrote: What's your take on code folding, especially with respect to regions?
Don't like regions, everybody uses them in a different way and the different groupings that some teams want are merely timewasters.
I first came across the concept in Amos BASIC, and I loved it; it was a huge improvement, but it didn't work with regions. Amos collapsed them at the method-level, and if you collapsed them all, you'd be looking at the signatures - comparable to Delphi's interface part of the unit.
It worked very well, and I haven't come across a decent code-folding feature since then.
Bastard Programmer from Hell
|
|
|
|
|
I use regions extensively around every method/property. Keeps my classes neat and easy to glance through. (see example below)
#region public string Name
public string Name {
get {return _name;}
set {_name=value;}
}
private string _name="default";
#endregion
I have written macros that creates/updates the regions and for folding/unfolding the current or all regions in a class. Just press Ctrl+d when cursor is in/on a method/property and you have the correct region and documentation for the member as well...
See article about macros here[^] or download the latest version[^].
|
|
|
|