StyleChecker
ThoughtlessName
Summary
Avoid giving a name that is too facile or thoughtless to the identifiers of local variables and parameters.
Default severity
Warning
Description
Consider a good name for each local variable. The name of the identifiers must not be too easy as a typical sample code. This rule reports the following cases:
- The identifier of local variables and parameters must not be an acronym of
the type name if it is composed of two letters or more. For example, use
b
orbuilder
for the identifier whose type isStringBuilder
, rather thansb
. - Hungarian notation must not be used. For example, do not use
int iResult
. - The identifiers specified with the configuration file
StyleChecker.xml
must not be used.
You can specify identifiers which are not allowed to use,
with the configuration file StyleChecker.xml
.
For example, if you would like to make sure that flag
and flags
are not
used for identifiers, edit StyleChecker.xml
file as follows:
<?xml version="1.0" encoding="utf-8" ?>
<config xmlns="https://maroontress.com/StyleChecker/config.v1">
⋮
<ThoughtlessName>
<disallow id="flag"/>
<disallow id="flags"/>
</ThoughtlessName>
⋮
</config>
The ThoughtlessName
element can have disallow
elements
as its child elements,
and the id
attribute of the disallow
element specifies the identifier
that is not allowed to use.
Code fix
The code fix is not provided.
Example
Diagnostic
public void Method(Stream inputStream)
{
var sb = new StringBuilder();
var br = new BinaryReader(inputStream);
var iResult = "hello".IndexOf('e');
⋮
See also
-
General Naming Conventions [1]
Word Choice
- ✓ DO NOT use Hungarian notation.
Using Abbreviations and Acronyms
- X DO NOT use abbreviations or contractions as part of identifier names.
For example, use
GetWindow
rather thanGetWin
. - X DO NOT use any acronyms that are not widely accepted, and even if they are, only when necessary.