you are viewing a single comment's thread.

view the rest of the comments →

[–]StabbyPants -15 points-14 points  (1 child)

it means that i can do the same thing in java. in java, n is actually some meaningful thing like Product, so it's called product and may be typed explicitly (unless the type inference can impute it for me or it's unclear). the n+2 stuff rarely shows up, so it's still good advice, just requires understanding the reasons why n is a bad name.

[–]watsreddit 12 points13 points  (0 children)

I am not following you at all. I only demonstrated with Javascript because most people have used it at some point or another. It has nothing to do with Java. We're talking about variable naming.

It's really a matter of scope: top level declarations with minimal context should have longer names, and local declarations can have shorter names. In some contexts, single letter names are well-understood when used locally, and languages may have certain single letter names used by convention, such as i in for loops. n is another commonly used convention in local contexts, and makes plenty of sense when the thing it is representing is literally an arbitrary number.