2 ms·
I disagree, and think people should use lots and lots of temporary variables. variables like "retval", "data" or even "result", as quoted in GP. I have zero qu
by logicallee 11y ago
I disagree, and think people should use lots and lots of temporary variables. variables like "retval", "data" or even "result", as quoted in GP.
I have zero qualms about writing two lines
bool passes = /*stuff goes here*/
if (passes) {
}
whereas it is trivial that you could fold this into one line. the ONLY thing you're adding is the term "passes". Which most certainly is meaningful to the human reading it.
Compare:
if (!(i%2))
with
bool isodd = i%2;
if (!isodd)
which test do you think you'll accidentally flip the parity of?
Likewise I find "retval", "data", etc, to be perfectly fine variable placeholders while you treat the thing for a few lines.
- jessaustin 11y agoIn particular situations "wasted" vars like this are helpful. (although I agree with sibling comment that informatively-named functions are usually a better way to communicate meaning than extra vars) If this is your general rule, however, your code will be like twice as long as it needs to be.
- logicallee 11y agoi'll take twice as long over twice as wide any day of the week :)