Skip to content

(Proposal) Coding Guidelines allowances. #299

@AdamSpeight2008

Description

@AdamSpeight2008

The coding guidelines should be alter to allow the following styles. which aids the readability of the code.

  • Align on the : of named parameters rather than lefthand edge of parmeter name
public static ImmutableArray<Diagnostic> GetAllMethodBodyDiagnostics(CSharpCompilation compilation, CancellationToken cancellationToken) 
{ 
  DiagnosticBag diagnostics = DiagnosticBag.GetInstance(); 
  CompileMethodBodies( 
                compilation: compilation,  
           moduleBeingBuilt: null,  
          generateDebugInfo: false,  
       hasDeclarationErrors: false,  
                     filter: null,  
                 filterTree: null,  
       filterSpanWithinTree: null, 
                diagnostics: diagnostics,  
          cancellationToken: cancellationToken ); 
  DocumentationCommentCompiler.WriteDocumentationCommentXml(compilation, null, null, diagnostics, cancellationToken); 
  compilation.ReportUnusedImports(diagnostics, cancellationToken); 

  return diagnostics.ToReadOnlyAndFree(); 
} 

vs

public static ImmutableArray<Diagnostic> GetAllMethodBodyDiagnostics(CSharpCompilation compilation, CancellationToken cancellationToken) 
{ 
    DiagnosticBag diagnostics = DiagnosticBag.GetInstance(); 
    CompileMethodBodies( 
         compilation: compilation,  
         moduleBeingBuilt: null,  
         generateDebugInfo: false,  
         hasDeclarationErrors: false,  
         filter: null,  
         filterTree: null,  
         filterSpanWithinTree: null, 
         diagnostics: diagnostics,  
         cancellationToken: cancellationToken); 
    DocumentationCommentCompiler.WriteDocumentationCommentXml(compilation, null, null, diagnostics, cancellationToken); 
    compilation.ReportUnusedImports(diagnostics, cancellationToken); *
    return diagnostics.ToReadOnlyAndFree(); 
} 
  • Simple IF
    If the If statement is small and has no else, and the code block is small enough.
    The combined width is less than the 80 character width limit.
if( arg0 == null ) throw new ArgumentException( nameof( arg0 ) );
if( arg0 == null ) { throw new ArgumentException( nameof( arg0 ) ); };

vs

if( arg0 == null )
{
    throw new ArgumentException( nameof( arg0 ) );
}

Consider multiple guards statements you are approaching halve of the length of the screen, ever before you've reached the core of the method.

  • Simple case clause
select ( value )
{
 case 0: return "Zero";
 case 1: return "One";
 case 2: return "Two";
 // ...
 case 9: return "Nine";
 default:
   return "Foo";
}```
vs
```c#
select ( value )
{
 case 0:
   return "Zero";
 case 1: 
   return "One";
 case 2:
    return "Two";
 // ... 
 case 9:
    return "Nine";
 default:
   return "Foo";
}

15 LoC rather than 25 or 35 if you need to include the break

case 0: output = "Zero"; break; 
  • 2 space indentation
    Consider the case of pattern-matching, each scope gets indented, 5 levels of indentation and you're already used a quarter of the permitted code width.
  • Method Parameter align vertically
    If the method signature is getting "too" wide, then consider vertical alignment.
internal static MethodSymbol DefineScriptEntryPoint
  (    CSharpCompilation           compilation,
         PEModuleBuilder      moduleBeingBuilt,
              TypeSymbol            returnType,
                    bool  hasDeclarationErrors,
           DiagnosticBag  diagnostics
  ) 
{ 
internal static MethodSymbol DefineScriptEntryPoint(CSharpCompilation compilation, PEModuleBuilder moduleBeingBuilt, TypeSymbol returnType, bool hasDeclarationErrors, DiagnosticBag diagnostics) 
{

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions