Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming Conventions: What to name a boolean variable? [closed]

I need a good variable name for a boolean value that returns false when an object is the last in a list.

The only decent name I can come up with is 'inFront', but I don't think that is descriptive enough.

Another choose would be 'isNotLast'. This is not good practice though (Code Complete, page 269, Use positive boolean variable names).

I am aware that I could change the variable definition. So true is returned when an object is the last and call the variable 'isLast', however, it would make this task easier if I had the first explanation.

like image 230
Berek Bryan Avatar asked Aug 04 '09 14:08

Berek Bryan


People also ask

What are the 3 rules that need to be considered while naming a variable?

A variable name must start with a letter or an underscore character (_) A variable name cannot start with a digit. A variable name can only contain alpha-numeric characters and underscores ( a-z, A-Z , 0-9 , and _ ) Variable names are case-sensitive (age, Age and AGE are three different variables)

How do you name a boolean method?

The usual convention to name methods that return boolean is to prefix verbs such as 'is' or 'has' to the predicate as a question, or use the predicate as an assertion. For example, to check if a user is active, you would say user.

How do you name a boolean variable in react?

We should name our boolean props with a consistent naming scheme. For instance, we should start with an is prefix for booleans. So something like isEnabled would be appropriate. This way, if we see something that starts with is , we know that we should pass in a boolean value for the prop.


2 Answers

isBeforeTheLastItem  isInFrontOfTheLastItem  isTowardsTheFrontOfTheList 

Maybe too wordy but they may help give you ideas.

like image 57
Bela Avatar answered Oct 14 '22 00:10

Bela


My vote would be to name it IsLast and change the functionality. If that isn't really an option, I'd leave the name as IsNotLast.

I agree with Code Complete (Use positive boolean variable names), I also believe that rules are made to be broken. The key is to break them only when you absoluately have to. In this case, none of the alternative names are as clear as the name that "breaks" the rule. So this is one of those times where breaking the rule can be okay.

like image 27
Jeff Siver Avatar answered Oct 14 '22 00:10

Jeff Siver