Naming confusion: 'isPackageOmitted' or 'packageIsOmitted'?

Viewed 28

As for property names 'isPackageOmited' and 'packageIsOmitted', which should I choose? Could some native speaker help me?

2 Answers

TLDR: don't put "is" into the middle of the name. It's hard to see quickly. Use isPackageOmitted.

The standard is to always prefix accessors, mutators and predicates with get, set and is.

So you would have methods like getPackage(), setPackage(), and isPackageOmitted().

Even though PackageIsOmitted reads closer to normal English, it is a really good idea to follow the convention of prefixing. It makes it incredibly easy to instantly know that this is a method that retrieves the boolean value.

Compare anIncrediblyLongAnacondaIsAbleToEatSheep with isAnIncrediblyLongAnacondaAbleToEatSheep. The second one instantly tells you that this is a boolean value, while in the first example you have to carefully look through the whole name to figure it out.

Now, if this is just the property, it would probably be best to drop the "is" altogether. Does it really provide any new information? I'd say, generally, it would be best to have a property called packageOmitted and a method isPackageOmitted() to retrieve the property value.

packageIsOmitted is better since "Package is omitted." is an assertion which is either True xor False, whereas "Is Package omitted?" is a question whose answer is either Yes xor No.

Related