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.

lapin
  • 149
  • 1
  • 2

2 Answers2

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.
Hieu Le
  • 663
  • 4
  • 10
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

jk.
  • 10,216
  • 1
  • 33
  • 43
  • 1
    `is` is a verb too. – David Arno May 02 '19 at 08:52
  • oh yes, hmmm, show still seams wrong though but now i'm not sure why – jk. May 02 '19 at 09: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 02 '19 at 09: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 02 '19 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 02 '19 at 18:03
  • @jk true if it's a field that applies to the whole object being visible then yes, it would be redundant. Good point! – Adam B May 02 '19 at 18:20