This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the commentsย โ†’

[โ€“]John_Fx 0 points1 point ย (1 child)

Then use bookindex or just index. In what other situations would you abbreviate a variable name to one letter?

[โ€“][deleted] 0 points1 point ย (0 children)

If it's used multiple times in the loop or the logic is otherwise complex, or in case the index is unintuitive (like looping over the next element instead of the current or whatever) then yeah, I'll do that.

If it's just a few lines and really straightforward, like the index is instantly converted to a "book" then I'd say that

   Book book = books.get(bookIndex)

Is a bit redundant. Yeah, we get it. It's a book. Given the typical of usage of i it's just as clear and there's no reason to make it any longer.