Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to name a method that may or not do something? [closed]

To be more specific, how to name a method that may or not present a view to the user?

For example:

void maybeShowView() {

    if (checkSomething()) {
        presentViewToUser();
    }
}

So maybeShowView is an awful name, also Im separating the maybe method from the presenting method for unit testing purposes, this way the maybe method can be unit tested properly.

In my team we have come up with names like

  • maybeDoSomething
  • presentThingIfAvailable

But this are really bad names

Any Ideas?

Thanks

note: I could create a boolean method shouldPresentView() but this would require me to check for it everytime I want to present my view, I dont want this.

like image 998
Hazneliel Avatar asked May 31 '16 18:05

Hazneliel


1 Answers

Your best bet would be to include both the condition and what you will do in the name of the method. so, if your view will be shown when checkSomething() is true, you would call it like so:

void presentViewIfSomething() {

    if (checkSomething()) {
        presentViewToUser();
    }
}

This will leave no doubt what the method actually does. The downside to this approach is, of course, that if you change the condition you'll also have to change the name of the method.

like image 156
Paul O. Avatar answered Oct 27 '22 06:10

Paul O.