Timeline for Using single characters for variable names in loops/exceptions [duplicate]
Current License: CC BY-SA 3.0
48 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 21, 2024 at 14:28 | comment | added | Johan Karlsson | @DanAtkinson I think that's much more gentle and diplomatic way of putting it. | |
| Feb 19, 2024 at 10:19 | comment | added | Dan Atkinson | @JohanKarlsson I'm inclined to agree that it's harsh. I will say that, if you're a programmer then i is a standard variable denoting the iteration index of the object being enumerated. | |
| Feb 16, 2024 at 7:38 | comment | added | Johan Karlsson | I don't think this is a relevant, or good, argument "if one does not know what i means in a for loop, then they probably shouldn't be a programmer". That's like looking down on other people and if you are looking for sound argument, it's good to start with relevant argument. | |
| Oct 11, 2019 at 21:09 | comment | added | jxramos | I second the observation by @chrisw about nested loops. I worked on projects that would span the three spatial dimensions frequently x,y, and z for entities with different contexts. Suggestive index names helped a lot here and actually made the code less bug prone for easy to make copy paste errors mixing incorrect indexes. For nestings 3+ deep I'd say its essential to drop the single character convention. | |
| Oct 11, 2019 at 20:37 | comment | added | jxramos | They're also used in python contexts also for lambda expressions but likewise for list-comps and genexp's. In fact the original list-comp PEP uses f for fruit, which is also a single letter convention where the first character is used to abbreviate with. | |
| May 18, 2017 at 2:00 | comment | added | Dhanuka777 | "i - it doesn't mean anything.", but it make sense, which any one understands that 'i' is for 'index' or 'iteration'. This how all programmers write their first for loop (and forever :)) which is a well-known convention. I would say if it was something like 'a' it does'not make sense. | |
| Jun 2, 2015 at 13:19 | history | closed | gnat durron597 CommunityBot TZHX | Duplicate of Why do most of us use 'i' as a loop counter variable? | |
| May 30, 2015 at 19:20 | comment | added | Dan Atkinson | @gnat - Given that this question is older, I'm inclined to say that the other issue is a duplicate. :) | |
| May 29, 2015 at 16:57 | review | Close votes | |||
| Jun 2, 2015 at 7:59 | |||||
| May 29, 2015 at 16:39 | history | protected | gnat | ||
| Jun 2, 2014 at 15:47 | comment | added | David Hammen | I don't want to write a new answer to this old question, and this is just a comment. There's a key concept missing from the list of places where a single character variable name is acceptable, and maybe even preferable, and that's C++ templates. It's very common to see something along the lines of template <typename T, typename U, int N> .... | |
| Apr 29, 2011 at 13:49 | comment | added | Adam Lear♦ | Commenters: comments are not meant to be used for extended discussion, but for clarifying the question. Please use chat for discussion, not answers. If you want to express your support for a standard, see if any of the existing 20 answers list it and upvote that answer. If there's no answer that fits your view, add one. | |
| Apr 28, 2011 at 7:44 | vote | accept | Dan Atkinson | ||
| Apr 27, 2011 at 22:23 | comment | added | Peter Olson | I prefer ex for exceptions and e for event arguments. | |
| Apr 27, 2011 at 22:02 | answer | added | Richard | timeline score: 1 | |
| Apr 27, 2011 at 17:27 | comment | added | Hogan | He should have said that i by itself looks to much like l and 1. After about the 20th time of debugging to find it was an error between those three I stopped using i and l. | |
| Apr 27, 2011 at 17:15 | history | edited | AttackingHobo | CC BY-SA 3.0 | deleted 35 characters in body |
| Apr 27, 2011 at 17:07 | comment | added | Mateen Ulhaq | Become a mathematician - that'll solve all your problems. :) | |
| Apr 27, 2011 at 16:19 | comment | added | sam hocevar | In addition to all the other examples, I also use t for interpolators, or p for pixels. When a project has 18,000 lines of code using p for a pixel value everywhere, I see absolutely no need to use pixel_value instead. | |
| Apr 27, 2011 at 15:14 | answer | added | David Rhoden | timeline score: 1 | |
| Apr 27, 2011 at 15:06 | answer | added | Phoenix | timeline score: 1 | |
| Apr 27, 2011 at 13:25 | comment | added | chrisw | The problem is when you end up in a shop like I work and you have nested loops, then naming takes priority. My colleague and I use to go back and forth, he took the site of verbose naming and I took the side of truncation. After working on a few private projects together, I've changed my viewpoint on this; Due primarily because it's easier to read. Try working in a company with nested loops everywhere and your trying to decide what the 'a' index is for, or the 'z'. Personally I name my variables so comments are not necessary that's my rule of thumb. | |
| Apr 27, 2011 at 13:17 | answer | added | Chris Cudmore | timeline score: 2 | |
| Apr 27, 2011 at 13:03 | comment | added | user13278 | I use single-letter variables in several other situations: x, y, z for coordinates, for instance, and if I'm computing something using a mathematical formula I'll store the intermediate results in variables that match what's used in the formula. | |
| S Apr 27, 2011 at 12:55 | answer | added | gablin | timeline score: 3 | |
| S Apr 27, 2011 at 12:55 | history | made wiki | Post Made Community Wiki | ||
| Apr 27, 2011 at 12:28 | answer | added | Richard Ev | timeline score: 6 | |
| Apr 27, 2011 at 12:23 | answer | added | Berin Loritsch | timeline score: 4 | |
| Apr 27, 2011 at 12:09 | history | tweeted | twitter.com/#!/StackProgrammer/status/63213235771416576 | ||
| Apr 27, 2011 at 12:06 | comment | added | Berin Loritsch | I'd agree with your friend about exceptions, not about iterator/index variables though. In Java, it isn't uncommon to have to handle an exception in an exception handler (i.e. nested try/catch in a catch clause). What do you call the interior exception? I've seen e1, ex, ex1, etc. I typically shorten the exception name, but have it reflect the type of error it is. It just avoids confusion. | |
| Apr 27, 2011 at 11:59 | comment | added | eumiro | "e - it's the most common letter in the English language" - but it doesn't exist as a stand-alone word. So "searching whole words" in your IDE finds exactly what you need. | |
| Apr 27, 2011 at 11:53 | comment | added | Walter Mitty | I think that "self explanatory" is more relevant than "verbose". Sometimes a long variable name is needed in order to be self explanatory. Sometimes a one character name can be self explanatory. | |
| Apr 27, 2011 at 11:52 | comment | added | Walter Mitty | I think that it depends more on the scope of the variable than on the usage. There's a lot of overlap between the two. Loop variables for example tend to have a short scope. | |
| Apr 27, 2011 at 11:38 | answer | added | JeffO | timeline score: 1 | |
| Apr 27, 2011 at 11:18 | answer | added | Jack V. | timeline score: 4 | |
| Apr 27, 2011 at 11:13 | comment | added | Cody Gray | Hmm, I always thought ex was the idiomatic name for an exception variable. | |
| Apr 27, 2011 at 11:00 | answer | added | nikie | timeline score: 17 | |
| Apr 27, 2011 at 10:52 | answer | added | Ingo | timeline score: 4 | |
| Apr 27, 2011 at 10:52 | answer | added | Steven Jeuris | timeline score: 84 | |
| Apr 27, 2011 at 10:50 | answer | added | DPD | timeline score: 1 | |
| Apr 27, 2011 at 10:45 | answer | added | Ekkehard.Horner | timeline score: 6 | |
| Apr 27, 2011 at 10:45 | answer | added | quant_dev | timeline score: 5 | |
| Apr 27, 2011 at 10:28 | answer | added | jwenting | timeline score: 15 | |
| Apr 27, 2011 at 10:24 | answer | added | Péter Török | timeline score: 24 | |
| Apr 27, 2011 at 10:24 | answer | added | Rook | timeline score: 54 | |
| Apr 27, 2011 at 10:22 | answer | added | IvoC | timeline score: 5 | |
| Apr 27, 2011 at 10:19 | answer | added | TZHX | timeline score: 10 | |
| Apr 27, 2011 at 10:11 | history | asked | Dan Atkinson | CC BY-SA 3.0 |