Naming & Function Design

Names are the API you present to every future reader. Units, roles, side effects — and function design judged by responsibility rather than line count.

Naming

A name is the interface every future reader uses instead of the body. It has to carry domain meaning, role, units and whether calling it changes anything.

Q · What does a name have to carry so that a reader can use the thing correctly without reading its implementation?
Units in Names and Types

A bare number carries no unit, so the unit lives in someone's head. Three rungs — comment, suffix, type — with escalating cost and escalating safety.

Q · When is a unit a comment, when does it belong in the name, and when does it deserve its own type?
Boolean Parameters

`sendEmail(user, true, false)` is unreadable at the call site, and the call site is where every future reader meets it. The fix is a type, not a comment.

Q · What is actually wrong with a boolean parameter, and what should replace it?
Function Design

A function is judged by what it needs, what it returns, what it changes, how many reasons it has to change, and whether its name is true. Length is not on the list.

Q · What makes a function well designed, if not how long it is?
Long Functions

Long is not automatically bad. Ask whether it mixes responsibilities, whether the control flow can be followed, and whether it hides concepts that deserve names.

Q · This function is three hundred lines. Is that a problem, and how would I know?
Naming and Domain Language

When code uses the words the business uses, a reader can apply domain knowledge instead of tracing execution. That is the difference between reading and deducing.

Q · What does a reader gain when the code speaks the same language as the people who asked for it?