This directory contains practical examples demonstrating proper naming conventions in Python.
Shows common naming mistakes and poor practices that should be avoided:
- Generic variable names (x, y, z)
- Single letters for important data
- Unclear function names
- Abbreviated names
- Non-descriptive booleans
Shows the same code refactored with proper naming conventions:
- Descriptive variable names
- Clear function names with action verbs
- Meaningful boolean names
- Well-named classes and methods
Real-world example of a user management system demonstrating:
- Class naming (User, UserManager)
- Method naming (create_user, authenticate_user, find_user_by_username)
- Boolean methods (is_valid_username, is_valid_email, is_valid_password)
- Constants (MAX_LOGIN_ATTEMPTS, SESSION_TIMEOUT_MINUTES)
- Descriptive variable names throughout
Real-world example of data processing with proper naming:
- Class naming (DataValidator, DataProcessor, FileHandler)
- Method naming (process_records, calculate_success_rate, filter_records_by_threshold)
- Clear parameter names
- Descriptive internal variables
-
Study the comparison: Compare
before_refactoring.pywithafter_refactoring.pyto see the impact of good naming. -
Run the examples: Execute each file to see how the code works:
python before_refactoring.py python after_refactoring.py python user_management.py python data_processing.py
-
Learn from patterns: Notice the patterns:
- Variables use
snake_case - Functions use action verbs
- Classes use
PascalCase - Constants use
UPPER_CASE - Boolean variables/functions start with
is_,has_,can_, etc.
- Variables use
-
Apply to your code: Use these patterns in your own Python projects.
For comprehensive guidelines, see the main NAMING_CONVENTIONS.md document.