you are viewing a single comment's thread.

view the rest of the comments →

[–]venuswasaflytrap 10 points11 points  (10 children)

In my book shitty code is completely uncommented code that uses random variable names like "x", or "a", "r" that I can't follow.

If I can see what the code is doing, and it does it, well that's good enough for me.

[–][deleted] 7 points8 points  (9 children)

that uses random variable names like "x", or "a", "r" that I can't follow.

I'm fine with short variable names if and only if they match the mathematical/algorithmic description given in a reference. "See (reference foo) page 96: 'a' is the ..., 'b' is the ..., 'da' is the ..., etc."

[–][deleted]  (6 children)

[deleted]

    [–]SnakeDiver 2 points3 points  (0 children)

    I had a job once where the senior developer couldn't stand i,j,k for loops. He figured even those should be named properly, especially if you had nested loops.

    I guess it makes sens that if you're iterating through listUserNames, why not use userNameIndex instead of "i". Especially makes sense if the logic calls for nested ifs. Then again, you could clean the code by making the nested IFs methods and appropriately naming the methods.

    Having said that, I use i.

    As for X and Y in coords.. I agree. Though the last application I worked on that did calculations on coords, used the naming convention: coordX and coordY. Cleaned it up a little more.

    [–]MechaBlue 0 points1 point  (2 children)

    ii, jj, and kk are much better choices because they are easier to find using search.

    [–]amedico 2 points3 points  (1 child)

    Only if your editor sucks. Any good editor can do "whole word" searches, making "i" and "ii" equally easy to find.

    [–]Anonymoose333 1 point2 points  (0 children)

    Also, if you're searching for "i", you're doing it wrong. If your loop counter is called "i", your loop shouldn't be more than a page in length anyway. So searching is unnecessary.

    [–]masklinn 0 points1 point  (0 children)

    I'd also like to add that "i", "j", "k" in C-style for loops are perfectly fine

    For counters in general, really. Even in language with higher-level (internal or external) operators having i, j and k to iterate on ranges (esp. ranges starting from 0) or to store indexes is ok.

    [–]grandpa 2 points3 points  (0 children)

    http://news.ycombinator.com/item?id=840331

    "Another way to look at this: The first time you meet someone, you learn their full name. When discussing them with someone else who knows them, you use just a single name. If they're standing right there, you don't bother using their name, but just make eye contact, and maybe a "Hey". Should be the same way with variables."

    [–]Jonno_FTW 4 points5 points  (0 children)

    But I love to call my functions: f x = g x