|
|
|
|
|
by scintill76
1248 days ago
|
|
> The aphorism "There are two hard problems in computer science: cache invalidation, and naming things." is not an argument to never cache and never name things. Sure, it can’t be completely eliminated, but why not do less of a thing that’s hard, when it can be avoided? Values have a “name”, whether it’s a variable ‘keysAsString’ or the expression ‘keys.join(' ')’. The problem with keysAsString is that you have to type it twice, once to define it and again to use it. It’s also less exact, because it’s a human-only name, not one that has a precise meaning according to the rules of the language. (E.g. a reader might wonder what the separator between the keys was - if you don’t store it in a variable, then the .join “name” tells you precisely right at the site it’s used.) Making the variable name more precise implies more tedium in the writing and reading. If the value is used twice or more, I would usually say storing it in a well-named variable is preferable, but if it’s cheap or optimizable by the compiler I might still argue for the expression. This may be a irreconcilable split between different types of thinkers, perhaps between verbal and abstract. |
|