1.2.12 Naming Conventions

Names Communicate the Role of Code

C# identifiers name:

A good name helps a reader understand what the code represents.

Class Names Identify Types

Examples:

Plain text
Player
Team
Match

Class names commonly use PascalCase in C#.

The name should describe the kind of object.

Field Names Identify Stored Information

Examples:

Plain text
name
jerseyNumber
isAvailable
team

Use the naming convention required by the current course and StyleCop configuration.

Do not rename supplied identifiers simply because another convention appears online.

Names Should Be Specific Enough to Be Useful

Compare:

Plain text
x
data
thing

with:

Plain text
jerseyNumber
isAvailable
team

The second group communicates more meaning.

Preserve Traceability Across UML and Code

If UML shows:

Plain text
jerseyNumber : int

and C# declares:

C#
public int jerseyNumber;

the connection is easy to follow.

Unnecessary renaming weakens that traceability.

Avoid Encoding Future Design Ideas in Names

A beginner field name should describe the current concept.

Do not add words implying:

unless the current design actually contains that concept.

Names should describe what exists now.