domains / / servo/servo
Use semantically accurate names
Variable, method, and type names should accurately reflect their actual purpose, content, and behavior. Avoid generic or misleading names that don't match the underlying functionality.
Variable, method, and type names should accurately reflect their actual purpose, content, and behavior. Avoid generic or misleading names that don’t match the underlying functionality.
Key principles:
- Use plural names for collections:
visible_input_methodsnotvisible_input_methodfor a Vec - Match names to actual functionality:
closed_any_websocketnotcanceled_any_fetchwhen closing websockets - Avoid generic terms: use specific descriptive names instead of “Generic”, “this”, “that”
- Reflect current state:
hit_test_resultnotcached_hit_test_resultwhen it’s not always cached - Use precise terminology:
areanotsizewhen measuring area specifically
Example:
// Bad - misleading name
let cached_hit_test_result = match event.event { ... }
// Good - accurate name
let hit_test_result = match event.event { ... }
// Bad - singular for collection
visible_input_method: Vec<EmbedderControlId>,
// Good - plural for collection
visible_input_methods: Vec<EmbedderControlId>,
Names should immediately communicate what the code actually does, not what it might do or what it was originally intended to do.