Naming Conventions: What to name a boolean variabl

2019-01-11 12:13发布

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.

11条回答
混吃等死
2楼-- · 2019-01-11 12:46

I would call the variable beforeLast.

查看更多
混吃等死
3楼-- · 2019-01-11 12:48

hasFollowingItems? or hasFollowingXXXXs where XXXX is whatever the item in your list is?

查看更多
可以哭但决不认输i
4楼-- · 2019-01-11 12:48

isPenultimateOrPrior

isBeforeEnd

查看更多
萌系小妹纸
5楼-- · 2019-01-11 12:54

A simple semantic name would be last. This would allow code always positive code like:

if (item.last)
    ...

do {
   ...
} until (item.last);
查看更多
Melony?
6楼-- · 2019-01-11 12:58

Haskell uses init to refer to all but the last element of a list (the inverse of tail, basically); would isInInit work, or is that too opaque?

查看更多
登录 后发表回答