4

I've seen here that it was a dividing topic to use "should" as a prefix for a boolean because it could mean that we're unsure.

Then how would you prefix a boolean such as "myButton.shouldShow"?

I feel indeed that it's a little bit weird so I was hoping to find another solution.

2 Answers 2

7

I will use:

  • myButton.canBeShown if I want to know whether the button can be shown or not.
  • myButton.isShown or myButton.isVisible to know whether the button is currently showing or not.
  • myButton.isAlwaysShown to know whether the button must be shown everytime or not.
3

you are using a verb to describe state (show) which I think is where the problem arises. if possible I'd change it to isVisible or similar

6
  • 1
    is is a verb too.
    – David Arno
    May 2, 2019 at 8:52
  • oh yes, hmmm, show still seams wrong though but now i'm not sure why
    – jk.
    May 2, 2019 at 9:01
  • I'm being a little unfair as "show" is just a verb, whereas "isVisible" is a verb and adjective. I know that a lot of folk like to use is and the like for booleans. I personally dislike them and would just go with the adjective, Visible.
    – David Arno
    May 2, 2019 at 9:22
  • I would go a step further and name it somethingIsVisible where something is replaced with the thing that is visible or not.
    – Adam B
    May 2, 2019 at 13:11
  • @AdamB usually that thing would be the object that isVisisble is a member of so that would be somewhat redundant
    – jk.
    May 2, 2019 at 18:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.