Language: Support for code regions

Created on 22 Mar 2019  路  7Comments  路  Source: dart-lang/language

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

All 7 comments

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.

I think this is solved with a plugin for the IDE

which plugin?

This features would be useful

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!

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.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dev-aentgs picture dev-aentgs  路  3Comments

leonsenft picture leonsenft  路  4Comments

stategen picture stategen  路  4Comments

har79 picture har79  路  5Comments

moneer-muntazah picture moneer-muntazah  路  3Comments