Script Valley
Writing Clean Code: Naming, Functions & Structure
Why Naming MattersLesson 1.2

How to name functions clearly in any language

verb-noun function naming, single responsibility signals, predicate functions, factory vs action names, naming consistency across codebase

Function Names That Say Exactly What They Do

Function naming patterns

A function name is a contract. It promises what the function does. Break that contract — naming a function processData when it actually deletes records — and you create bugs that are nearly impossible to track.

Function names must start with a verb. No exceptions.

// Bad — what does this do?
function userData() { }
function emailCheck() { }

// Good — the name is a complete action
function getUserById(id) { }
function validateEmailFormat(email) { }

Verb categories to use:

Get/Fetch/Find — retrieves something without side effects. getUser, fetchOrderHistory, findByEmail.

Create/Build/Make — constructs and returns a new object. createSession, buildQueryString.

Save/Update/Delete — mutates state or storage. These are dangerous, so name them explicitly.

Is/Has/Can — returns a boolean. isExpired, hasAdminRole, canAccessDashboard.

// Predicate functions — always return boolean
function isTokenExpired(token) {
  return Date.now() > token.expiresAt;
}

// Action functions — always do something
function deleteExpiredSessions(userId) {
  // explicit: this mutates data
}

Consistency matters as much as accuracy. If you call it getUser in one module and fetchUser in another, readers will waste time wondering if there's a difference. Pick one verb per concept and stick to it across the entire codebase.

If you struggle to name a function, the function probably does too much. That is a design problem, not a naming problem.

Up next

Class and type naming conventions that make architecture clear

Sign in to track progress