Assigning Names to Variables, functions, Classes & more
A consistent naming convention improves code readability, maintainability, and collaboration across teams. The goal is to make your code self-explanatory without requiring additional comments.
🧯 Naming Casing Conventions
Element Type
Naming Style
Example
Variable / Property
camelCase
userEmail, totalAmount
Constant
UPPER_CASE
MAX_RETRY_COUNT
Function / Method
camelCase
getUserData(), validateForm()
Class / Constructor
PascalCase
User, OrderController
Private Variable (optional)
_camelCase
_isInitialized
File / Module
kebab-case or snake_case
user-service.js, order_helper.js
🌟 General Principles
1. Be Descriptive and Clear
Names should reveal intent and make code self-documenting.
2. Avoid Abbreviations
Unless the abbreviation is universally understood (url, id, db, api), spell out words completely.
3. Use Pronounceable Names
Names should be easy to pronounce aloud during code reviews and discussions.
4. Use Searchable Names
Single-letter names and numeric constants are hard to locate across a codebase.
🧱 Variables & Constants
Variables and constants serve as data containers, storing values, states, or objects.
✅ Guidelines
Use nouns or short descriptive phrases
Use camelCase for variables
Use UPPER_CASE for constants
Keep names clear, meaningful, and contextual
Be specific about what the variable contains
💡 Basic Examples
🔘 Boolean Variables
Prefix with is, has, can, should, was or similar verbs that indicate true/false states.
📦 Collections and Arrays
Use plural nouns to indicate multiple items.
🔒 Constants
Use UPPERCASE with underscores (SCREAMING_SNAKE_CASE).
⚙️ Functions & Methods
Functions perform actions or return computed values. Their names should describe what they do or return.
✅ Guidelines
Use verbs or verb phrases
Start with an action word
Use camelCase for naming
Be specific about actions and side effects
Be consistent with naming patterns
💡 Examples
📚 Common Function Prefixes
Prefix
Purpose
Example
get
Retrieve data
getUserName()
set
Assign or update data
setUserName()
is / has
Return boolean
isValid(), hasAccess()
can
Check ability/permission
canDelete()
should
Conditional check
shouldUpdate()
create
Create new instance
createUser()
update
Modify existing
updateProfile()
delete
Remove data
deleteUser()
remove
Remove from collection
removeItem()
calculate
Perform computation
calculateTotal()
compute
Complex calculation
computeDistance()
fetch
Get data remotely
fetchUserData()
save
Persist data
saveToDatabase()
load
Load data
loadConfiguration()
validate
Check validity
validateEmail()
verify
Confirm authenticity
verifyCredentials()
parse
Convert format
parseJSON()
format
Transform display
formatDate()
handle
Event handler
handleClick()
on
Event handler (alternate)
onSubmit()
init
Initialize
initializeApp()
reset
Reset to default
resetForm()
🎯 Special Function Types
Predicates (return boolean):
Getters and Setters:
Event Handlers:
Callback Functions:
🏛️ Classes
Classes represent entities or things (objects, models, components). They usually describe what something is, not what it does.
✅ Guidelines
Use PascalCase (capitalize each word)
Use singular nouns (e.g., User, not Users)
Avoid verbs — classes describe things, not actions
Keep names intuitive and domain-relevant
Represent entities or concepts
💡 Examples
🎨 Class Type Patterns
Entity Classes (Domain Models):
Service Classes:
Utility Classes:
Manager Classes:
Controller Classes:
🔷 Abstract Classes and Interfaces
Abstract Classes - Often prefixed with "Abstract" or "Base":
Interfaces - Describe capabilities, often use adjectives ending in "-able":
🚫 Anti-Patterns to Avoid
1. Redundant Names
2. Hungarian Notation (Type Prefixes)
3. Meaningless Names
4. Overly Long Names
5. Misleading Names
📚 Summary
"The best name is one that needs no comment to explain it."
Key Takeaways
✅ Use nouns for data, verbs for actions, and PascalCase for entities
✅ Keep naming consistent, descriptive, and intuitive
✅ Follow your language's conventions and community standards
✅ Choose clarity over brevity — readable code is maintainable code
✅ Code is read far more often than it is written — invest time in choosing good names
Remember
Good naming is a skill that improves with practice, code review, and collaboration. When in doubt, choose the name that would be clearest to someone reading your code for the first time.
Future you (and your teammates) will thank you for writing self-documenting code with clear, consistent names! 🎉