1

This is my first question on this website. I'm a developer and my native language is Persian.

Many times I see a variable name such as isShown, hasChild, etc. in open source projects. Are these names grammatically correct for English or are they just some informal usages? If they are grammatical, then what is the English grammar rule and what is the boundary between formal and informal usages?

I think we should use isItShown instead of isShown and hasItChild instead of hasChild.

closed as off-topic by Chenmunka, Nigel J, Hellion, Skooba, Mari-Lou A Nov 9 '17 at 22:21

  • This question does not appear to be about English language and usage within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 5
    I'm voting to close this question as off-topic because it concerns names of software variables. – Chenmunka Nov 6 '17 at 15:44
  • 2
    I actually see a definitive link to English language and usage, because even though programming languages are not English, naming conventions do depend on the natural language that is used in development, and coding standards often implicitly refer to that language, e.g. English. Many bugs, misunderstandings and general instances of miscommunication happen because of grammatically or semantically poor implementation of English in naming parts of code. – oerkelens Nov 6 '17 at 15:55
  • @Chenmunka But the readability of the code is in the Human language scope. we are coding by language like english. – kokabi Nov 6 '17 at 17:21
  • 1
    Variable names are more closely akin to headlinese than they are to standard English, since some brevity is generally desirable. – Davo Nov 7 '17 at 22:13
3

Apart from the correct point that programming languages do not have to follow English grammar, I would like to add that it is generally encouraged to write readable code, and thus, do follow the rules of English.

And your proposed names do not do that - let me expand on that.

A name like IsShown is typically a property of an object, which would appear in usage like this:

if (SomeObject.IsShown)
    SomeObject.Hide();

For somebody who doesn't know the application, but who can read C#, this code is clear as day: "If SomeObject is shown, hide SomeObject."

If the property would be called IsItShown, it would allude to a sentence like *"If SomeObject is it shown, ...", which is incorrect.

In general, a method or property always refers to the class it is a property or method of, and referring back to that class as "it" is superfluous at best and confusing at worst.

In the case of HasChild, HasItChild is equally confusing. I am not asking class B if class A has a child (in which case the name would make more sense). I am asking class A something about itself so I do not have to repeat who I am asking. You could make a point to make a distinction between HasChild and HasChildren if there are really two distinct use cases for it.

2

The names of variables in a computer program are not obligated to follow the rules of English grammar. The compiler or parser treats names as strings of symbols, not as constructs to be accepted or ignored dependent on the grammar of a natural language.

The names in your examples appear to be mnemonics indicating the human meaning of the data referenced by the name. "HasChild" might well be the name given to a switch that indicates whether or not the person referenced has a child. The name is an abbreviated but ungrammatical sentence that helps the programmer and reader understand what the data represents.

  • 1
    To elaborate and answer the question, no, those names are not grammatical because they are not sentences, by intention. As for the rule, 'naming' is typically informal because it is not a full sentence but just a moniker of sorts. – Hank Nov 6 '17 at 15:40
  • Okay, compiles treat "kjljfsewrwerw" as what you want but my question is not about compiling but about human readability. I have voted up to rest of answer. thanks. – kokabi Nov 6 '17 at 17:15
1

In addition to Jeff Morrow's answer, the program variables are not in fact used as questions (isItShown is a question). isShown will contain true of false, and as such is the answer to the question.

There are two parts to it: the 'is' part indicates that it's probably a binary (boolean) answer (true or false). The rest of it (Shown, Visible, Enabled etc etc) indicate the question is answers.

Not particularly grammatical in English, no, but in the context of a computer language very understandable.

Not the answer you're looking for? Browse other questions tagged or ask your own question.