How to name a method that both performs a task and returns a boolean as a status?
- by Limbo Exile
If there is a method
bool DoStuff() {
try {
// doing stuff...
return true;
}
catch (Exception ex) {
return false;
}
}
should it rather be called IsStuffDone()?
Both names could be misinterpreted by the user:
If the name is DoStuff() why does it return a boolean?
If the name is IsStuffDone() it is not clear whether the method performs a task or only checks its result.
Is there a convention for this case? Or an alternative approach, as this one is considered flawed? For example in languages that have output parameters, like C#, a boolean status variable could be passed to the method as one and the method's return type would be void.