Naming conventions: how to name a boolean variable?

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

The only decent name I can think of is "inFront", but I don't think it's descriptive enough.

Another option would be isNotLast. This is not a good practice (Code Complete, p. 269, Use logical names of logical variables).

I know that I can change the definition of a variable. Thus, true is returned when the object is the last and calls the isLast variable, however this would facilitate this task if I had the first explanation.

+56
coding-style naming-conventions
Aug 04 '09 at 14:57
source share
12 answers
isBeforeTheLastItem isInFrontOfTheLastItem isTowardsTheFrontOfTheList 

It may be too verbose, but they can help you give ideas.

+52
Aug 04 '09 at 14:59
source share

My vote is to call it IsLast and change the functionality. If this is not an option, I would leave the name IsNotLast.

I agree with Code Complete (use positive logical variable names), I also think that the rules are broken. The key is to break them only when you are absolute. In this case, none of the alternative names is different from the name that “breaks” the rule. So this is one of those times when a rule violation may be in order.

+32
Aug 4 '09 at 15:14
source share

hasFollowingItems? or hasFollowingXXXXs, where XXXX is what the item is on your list?

+17
Aug 04 '09 at 15:01
source share

Personally, more than anything, I would change the logic or look at the business rules to determine if they dictate any potential names.

Since the actual condition, which switches the logical value, is actually an act of the "last". I would say that switching the logic and calling it “IsLastItem” or similar would be the preferred method.

+13
Aug 04 '09 at 15:01
source share

isPenultimateOrPrior

isBeforeEnd

+4
Aug 04 '09 at 15:05
source share

Haskell uses init to denote everything except the last element of the list (mostly the opposite of tail ); will isInInit work, or is it too opaque?

+2
Aug 04 '09 at 15:03
source share

The simple semantic name is last . This will allow the code to always have a positive code:

 if (item.last) ... do { ... } until (item.last); 
+2
Jun 13 '12 at 22:01
source share

What about:

  hasSiblings or isFollowedBySiblings (or isFolloedByItems, or isFollowedByOtherItems etc.) or moreItems 

Although I believe that even if you should not get used to the “rules”, sometimes the best way to achieve something may be to make an exception to the rule (general Code rules), and in your case, the name of the variable isNotLast

+1
Aug 04 '09 at 15:02
source share

I would name the beforeLast variable.

0
Aug 04 '09 at 15:02
source share

Two questions to think about

  • What is the scope of the variable (in other words: are you talking about a local variable or field?)? A local variable has a narrower scope than a field. In particular, if a variable is used in a relatively short method, I would not have much about its name. When the scale is large, the name is more important.

  • I think there is such a conflict in which you are considering this variable. On the one hand, you say “false when the object is the last in the list”, where, on the other hand, you also want to name it “inFront”. An object that is (not) the last on the list does not hit me (not) inFront. That I would go with isLast.

0
Aug 04 '09 at 15:06
source share

I need a good variable name for a boolean that returns false when the object is the last in the list. According to the latest PEP 8 Style Guide for Python code , variable names "must be lowercase and words must be separated by underscores to improve readability." So you should name your variable, for example,

 is_not_last 
0
May 9 '19 at 11:40
source share

I would go with isUnlast.

He is short, informative, and describes the situation perfectly!

-four
01 Oct
source share



All Articles