I have a convention to correlate the size of variable scope with its name length.
If a variable is used all over the program, it will be named “response”. If it is <15 lines, then it can be “res”. If it is less than 3 lines, it can be only “r”.
This makes reading code a bit simpler, because it makes unimportant, local vars short and unnoticeable.
Using single character variable names is always bad practice
Unless you are implementing some mathematical formula. Then link the paper and stick to its variables.
Counterpoint: using anything other than ‘i’ as your index in a for loop in C or C++ is obnoxious as fuck.
At most I’ll go with ‘it’ for C++ iterators.
I have a convention to correlate the size of variable scope with its name length.
If a variable is used all over the program, it will be named “response”. If it is <15 lines, then it can be “res”. If it is less than 3 lines, it can be only “r”.
This makes reading code a bit simpler, because it makes unimportant, local vars short and unnoticeable.
Why though? Intellisense helps you write out the full name. And instead of response why not call it whatever the data you’re expecting to be
I agree because it makes the code easier to follow in 6 months time.
Could you comment a couple of examples? At best some that signifiy the importance with them as verstra wrote.
Mostly agree. I’m ok with single characters in a one line / single expression lambda, but that’s the only time I’m ok with it.
Sometimes you’re just using it once and it’s blindingly obvious what it is
To be fair everyone with poor documentation thinks the code is blindingly obvious when they write it.
I understand this conceptually, but there’s also a gremlin in my brain that wants me to make every line as short as possible.
Big same. Long feels complex until you go back later