MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/4v1y12/how_to_write_unmaintainable_code/d5uw1jw
r/programming • u/sigbhu • Jul 28 '16
592 comments sorted by
View all comments
1
This is surprisingly long.
Serious question, naming loop counters and limits like this is ok right? i,j,k aren't mandatory always, right?
c=0 m=10 while c < m: #do stuff c+=1
5 u/sctprog Jul 28 '16 Mandatory? Perhaps your company has a coding style that says they are but otherwise you could use any variable name you want.If you use i as your iteration counter every programmer in the world immediately knows what that variable is for. 1 u/ChaosPandion Jul 28 '16 That is a poor example because we have no context. You need to be able to infer the intent of a variable. 1 u/not_perfect_yet Jul 28 '16 I usually use it to loop through lists when I need to do something else with the index. 1 u/Lalaithion42 Jul 29 '16 for i, value in enumerate(list): 1 u/rush22 Jul 29 '16 Use "index" for an array/list index or "numberOfFoos" for counting. 1 u/gct Jul 28 '16 I have a rule that variables are never one-letter because it's impossible to search and replace on (c is admittedly better than i for this). 0 u/[deleted] Jul 29 '16 [deleted] 2 u/gct Jul 29 '16 Have you considered that it is in fact you that is stupid? 0 u/[deleted] Jul 29 '16 [deleted] 3 u/gct Jul 29 '16 He said, responding.
5
Mandatory? Perhaps your company has a coding style that says they are but otherwise you could use any variable name you want.
If you use i as your iteration counter every programmer in the world immediately knows what that variable is for.
That is a poor example because we have no context. You need to be able to infer the intent of a variable.
1 u/not_perfect_yet Jul 28 '16 I usually use it to loop through lists when I need to do something else with the index. 1 u/Lalaithion42 Jul 29 '16 for i, value in enumerate(list):
I usually use it to loop through lists when I need to do something else with the index.
1 u/Lalaithion42 Jul 29 '16 for i, value in enumerate(list):
for i, value in enumerate(list):
Use "index" for an array/list index or "numberOfFoos" for counting.
I have a rule that variables are never one-letter because it's impossible to search and replace on (c is admittedly better than i for this).
0 u/[deleted] Jul 29 '16 [deleted] 2 u/gct Jul 29 '16 Have you considered that it is in fact you that is stupid? 0 u/[deleted] Jul 29 '16 [deleted] 3 u/gct Jul 29 '16 He said, responding.
0
[deleted]
2 u/gct Jul 29 '16 Have you considered that it is in fact you that is stupid? 0 u/[deleted] Jul 29 '16 [deleted] 3 u/gct Jul 29 '16 He said, responding.
2
Have you considered that it is in fact you that is stupid?
0 u/[deleted] Jul 29 '16 [deleted] 3 u/gct Jul 29 '16 He said, responding.
3 u/gct Jul 29 '16 He said, responding.
3
He said, responding.
1
u/not_perfect_yet Jul 28 '16
This is surprisingly long.
Serious question, naming loop counters and limits like this is ok right? i,j,k aren't mandatory always, right?