i,j, n,m, x,y,z ... We dont know the alphabet

This is a discussion on i,j, n,m, x,y,z ... We dont know the alphabet within the A Brief History of Cprogramming.com forums, part of the Community Boards category; Not working unexpectedly today, so I'm home bored out of my tree, and got to thinking (ya, it happens). [warning: ...

  1. #1
    Peace
    Join Date
    Aug 2001
    Posts
    1,510

    i,j, n,m, x,y,z ... We dont know the alphabet

    Not working unexpectedly today, so I'm home bored out of my tree, and got to thinking (ya, it happens).

    [warning: This will only seem interesting if you are a) bored out of your mind, like me or b) slow in the head (arguably also like me)]

    Us programmers have strange habits in terms of naming conventions. We commonly use "i" as a counter. This makes some sense as its short form for integer. "n" is also common (number). So far so good. Yet when a nested loop is found and we need a new counter, we commonly proceed to j (or m after n). Apparently this is simply because j comes after i in the alphabet as has nothing whatsoever to do with our origional reason for chosing a logical variable name.

    I tried using inc1 (for increment) and inc2 as its use was more apparent, but I have some kind of personal religious belief against using numbers in my variable names, so that fell through. x y and z are reserved for spacial coordinates, and it would be heresy to use them as simple counters. Doesn't it seem arbitrary to anyone else that we use two separate methods to derive an appropriate name? Why start in the middle of the alphabet and then proceed down the line from there?

    The point? Yes, I sort of have one... I think there are lots of "standard" things we do that have no logical basis and yet are taught de facto. We have no idea why we do them, but we do it anyhow. Things like treating structs and classes like totally different creatures. We do it because its always been done that way. We no longer know why.

    ... Okay so I need to get outside, but its really wet. I'd say its ........ing harder than an alcoholic on cheap beer night, but thats probably too rude for the PG rating, so I wont... wait... doh...
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  2. #2
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    Code:
    int ia, ib, ic, id;
    ?

  3. #3
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    (i, j) is used frequently in math with vectors.
    hello, internet!

  4. #4
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Yes, the math language is to blame

    a,b,c,k = number constants
    k,m,n = any integer (l is too similar to 1)
    x,y,z = coordinates in 1,2 and 3 dimensions
    u,v,w = vectors
    A,B = matrices
    i,j = matrix indexing

    etc.

    btw, questions like yours are quite interessing.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  5. #5
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    lol
    throw some hungarian notation in there
    lol

    [crappy code]
    for (UINTi=0;UINTi<=5;UINTi++)
    {
    std::cout<<"Hungarian notation sucks"<<std::endl;
    }
    [/crappy code]
    PHP and XML
    Let's talk about SAX

  6. #6
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    >>btw, questions like yours are quite interessing.

    Ah, thank you for making my thread feel less like pointless pontification.


    a,b,c,k = number constants
    k,m,n = any integer (l is too similar to 1)
    x,y,z = coordinates in 1,2 and 3 dimensions
    u,v,w = vectors
    A,B = matrices
    i,j = matrix indexing
    Yes, thats pretty much the way I understand it too. I'm just not sure when this became some sort of unofficial standard. I mean, why a,b,c,k? Why i,j for matrices? Theres got to be reasons buried somewhere for this stuff.
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  7. #7
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    I read in a JavaScript book that using 'i' as your count variable is a programming tradition which originally started in (insert old programming language here). Now look what you've done; I have to go get that book back and find out what it said.

  8. #8
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    with loop variables I usually use x, y, z, i, and j. Anything else and I tend to get confused and write stupid things... for(int boobie=0....

  9. #9
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Apparently the language was called "Forth". www.forth.org for more info.

  10. #10
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    haha, i use i and count as my usual counters. don't really know why, just do.

    oh, also...
    i,j,k are used in unit vector notation for the three dimensions as well.

  11. #11
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>>
    I think there are lots of "standard" things we do that have no logical basis and yet are taught de facto. We have no idea why we do them, but we do it anyhow.
    <<<

    One of the first real high level programming languages was FORTRAN. In Fortran, variable with names beginning with I, J, K... up to O I think, (rarely use that many), were implicitely typed as integers, where variables beginning with the other letters were implicitly real.

    Of course you could declare a variable to be different thus...

    REAL*4 I

    ... made a 32 bit real and...

    INTEGER*2 X

    ... made a 16 bit integer.

    As many people didn't bother declaring their variables for loop counters, I, then J then... and old habits die hard.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  12. #12
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Originally posted by lightatdawn
    I mean, why a,b,c,k?
    The word "constant" is spelled "konstant" in many other germanic languages (swedish, german etc.)

    In Fortran, variable with names beginning with I, J, K... up to O
    There's a good explanation.


    I also think it's quite natural to type like that.
    Code:
    int i;
    char c;
    char ch;
    long l;
    class Dog;
    Dog d;
    Dog dog;
    //etc.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. shorter way to represent alphabet
    By cdkiller in forum C++ Programming
    Replies: 5
    Last Post: 09-30-2006, 12:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21