Avoid methods with name too long

Rule ND2010 Naming Conventions

Matches methods with names longer than 40 characters: less readable, and possibly a sign the method does too much. Very expressive names are good practice for unit tests though, so test methods and methods of test classes are not matched.

How to fix

Rename the method with a shorter name equally conveying its behavior, or split it into smaller methods.

CQLinq source

This rule is written in CQLinq, C# LINQ over the NDepend code model. It ships with every new NDepend project: you can read it, adapt it, or use it as a starting point for your own custom rules.

// <Name>Avoid methods with name too long</Name>
// <Id>ND2010:AvoidMethodsWithNameTooLong</Id>

warnif count > 0

from m in JustMyCode.Methods where  

 // Explicit Interface Implementation methods are 
 // discarded because their names are prefixed 
 // with the interface name.
 !m.IsExplicitInterfaceImpl &&
 !m.IsGeneratedByCompiler &&
 ((!m.IsSpecialName && m.SimpleName.Length > 50) ||
   // Property getter/setter are prefixed with "get_" "set_" of length 4.
  ( m.IsSpecialName && m.SimpleName.Length - 4 > 50)) &&

 !m.SimpleName.Contains("Test") &&
 !m.ParentType.SimpleName.Contains("Test") &&
 !m.ParentNamespace.Name.Contains("Test")

orderby m.SimpleName.Length descending

select new { 
   m, 
   m.SimpleName,
   NameLength = m.SimpleName.Length - (m.IsSpecialName ? 4 : 0),
   Debt = 3.ToMinutes().ToDebt(),
   Severity = Severity.Medium
}

//<Expl>
// The *{0}'s name* is excessively long, which tends to reduce code readability.
//</Expl>

//<Desc>
// Matches methods with names longer than 40 characters: less readable, and
// possibly a sign the method does too much. Very expressive names are good
// practice for unit tests though, so test methods and
// methods of test classes are not matched.
//</Desc>

//<HowToFix>
// Rename the method with a shorter name equally conveying its behavior, or
// split it into smaller methods.
//</HowToFix>

Naming Conventions: all 23 items