Course contentsShow
← Computer Science
Lesson 191 of 2,8725. Functions and ModularityFree lesson

Function Naming Conventions

Learning best practices for naming functions to improve code readability and maintainability.

Function Naming Conventions

What you'll learn: How to choose clear, meaningful names for your functions so your code is easy to read and maintain.


Why Names Matter

Just like you wouldn't name your dog "Thing" or "Stuff," you shouldn't name your functions with vague labels. Good function names act like mini-documentation—they tell other programmers (and future-you) exactly what the function does without needing to read its entire definition.

Core Naming Guidelines

Use verbs or verb phrases because functions do something. Since functions perform actions, their names should reflect that:

  • calculateArea ✓
  • area ✗ (sounds like a variable)
  • printReport ✓
  • report ✗ (ambiguous)

Be descriptive but concise. Aim for clarity over brevity:

  • getUserAge ✓
  • get ✗ (too vague)
  • retrieveCurrentlyLoggedInUserAgeFromDatabase ✗ (too long)

Follow consistent casing conventions:

  • camelCase: calculateTotal, findMaxValue (common in many languages)
  • snake_case: calculate_total, find_max_value (common in Python)

Pick one style and stick with it throughout your program.

Boolean-returning functions should sound like yes/no questions:

  • isValid ✓
  • hasPermission ✓
  • canDelete ✓

Practical Example

Compare these two function names:

  • doStuff() — What stuff? Unclear.
  • convertCelsiusToFahrenheit() — Crystal clear purpose.

The second name tells you exactly what the function does before you even look at its code.

Key Takeaway: Name functions with clear, verb-based descriptions that reveal their purpose—good names make your code self-documenting and dramatically improve readability.