Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
detrin1854yIn python package quantarhei we often need a, b, c for bra and ket states. We use on the other side i, j, k anywhere you have no idea what short name you should use.
-
ltlian21884yIt's what's common to use for the index variable in math in general as well. You are free to use any other symbol, but people might look for the reason why you are specifically avoiding this convention.
I remember using 'o' (for object) for the lambda variable in a project where everyone else just used x (or 'e' for element/event in the frontend), just because x and e incurred autocompletes for me. I ended up renaming it all back to x and e after discovering how it looks like I'm signalling something by deliberately changing the notation.
I figure the third "no it's fine, just checking" was my call to just follow convention. Funny how much time these things can cost. -
@bosi The things you learn after programming for 10 years....
But, I regularly use a and b as well when working with nested loops! -
theuser47814yI use i, j, b, and n for some reason. Probably got it from a textbook somewhere.
j is probably not good though, error prone. -
Here's my current logic:
i is an iterator or index,
v, *v are vectors or collections,
*c is the number of elements in the respective *v,
el,elem,item are elements,
ev is an event
e is avoided due to it being inobvious.
If there are multiple of any of these, none of them may have a type-based name. If you know the implementation, every name must be obvious individually, and type-based names are only obvious when there's only one value of the type involved. -
There's no way you have two nested loops and no distinct property by which to name both iterators, so j is already a bad name.
-
The "i for index" is retrofitted. It actually comes from Fortran, where variables had default types inferred from their names unless the type was explicitly declared. If a variable name started with I,J,K,L,M or N, it was integer, otherwise it was real.
-
How about no longer use indexed loops (if your language allows it) and call your variables what they are.
So don't do
for(int i=0; some boolean; i++) {
....
}
And instead do this
for(var billingItem in basket) {
...
}
Much more readable and safer to use 😁 -
no idea, i do c for a single cycle, c1, c2, c3... for nested cycles, and x, y, z, when they're about traversing (pseudo)spatial structures.
Why do programmers always start with variable I,j,k for loops and not a,b, c ...?
question