dennisdoomen / CSharpGuidelines

A set of coding guidelines for C# 9.0, design principles and layout rules for improving the overall quality of your code development.
https://www.csharpcodingguidelines.com
Other
745 stars 272 forks source link

AV2407: Regions #191

Closed bkoelman closed 5 years ago

bkoelman commented 5 years ago

Given the pushback at https://softwareengineering.stackexchange.com/questions/53086/are-regions-an-antipattern-or-code-smell/53114 and https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1124.md, should we keep recommending to use regions in some cases?

Feel free to close if you believe so, just checking. Current guidance:

Be reluctant with #region (AV2407) Regions can be helpful, but can also hide the main purpose of a class. Therefore, use #region only for:

  • Private fields and constants (preferably in a Private Definitions region).
  • Nested classes
  • Interface implementations (only if the interface is not the main purpose of that class)
cocowalla commented 5 years ago

I don't see the need for region - every IDE for several years has had code block collapse/expand capabilities. I absolutely loathe reading code with regions in it, as it's just extra clicks to see what is going on - little more than a nuisance masquerading as "good practice"! /rant

dennisdoomen commented 5 years ago

Yes, I've changed my mind over the years and agree with @cocowalla now.