Today we had a discussion at work.
The focal point was a cite from a book 'Steven C. McConnel. Code Complete, Second Edition':
<em>Arrays are often indexed with the same variables that are used for loop indexes. If you have a one-dimensional array, you might be able to get away with using i, j, or k to index it. But if you have an array with two or more dimensions, you should use meaningful index names to clarify what you’re doing. Meaningful array-index names clarify both the purpose of the loop and the part of the array you intend to access.</em>
My POV was that names like i, j, k are never meaningful (although sometimes it's clear in the context what they mean).
The opposite one was that i, j, k are meaningful if their meaning may be quickly established in the context.
Whose understanding of the word 'meaningful' is correct?
I believe i,j and k are never meaningful names. They are symbols taken from algebra.
I understand "meaningful name" as one that communicates what the variable is representing. For example
if you are iterating over an array of words, each word has several characters, then names like "word_index" and "char_index" would be meaningful names.
It's not like you MUST do it. It's just good technique. So, really, it's what makes <em>you</em> and the team you work with at your prime that matters.
Anyway, I have got to side with the guys on this one. Sometimes variables/etc. are not supposed to represent any real entity in real life. Whenever you need a placeholder and no more, those names can be as meaningful as they come. Meaning is a relative thing.
In computer programming, meaningfull means that the software will understand them by default. You will not need to define them again. Otherwise, you need to define them.
software developers? not all software deveoplers use the same software. You has to specify which language is used. Such as Pascal, C, C++, visual basic etc. In general speaking, meaningfull means the built in functions.
That's correct. i,j, and k are arbitrary names, as the previous commenter said more like algebraic variables. A meaningful name more truly represents the value or values you are storing in the array.
Thanks, guys, for your comments!
Answering Generation Gap's question, we use a few languages (Delphi, Java, php), but the code my team analized was written in Delphi. I didn't aimed to ask only programmers. I've just thought they definitely must know the answer, while other people may or not.