2

Can someone point me to a guide for naming methods that return boolean or indicate a boolean state? I'm talking about things I've named like recordsExist(), issetVariable(), questionPrompted(), commentAsked().

Thinking this over, I think that two basic problems I'm looking at are 1: Has a user-interface event happened? and 2: do[es] data exist? Another case, whether or not an adjective is true, isAdj() or isNounAdj convention works -- isValid(), isSent(), isNull(), isEmailSent(), areRecordsUpdated(), etc.

I'm sure other people have thought more thoroughly about this problem, and come up with more robust solutions than I have. In what other classes of scenarios do we return boolean, and what naming conventions do we use for them?

user151841
  • 17,377
  • 29
  • 109
  • 171

1 Answers1

1

Unfortunately, unlike Ruby and Scheme, for example, you can't use a question mark in an identifier in PHP. Otherwise you'd be sorted:

null?()

Otherwise, the naming conventions in the other question is and can both seem reasonable.

Community
  • 1
  • 1
Skilldrick
  • 69,215
  • 34
  • 177
  • 229
  • Thanks, Skilldrick. Can you tell me more about the cases where `can` would be used? Something like `canAcceptNull`? – user151841 Jan 14 '10 at 18:33
  • Well, anything where you're asking if it can, rather than if it is. So `canExplode` vs. `isExplodable`. `canBreak` vs. `isBreakable`. – Skilldrick Jan 14 '10 at 21:16