Ah, excellent question! You're asking about the semantic approach to naming, not just the style. Here's the recipe for choosing between action-based, behavior-based, or return-based names:
🎯 The Golden Rule: Name Based on Primary Purpose
1. Action/Command Functions → Name What It Does
When the function's main purpose is to perform an action or cause a side effect:
When the function's main purpose is to retrieve or compute a value:
cpp
int size() const; // Returns: the size
std::string fullName() const; // Returns: full name
double distanceToOrigin() const; // Returns: distance
User currentUser() const; // Returns: current user
3. Predicate Functions → Name the Question/Behavior
When the function returns a boolean, name it as a yes/no question:
cpp
bool isEmpty() const; // Is it empty?
bool hasChildren() const; // Does it have children?
bool canExecute() const; // Can it execute?
bool isValid() const; // Is it valid?
🔍 Special Cases & Patterns
Conversion Functions
Name what it becomes:
cpp
std::string toString() const; // Converts to string
int toInt() const; // Converts to int
Json toJson() const; // Converts to JSON
Factory Functions
Name what they create:
cpp
static Widget createDefaultWidget(); // Creates a widget
static Config fromFile(const Path& path); // Creates config from file
std::unique_ptr<Shape> makeCircle(); // Makes a circle
Processing Functions with Returns
When a function both acts AND returns, prioritize the more important aspect:
cpp
// If the processing is primary:
Result processAndValidate(Data& data); // Focus on action
// If the return is primary:
ValidationResult validate(const Data& data); // Focus on return
📋 Decision Tree
code
Does it primarily cause side effects?
├─ YES → Name the ACTION
│ save(), send(), update(), delete()
│
└─ NO → Does it return a boolean?
├─ YES → Name the QUESTION
│ is...(), has...(), can...()
│
└─ NO → Does it return a value?
├─ YES → Name the RETURN VALUE
│ size(), name(), nextItem()
│
└─ NO → It's probably poorly designed!