Re:How to Write Unmaintainable Code (2017)
by dawkins on Friday August 17, 2018 @08:20AM
(#17782219)
In Go single letter variables are used when they are short lived (3 or 4 lines) and in this cases I find it way more readable than long names.
[ Parent
| on HN ]
It's also perfectly acceptable (and preferred) if the code maps cleanly onto some existing mathematical terminology. 'v' is more readable than 'velocity' in the correct context.
Re:How to Write Unmaintainable Code (2017)
by kstenerud on Friday August 17, 2018 @10:00AM
(#17782862)
... until it isn't.
The problem is that you get too close to the code you write, and make assumptions about its obviousness that simply aren't true. Far better to be explicit at the cost of a few extra keystrokes.
Re:How to Write Unmaintainable Code (2017)
by maze-le on Friday August 17, 2018 @08:31AM
(#17782263)
Yes, single letter variables do have their place. But this place is very limited. Consider these lines in ruby
data.reject{|e| e.value.nil?}
data.reject{|element| element.value.nil?}
I would always prefer the first one. My general rule of thumb is: If a variable has the scope of exactly one line, or if it is an incremental counter, use one letter.I just read it and thought 'e' was an error.
Re:How to Write Unmaintainable Code (2017)
by smudgymcscmudge on Friday August 17, 2018 @09:16AM
(#17782553)
I’ll admit to a few larger funcs where I used one letter variables. It always starts with me thinking it will be a three-line routine, then It turns into a 30 line monstrosity that I don’t realize until I get a code review comment like “wtf is ‘zz = z’ about?”