*Naming Conventions*

  • Thread starter Marc 'BlackJack' Rintsch
  • Start date
M

Marius Gedminas

Certainly i and j are just as generic, but they have the
advantage over 'item' of being more terse.

Python programmers usually prefer readability over terseness. Finding
a variable named 'i' that is not an integer index would be surprising
to me.
 
N

Neil Cerutti

Python programmers usually prefer readability over terseness.
Finding a variable named 'i' that is not an integer index would
be surprising to me.

Terseness and readability can go together in some circumstances,
though. But every case should be handled with taste and the
application experience, obviously. In a situation where 'i' might
be misleading I wouldn't use it.
 
B

bruno.desthuilliers

(snip)


Why not?

Because
1/ too much terseness (like too much verbosity) goes against
readability,
2/ 'i' and 'j' are canonical names for C-style for loops indices - and
Python's for(each) loops are very different...

A few special cases aside, one-letter identifiers are bad when it
comes to readability. As far as I'm concern, I stopped using 'j' even
in C code a long time ago - as soon as I have too distinct loop
indices, I can never remember what are 'i' and 'j' supposed to
represent, so I prefer to name them more explicitly (ie : 'row' and
'col').

Just make the test:


for (i=0; i < mi; i++)
for (j-0; j < mj; j++)
f(a[j]);


vs

for (row=0; row < nb_rows; row++) {
for (col=0; col < nb_cols; col++) {
init_item_at(grid[row][col]);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top