Search code examples
javabooleancoding-stylenaming-conventions

If condition naming convention


I have a boolean function that checks if scandata keys are valid. I named it as :

areScandataKeysValid()

For naming conventions, should it be named as isScandataDataKeysValid() or like how I did above?. In Clean Code book, I only saw examples with is version. So, I'm confused which one makes sense? Grammatically, "are" thats for sure.


Solution

  • The isName() convention is part of the JavaBeans standard, and applies to boolean-valued properties.

    • If your API does not need to be JavaBeans compatible, you can ignore the convention.

    • If your method for checking the scan keys is not intended as a getter for a "property", the isName() convention does not apply.

    I share your preference for areScandataKeysValid over isScandataKeysValid, because of the grammatical dissonance. There are other alternatives to consider; e.g.

    • hasValidScandataKeys for a predicate, or
    • validateScandataKeys or checkScandataKeys for a method that (typically) throws an exception to indicate invalidity.

    I am not aware of any documented conventions (i.e. style guides) that favor any one of the above. (Nothing says that "good grammar" is essential.)

    Bottom line: your choice.