MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/jsrvdw/its_the_law/gc1a7vb
r/ProgrammerHumor • u/khanshahvarem • Nov 12 '20
[removed] — view removed post
378 comments sorted by
View all comments
Show parent comments
186
Usually I'd agree with you but in
for (int i = 0; i < limit; i++)
writing "index" or "iterator" instead of "i" doesn't add any useful information.
It's such a universal snippet that everyone will immediately know what i is.
i
But if someone writes
Class A
{
private int i;
}
then fuck that person.
9 u/AceSLS Nov 12 '20 Class A{private int i;}I'm waiting fingers crossed 27 u/TSPhoenix Nov 12 '20 It isn't about adding information, it is so when I CTRL+F my loop variable I get only my loop variable. Yes I know a better IDE solves this, but we don't always get to choose. 57 u/nasaboy007 Nov 12 '20 If your loops are long/complicated enough that you need to ctrlF your index variable, that sounds like a code smell itself. 1 u/TSPhoenix Nov 13 '20 Sure, but if I can't pick my own IDE I'm probably not talking about a loop I wrote. 12 u/idekvro Nov 12 '20 Can't you specify that you need whitespace around i in your search? 2 u/sometimes_insightful Nov 12 '20 Wouldn’t that miss something like array[i] or i-1 1 u/olafurp Nov 13 '20 Then don't make long loops 1 u/olafurp Nov 13 '20 For this case I agree, it's convention after all. I'm a js guy now so I write these nowadays[...elements].forEach((element, index) => {})Variable name should convey the whole meaning, no more, no less. 1 u/[deleted] Nov 13 '20 That's assuming you want to iterate to the end, though.
9
I'm waiting fingers crossed
27
It isn't about adding information, it is so when I CTRL+F my loop variable I get only my loop variable. Yes I know a better IDE solves this, but we don't always get to choose.
57 u/nasaboy007 Nov 12 '20 If your loops are long/complicated enough that you need to ctrlF your index variable, that sounds like a code smell itself. 1 u/TSPhoenix Nov 13 '20 Sure, but if I can't pick my own IDE I'm probably not talking about a loop I wrote. 12 u/idekvro Nov 12 '20 Can't you specify that you need whitespace around i in your search? 2 u/sometimes_insightful Nov 12 '20 Wouldn’t that miss something like array[i] or i-1 1 u/olafurp Nov 13 '20 Then don't make long loops
57
If your loops are long/complicated enough that you need to ctrlF your index variable, that sounds like a code smell itself.
1 u/TSPhoenix Nov 13 '20 Sure, but if I can't pick my own IDE I'm probably not talking about a loop I wrote.
1
Sure, but if I can't pick my own IDE I'm probably not talking about a loop I wrote.
12
Can't you specify that you need whitespace around i in your search?
2 u/sometimes_insightful Nov 12 '20 Wouldn’t that miss something like array[i] or i-1
2
Wouldn’t that miss something like array[i] or i-1
Then don't make long loops
For this case I agree, it's convention after all. I'm a js guy now so I write these nowadays
[...elements].forEach((element, index) => {})
Variable name should convey the whole meaning, no more, no less.
1 u/[deleted] Nov 13 '20 That's assuming you want to iterate to the end, though.
That's assuming you want to iterate to the end, though.
186
u/[deleted] Nov 12 '20
Usually I'd agree with you but in
for (int i = 0; i < limit; i++)writing "index" or "iterator" instead of "i" doesn't add any useful information.
It's such a universal snippet that everyone will immediately know what
iis.But if someone writes
Class A{private int i;}then fuck that person.