17
Warning: Stop using single-letter variable names in your code
I just spent 2 hours debugging a 500 line script because someone used 'i', 'j', and 'k' for 3 different loops nested together. If you're writing anything longer than a quick test, give your variables real names like 'userIndex' or 'rowCount' - has anyone else gotten burned by this kind of shortcut?
3 comments
Log in to join the discussion
Log In3 Comments
nancy_ross26d ago
Oh yeah, "i", "j", and "k" in three nested loops is basically a hazing ritual at this point. Nothing like squinting at line 312 trying to figure out if that rogue 'k' is the outer loop or the middle one while your coffee gets cold. I once inherited a script where someone used 'ii', 'jj', and 'kk' thinking that made it better. Spoiler: it did not. Real variable names are free, people. Use them or spend an extra hour playing "guess which counter I meant".
4
charles_kelly4326d ago
And don't even get me started on when someone throws an 'l' in there too, I swear I spend half my time counting characters like it's a puzzle. I had a colleague once who used 'i1', 'i2', and 'i3' and then got mad when nobody could tell which loop was which without a dang map. Might as well just name them 'please_dont_touch_this' and 'broken_again' and call it a day.
7
the_robin23d ago
Wait, isn't "ii" actually WORSE than just "i" because now you've got two characters and it's still just as meaningless? Some people really don't get that adding more letters to a bad name doesn't make it good.
3