Best Practices for Naming in Programming

· algiegray's blog

Key takeaways:

  1. Avoid single-letter variable names and abbreviations for clearer code.
  2. Do not include types in variable names; rely on static typing for clarity.
  3. Use meaningful units in variable names and leverage language-specific types to abstract units.
  4. Avoid redundant naming patterns, such as prefixing interfaces with 'I' in C#.
  5. Refactor class hierarchies for clear naming, avoiding 'base' or 'abstract' in class names.
  6. Replace generic 'utils' or 'helper' classes with more descriptive module names or integrate functions into relevant classes.

# Introduction to Naming Conventions

# Avoid Single-Letter Variable Names

# Shun Abbreviations

# Do Not Include Types in Variable Names

# Use Units in Variable Names When Necessary

# Avoid Redundant Prefixes for Interfaces

# Refactor Class Hierarchies for Clearer Naming

# Eliminate 'Utils' and 'Helper' Classes

# Conclusion

By following these best practices, developers can ensure that their code communicates its intent clearly, making it easier for others (and themselves) to understand and modify in the future. Remember, the goal is to write code that is as clear as possible, reducing the cognitive load required to work with it.

Summary for: Youtube