Back to all reviewers

Meaningful identifier names

bridgecrewio/checkov
Based on 7 comments
Python

Choose descriptive and semantic identifiers that clearly convey purpose, role, and behavior. Avoid vague, generic names in favor of specific ones that enhance code readability and self-documentation.

Naming Conventions Python

Reviewer Prompt

Choose descriptive and semantic identifiers that clearly convey purpose, role, and behavior. Avoid vague, generic names in favor of specific ones that enhance code readability and self-documentation.

Key practices:

  1. Use descriptive names - Replace generic identifiers with specific ones that reveal intent:
    # Poor naming
    new_value = [*vertex.attributes[property], *value]
       
    # Better naming
    list_updated_value = [*vertex.attributes[property], *value]
    
  2. Function names should reflect behavior - Functions should have names that indicate what they do or return:
    # Misleading (returns boolean)
    def _prioritise_secrets(secret_records, secret_key, check_id):
           
    # Clear and accurate
    def _should_prioritise_secrets(secret_records, secret_key, check_id):
    
  3. Avoid name collisions - Use prefixes or qualifiers to distinguish similar components:
    # Ambiguous - multiple "Runner" classes in codebase
    class Runner(TerraformRunner):
           
    # Clear and specific
    class TerraformJsonRunner(TerraformRunner):
    
  4. Use consistent naming patterns - Maintain consistent naming styles for similar concepts:
    # Inconsistent
    self.dataflow = data_flow
       
    # Consistent
    self.data_flow = data_flow
    
  5. Disambiguate from standard library - When naming functions that might conflict with standard functions, use clarifying prefixes:
    # Potentially confusing with standard library
    def deepcopy(obj: _T) -> _T:
           
    # Clear it's a custom implementation
    def pickle_deepcopy(obj: _T) -> _T:
    

When iterating over collections, use descriptive variable names instead of generic ones:

# Vague
for each in resource_changes:
    # ...

# Descriptive
for changed_resource in resource_changes:
    # ...
7
Comments Analyzed
Python
Primary Language
Naming Conventions
Category

Source Discussions