DEV Community

Chris Lee
Chris Lee

Posted on

TIL: Let your code speak for itself through naming

One of the most impactful habits I've adopted as a freelance developer is prioritizing descriptive naming over excessive commenting. While comments are useful for explaining why something is done, they often become outdated as the code evolves. If you have to write a paragraph of comments to explain what a function does, it's usually a sign that the function is doing too much or isn't named clearly enough.

Instead of using vague names like data or process(), try to be specific about the intent. For example, renaming calc() to calculateMonthlySubscriptionTotal() immediately tells another developer (or your future self) exactly what to expect without needing to read a single line of implementation. This reduces cognitive load and makes code reviews much faster.

Maintainable code is code that can be easily handed off to a client or another developer. By treating your identifiers as documentation, you create a codebase that is self-explanatory and resilient to change.

Top comments (0)