domains / / expressjs/express
Clear intention in names
Choose names that clearly communicate intention and follow established conventions. This applies to variables, functions, methods, and architectural components.
Choose names that clearly communicate intention and follow established conventions. This applies to variables, functions, methods, and architectural components.
Key practices:
- Follow architectural naming patterns (e.g., Controller-Service-Repository)
// Instead of: function NotesUseCase(notesRepository) { ... } // Prefer: function NotesService(notesRepository) { ... } - Use explicit function names rather than anonymous expressions
// Instead of: var proto = module.exports = function(options) { ... } // Prefer: function router(options) { ... } module.exports = router; - Choose distinct names for properties and methods to prevent confusion
// Confusing - same name used for different purposes: app.router = function() { ... } // Method this.router = new Router(); // Property // Better - clearly distinguished names: app.createRouter = function() { ... } // Method this._router = new Router(); // Property - Use prefixes (like underscore) to indicate private members
// No visibility indication: this.cache = Object.create(null); // With visibility indication: this._cache = Object.create(null); - Avoid names that could be misinterpreted for other common patterns
// Potentially confusing: app.dispatch = function(res, event, args) { ... } // More descriptive of actual purpose: app.dispatchEvent = function(res, event, args) { ... } - Choose descriptive names over abbreviated ones
// Unclear abbreviation: res.addTmplVars(options); // More descriptive: res.addTemplateVariables(options);
Consistently following these naming conventions improves code readability, maintainability, and helps prevent confusion among team members.