Variable names: how to shorten the "index"?

I like to keep my variable names short but readable.

Nevertheless, when, for example, by naming a variable that contains the index of an element in a certain list, I am inclined to use elemIndexit because I do not know the correct (and generally accepted) way to abbreviate the word "index".

Is there a canonical way to abstract the "index"? Or is it best to write it down completely to avoid misunderstandings?

+5
source share
2 answers

In my experience, it depends on the context. Usually I can determine if something is an index of what it is used for, so I am often more interested in knowing that it is an index.

:

(: ), , , , , - , i.

:

//For each pixel in the image, threshold it
for (int i = 0; i < height; i++ ) {
  for (int j = 0; j < width; j++) {
    if (image[i][j] < 128) {
      image[i][j] = 0;
    } else {
      image[i][j] = 255;
    }
  }
}

, , :

File[] files_in_dir = ...;
int num_files = files_in_dir.length();
for (int fileIdx = 0; fileIdx < num_files; fileIdx++) { //for each file in dir.
  ...
}

, , , , :

int imageToDeleteIdx = 3; //index of the image to be deleted.
image_list.delete(imageToDeleteIdx);

" , ", ; i.e.: , . , , , . , .

+7

. , , .

. . :

i, j, k

, , , :

x, y, z

, , . . - . , .

, . -, , .

+1

All Articles