Avoid Magic Numbers and Strings

Magic numbers and strings are hard-coded constants scattered throughout your code. Instead of using magic numbers or strings directly, define them as named constants with descriptive names. This makes your code more self-explanatory and easier to maintain.

Comments should explain why code is written

Focus on documenting the intent behind the code rather than reiterating what the code does. Be mindful of keeping comments up-to-date; outdated comments can be worse than no comments at all.

Keep Functions and Methods Small

Follow the Single Responsibility Principle (SRP) and keep your functions and methods small. Each function should ideally do one thing and do it well. Smaller functions are easier to understand, test, and maintain. If a function grows too large, consider refactoring it into smaller, more focused functions.

Use Meaningful Names

Choose descriptive names for variables, functions, classes, and other identifiers. Names should reflect the purpose and functionality of the entity they represent. Avoid single-letter variable names (unless they’re used as loop counters) and cryptic abbreviations.

Follow a Consistent Coding Style

Consistency in coding style makes it easier for everyone to understand the codebase. Whether you prefer tabs or spaces, curly braces on the same line or a new line, consistency is key. Adopt a style guide or use tools like Prettier or ESLint to enforce consistency automatically.