This inconsistency is a combination of things:
Language designers are not required to adopt naming conventions from other languages when inventing a new programming language.
Naming conventions have developed and evolved over the years by many different people.
English grammar and meaning of the words being used in identifiers.
Points 1 and 2 are summed up as "because that's what people wanted to do." Point #3 is worth a little elaboration.
The context in which a word or phrased gets used helps determine its meaning. Consider the identifier empty used in the following lines of code:
if (box.empty) — the context of the code using empty tells you it is a boolean value since it is used in an if statement. The language construct of the if statement provides the context to understand that empty is a question rather than a command. The word "empty" is being used as an adjective describing the noun "box".
This next example uses the word "empty" as a verb, which changes the context of the conversation in the code:
if (box.itemsCount > 0) { box.empty(); } ^^^^^
Here, the word empty implies the box (which contains more than zero items) should have its contents removed. This appears to mutate the box object and would typically have the signature void empty() in many languages. The word "empty" implies an action — a verb.
Both uses are grammatically correct enough to be understood. It becomes personal preference whether you use empty or isEmpty in this case.
Other cases like ValueIsEmpty can be written as:
- IsValueEmpty
- EmptyValue (based on context again, like
if (foo.EmptyValue)).
Same thing for word_is_short. It can be written as is_short_word and it means the same thing. Pluralizing words gets a little trickier in English because "is" becomes "are" in many cases:
// The word 'boxes' is plural, implying more than one box, // so we use 'are' instead of 'is': if (boxes.areEmpty)
As a native English speaker, if (boxes.empty) feels awkward as a boolean, which implies a question, but for some reason if (box.empty) doesn't.
Other words like 'visible' are inherently adjectives which describe a noun. Furthermore, something is either visible or not, unless specified by a qualifier like "partially" (something is "partially visible"). Both visible and isVisible work in all the contexts in which I've seen them in programming. The addition of is does not provide additional context to the word visible. The word visible by itself is easy enough to understand.
In summary, there is inconsistency because humans are inconsistent. We never sat down and universally agreed upon these naming conventions. Things are further complicated by the meanings of identifiers and the contexts in which they are used. For these reasons you'll never find consensus on this.
Refer to a specific language for naming conventions. Failing that, refer to your team. Failing that, just make sure your code is understandable by having another person read it. Peer reviews of code are a great way to accomplish this.
NounIsAdjectiveform used, please just give me a link. Thanks in advance.isis reserved! So strictly speaking,isReserved()is a reserved identifier, as isislandorissue