views:

70

answers:

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?

A: 

Here's a similar question:

http://stackoverflow.com/questions/1370840/naming-conventions-what-to-name-a-method-that-returns-a-boolean

http://stackoverflow.com/questions/1227998/naming-conventions-what-to-name-a-boolean-variable

Ben Gartner
Thanks! I had looked at them. They seem to cover the isAdj() and isNounAdj() cases I covered in my question.
A: 

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.

Skilldrick
Thanks, Skilldrick. Can you tell me more about the cases where `can` would be used? Something like `canAcceptNull`?
Well, anything where you're asking if it can, rather than if it is. So `canExplode` vs. `isExplodable`. `canBreak` vs. `isBreakable`.
Skilldrick