language icon indicating copy to clipboard operation
language copied to clipboard

Support for code regions

Open Sam-bit opened this issue 7 years ago • 9 comments

Can we have code regions facility for dart just like #region in c# for structural code blocks purpose. And thus can be used in flutter also

Sam-bit avatar Mar 22 '19 19:03 Sam-bit

My feeling has long been that #region is a somewhat useful feature in C#, but also implies there are other problems in the code. If a class is so big it needs to be broken down into "chapters", it's probably just too big.

For C#, the argument was that much of that code was generated WinForms code, so it made sense to be able to hide it. But I think partial classes (which if I recall came later) were a cleaner solution because it let you move that stuff to a separate physical file. That makes it much easier to integrate with code generators and otherwise manage things more cleanly.

For Dart, in many cases you can use mixins to break up a giant class into smaller more manageable pieces. You can even, if you want, put those all into the same file, which then also plays nice with library privacy.

I think that would be a better approach than applying a band-aid like #region.

munificent avatar Mar 22 '19 21:03 munificent

I think this is solved with a plugin for the IDE

listepo avatar Mar 23 '19 02:03 listepo

which plugin?

ercankayaNet avatar Oct 15 '19 11:10 ercankayaNet

This features would be useful

arbaieffendi avatar Dec 16 '19 00:12 arbaieffendi

while i agree with @munificent i think that in the other hand we have a spread of too much files and in some cases is useless to create another class in another file just to introduce one or two methods that can be more easily implemented on the file you already have. In my case i have Auth and AuthProvider which basically are the same, they only differ that in Auth i have the 2 methods i use for new users registration. and in AuthProvider i have the login implementation. In my personal case the use of regions could be a nice feature to have!

ginuxone avatar Mar 04 '20 18:03 ginuxone

Here's another vote for code regions as a useful feature.

While I agree with @munificent regarding classes that grow too large, I don't know that code regions actually encourage that growth. Sometimes bad developers are bad no matter how hard you wish they were better :)

Also, in some cases you may not have total control over the organization of your class. For example, you may be implementing a particularly large interface from an external package. In these cases, code regions can at least help organize the clutter from that (sometimes poorly designed) interface.

techfan101 avatar Mar 24 '20 14:03 techfan101

This Feature will be very useful in managing parts for class, or parts of code written by different team members.

anasnaguib avatar Apr 18 '20 21:04 anasnaguib

I would also love this, although I think it really only needs to be part of the vscode extension, not specifically the sdk?

which plugin? https://marketplace.visualstudio.com/items?itemName=maptz.regionfolder

mika76 avatar Mar 08 '22 10:03 mika76

Yeah, it's definitely possible for an IDE to support regions just by recognizing comments that contain some special marker text. In that case, no language support is needed.

munificent avatar Mar 10 '22 00:03 munificent