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:
- 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] - 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): - 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): - Use consistent naming patterns - Maintain consistent naming styles for similar concepts:
# Inconsistent self.dataflow = data_flow # Consistent self.data_flow = data_flow - 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:
# ...