Skip to main content

Command Palette

Search for a command to run...

Variable Naming Conventions

Updated
2 min read

This article is inspired by the official Microsoft documentation: https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/naming-guidelines

It is advisable to read the original article for a more complete understanding of the subject.

It’s always better to use readable variable names even if they are longer than short names that doesn’t mean anything. As developers it’s our responsability to make our code as readable as possible.

Following the orientation found on Microsoft documentation, never use underscores or hyphens to separate words in an identifier. Whenever more than one word is needed to name a variable, two approaches are preferable:

PascalCasing and camelCasing.

PascalCasing is used to name all the identifiers execpt for parameters.

camelCasing is used to name all the parameters.

public static int Sum(int numA, int numB); → As you can see, numA and numB are parameters of the method Sum so we use camelCasing for naming them. Sum is a method so we use PascalCasing for naming it.

public class Person → Person is a class so we use PascalCasing;
{
public int Height {get; set;} → Height is a property or an attribute of Person so we use PascalCasing;
}

IMPORTANT: When using APIs, it is not possible to know whether the other side is using the same language as us or a different one. Not all the languages are case sensitive as .NET so firstName and firstname could be the same variable in another language causing errors. Don’t rely on case to differ one variable from another, always use different names.