The Name is the Documentation: 3 Rules for Naming Functions
In modern software development, we often strive to write code that requires no comments. When you remove comments, the function name becomes the only clue to what the code does. Therefore, naming is not just a stylistic choice; it is a structural necessity.
Based on the philosophy of clean code, a good function name must satisfy three core properties: Honesty, Completeness, and Domain Understanding.
1. The Name Must Be Honest
Rule: The name must describe the function's true intention, not just its mechanism. An honest name tells the caller exactly what to expect. A dishonest name hides behavior (side effects).
- Bad (Dishonest):
- Good (Honest):
2. The Name Must Be Complete
Rule: The name must capture everything the function does. If a function performs two distinct actions, the name must reflect both (or the function should be split). Avoiding long names is not an excuse for incomplete names.
- Bad (Incomplete):
- Good (Complete):
3. The Name Must Be Understandable (Domain Language)
Rule: Use words from the business domain, not computer science jargon. This concept (often called Ubiquitous Language in Domain-Driven Design) ensures that developers and business experts speak the same language. Avoid technical terms like "List", "Array", or "Flag" if a business term exists.
- Bad (Technical Jargon):
- Good (Domain Language):