this post was submitted on 09 Jul 2023
609 points (93.8% liked)

Programmer Humor

32042 readers
1120 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] psysop 1 points 1 year ago (3 children)

I'm honestly prefer short but (usually) complete words. Somewhere along the line I realized that being explicit really helps when you need to change it later.

[–] [email protected] 5 points 1 year ago (2 children)

due to convention everybody understands what i and j are, I don't think they need longer names. If it's something more complicated than a counter or index then maybe you should be using a foreach loop instead (if language supports it)

[–] psysop 3 points 1 year ago (1 children)

I generally use 'count' for a counter and 'idx' for index.

I'm not using C or Java languages though - if I were I would probably go with the more classic terse approach.

Also, if I'm reviewing a PR and I have to load more of the diff context to understand what a variable represents, then that variable has the wrong name.

[–] [email protected] 3 points 1 year ago

Even as an embedded C developer I use "idx" and "count" instead of "i". Not just because I'm a member of the "slightly longer but more descriptive names are better" gang, but also for searchability. If I'm trying to track down where an array is accessed in a loop, for example, "idx" is more likely to take me only to the results I'm looking for and not also the "i" in int8_t or whatever.