DEV Community

Discussion on: Tips on naming boolean variables - Cleaner Code

Collapse
 
azclau profile image
A-ZC-Lau • Edited

isEveryUserOnline? Is he? I don't know, maybe? Are you asking me? Or is anyone standing behind me? Why is code talking to me and making me decide? Code is a set of commands. It answers questions. It doesn't ask them.

Seems very pedantic. The word is isn't asking you, it's invoking a question with a binary answer.

userIsActive is a statement. It makes it sound like a constant.

Take for example "Is it 5 o'clock" would invoke a yes/no answer in your mind immediately. If your brain suddenly thinks that the computer is talking to you, rather than you realizing that the variable is actually saving a boolean, it's a problem between chair and keyboard.

Conversely, with your format, "It is 5 o'clock" would be a statement. You don't answer a statement, which makes it seem like a constant.

In fact, I would argue that statements are invocation of action. Because you wouldn't have a statement of "It is 5 o'clock" and then do nothing with it. So the name userIsActive would be a function i.e. userIsActive(), which you would use as in

if (isUserActive) { 
    userIsActive()
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
stepanstulov profile image
Stepan Stulov • Edited

For invocation of actions in the imperative programming paradigm, with which you (arguably) unbeknownst to yourself operate, imperative mood of verbs is conventionally used. This is what gave imperative programming paradigm its very name.

if (userIsActive)
    SetUserActive(false); // Imperative mood of the word "set"
Enter fullscreen mode Exit fullscreen mode

PS: In an educated and intelligent community such as ours we do not call people "a problem between the chair and the keyboard" just because we disagree. Disagree one may. Insult one may not. Assuming education and intelligence are there in the first place, of course.