Naming Conventions in Programming

Asitha Lakshan - Oct 11 - - Dev Community

As developers, there are many rules and best practices that we use in programming. One of the most important ones is the Naming conventions.

As programmers, we use names in lots of things, such as variables, functions, classes, methods, interfaces, types, filenames, and so on. There are several principles of naming conventions for a design system are listed below.

Clarity and obviousness

Names should be evident and unambiguous.

// bad
var value = 'James';

// bad
var val = 'James';

// good
var firstName = 'James';
Enter fullscreen mode Exit fullscreen mode

Consistency and organization

The same name should be used for the same object, and there should be consistency in how each component name is created.

Uniqueness

Do not use repeating names to avoid conflicts.

Prefixes and Suffixes

We can use prefixes or suffixes for elements of different types.
Example: We can use “btn” for buttons, “lbl” for labels, etc.

Use Case Types in Programming

Lets think we need to create a variable in our code. The name of the variable is more than just one word. It has to be a meaningful readable name.
Also, we cannot use spaces in the naming in programming. Therefore we cannot use variable names like those below.

first name = 'James'
last name = 'William'
user Id = 'af6b3dff-c023-40b1-a32f-163b6071f360'
Enter fullscreen mode Exit fullscreen mode

That is where Naming Conventions come from

There are sets of standards that are generally accepted by the developers for Naming conventions. Developers are using different case types to name different entities in code. These are the most popular case types among developers.

  • Camel Case
  • Snake Case
  • Kebab Case
  • Pascal Case

Camel Case

camelCase is a naming convention where the first word is always lowercase and every other word starts with a capital letter.

Examples:

firstName = 'James'
lastName = 'William'
userId = 'af6b3dff-c023-40b1-a32f-163b6071f360'
Enter fullscreen mode Exit fullscreen mode

Commonly used in: Java, JavaScript, and TypeScript for creating variable, function, and method names

Snake Case

snake_case is a naming convention where each word is in lowercase, and separated by underscores.

Examples:

first_name = 'James'
last_name = 'William'
user_id = 'af6b3dff-c023-40b1-a32f-163b6071f360'
CONSTATNT_VALUE = 'value'
Enter fullscreen mode Exit fullscreen mode

Commonly used in: Python, Ruby, C/C++ standard libraries, WordPress, database tables, and column names.

Kebab Case

kebab-case is a naming convention where each word is in lowercase, and separated by dashes.

Examples:

first-name = 'James'
last-name = 'William'
user-id = 'af6b3dff-c023-40b1-a32f-163b6071f360'
Enter fullscreen mode Exit fullscreen mode

Commonly used in: COBOL, Lisp, Perl 6, CSS class names, HTML ids, URLs.

Pascal Case
PascalCase is a naming convention where the first letter in every word is a capital letter and the rest is in lowercase.

Examples:

FirstName = 'James'
LastName = 'William'
UserId = 'af6b3dff-c023-40b1-a32f-163b6071f360'
Enter fullscreen mode Exit fullscreen mode

**Commonly used in: **Pascal, Modula, .NET, Java classes and enums, JavaScript classes, typescript types and interfaces.

. . .