How to name a method that both performs a task and returns a boolean as a status?

Posted by Limbo Exile on Programmers See other posts from Programmers or by Limbo Exile
Published on 2014-06-11T09:41:15Z Indexed on 2014/06/11 15:40 UTC
Read the original article Hit count: 241

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.

© Programmers or respective owner

Related posts about naming

Related posts about methods