SteelReed

Search

Search posts, questions…

OOP & DesignQuestion 31 / 42

Junior

What is clean code, and how should you name things, write functions and use comments?

Short answer

Clean code is code others can read and change safely, fast. Code is read far more than written, so the core habits are intention-revealing names, functions that do one thing, guard clauses and comments that say why.

Name reveals intent?Function does one thing?Guard clauses, no nestedifs?Command or query?Comment says why?

3 points to say:

  1. Clean code = easy to read and change safely, fast; maintenance is the main cost.
  2. Business names with units (timeoutMs), booleans read as questions; guard clauses keep the happy path flat.
  3. A function is a command or a query, not both; comments explain why, not what the code already says.

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.