3 ms·
I’d love to understand the rationale for preferring extremely short variable names.
by hamandcheese 6y ago
I’d love to understand the rationale for preferring extremely short variable names.
- tempest_ 6y agoGotta save those bytes
- tedk-42 6y agoSingle letter variable names are throw away variables which you don't actually care about except for maybe a line or so. I think to use them when I'm trying to "show my working out" and it takes me back to algebra class days so I don't mind
- dmlerner 6y agoI like short variable names - for variables used in only a short block of code. I like long variable names - for e.g. a field on a struct used all over a file, and certainly exported ones. I think "Go uses single letter variable names" is not so true in practice. There's a balance, in every language, between when to use short and long names. Go's balance is tilted (a good bit) more towards short, but it's not a hard rule. There's significant mental overhead in reading `numberOfSubprotosOnProto`, as well as time hearing it in my head. I'd rather see `n` declared, used a few times in the next <10 lines, and then disappear. If there's two similar concepts in the same function, use slightly longer names, sure. Certainly not m and n. I think that's the same reason math tends to use single letter variables. "Taylor series are easy! Just memorize: 'f_series_degree(evaluation_point, expansion_point) = sum(derivative_order=0..series_degree, (evaluation_point - expansion_point)^derivative_order * f^{derivative_order}(expansion_point) / derivative_order!)' No thanks, I'll take f_n(x, a) = sum(i=0..n, f^n(a)(x-a)^n/n!).
- franklyt 6y agoI don’t know if it’s ironic or not, but as someone not into mathematics, the first example is far more readable, and it’s not close.
- runald 6y agoBy readable, I think you mean you get to read some whole words thereby get the impression of better readability, but in actuality it doesn't not necessarily aid comprehension if you don't know anything about taylor series, or maths in general. I'm not saying more descriptive variable names doesn't help, but saying that you are not into mathematics makes your point moot.
- franklyt 6y agoBut I know what an evaluation is, a point is, a degree is, etc. These words contain semantic data.
- justsomeuser 6y agoSome people prefer lattes, some cappuccinos, but it's all milk baby.