Function and Method Naming
You'll learn how to name functions so their purpose is instantly clear from a single glance.
When you name a function or method, you're writing a mini-contract that tells readers what action this code performs. Unlike variables (which hold data), functions do things—so their names should be verb phrases that describe those actions clearly.
Use Verb Phrases for Actions
Start function names with verbs that match what they accomplish:
calculateTotalPrice()— computes and returns a pricesendEmail()— performs the action of sendingisUserLoggedIn()— checks a condition (returns boolean)getUserProfile()— retrieves data
Avoid vague verbs like process(), handle(), or manage(). These tell the reader nothing about what actually happens. Compare processData() (what does it do?) with validateUserInput() (crystal clear).
Match the Level of Abstraction
Your function name should operate at the same level of detail as its implementation. If saveUserToDatabase() also sends a welcome email and logs analytics, the name is lying—it's doing more than saving. Either rename it to registerNewUser() or extract those extra responsibilities into separate functions.
Think of it like a restaurant menu: if you order "Grilled Chicken" and receive a full three-course meal, you'd be confused. The name sets expectations, and the implementation must honor them.
Boolean Functions
For functions returning true/false, use question formats: isValid(), hasPermission(), canDelete(). These read naturally in conditionals: if (canDelete()) { ... }.
Key Takeaway: Name functions with clear verb phrases that describe exactly what they do at the appropriate level of abstraction—no more, no less.