Clean Code: Meaningful Names

One of the most fundamental principles of writing clean code is to use meaningful names for variables, functions, classes, and other elements of your code. By using descriptive names that clearly convey the purpose and functionality of your code components, you can make your codebase more readable, maintainable, and easier to understand.

Let's explore some examples in TypeScript to help you grasp the concept:

Variables

Use descriptive names for variables, so it's clear what they represent and how they are used.

// Bad
const a = 60 * 60 * 1000;

// Good
const millisecondsInAnHour = 60 * 60 * 1000;

Functions

Choose function names that accurately describe their behavior and, if possible, the return type.

// Bad
function x(y: number): number {
  return y * y;
}

// Good
function square(y: number): number {
  return y * y;
}