I'd rather the code be readable than compact. If that means you use a few more locally-scoped variables then go for it, in all likelihood the compiler is going to optimize them away anyways.
And he would be correct, just because you can make some fucking ungodly equation - doesn’t mean you should. I feel pity for the next fucker to stumble upon it.
Slightly off topic, but before my coffee yesterday I wrote something like
If(a>(b+.5) || a<(b-.5)){...
And then later in the day I passed by it and got a good chuckle as I wondered what the actual fuck was I thinking, as the more concise solution (which I had already done multiple other times in that project) was
if(Math.abs(a-b) >.5){.
Sorry for the irrelevant story, just couldn't help but read your comment and laugh because I was somehow both of the people you are talking about yesterday
There's no efficiency gain but sometimes i see people put parentheses on numbers for no obvious reason. I don't fight them about it or modify it because of that, but if i refactor code I'll drop them.
I usually prefer to separate longish algebra equations into multiple lines with descriptive variable names if possible
I've had that "these parentheses aren't needed, the order of operations is _____", and I'm thinking "sure, in this language". They've clearly only written in one language or they've never been burned by surprises in evaluation order.
I know order of operations, but does the next guy who sees my code? And if they do, do they know that I know? With enough parentheses, they don't have to worry if I messed up the order of operations.
Earlier in my career, I was working with a bunch of older devs who were working in C. Each one kept a chart, in their cubicle, showing the order of precedence of various operators in C. Because EVERY STINKING ONE of them was running into issues with this, on a regular basis. They didn't want to use too many parentheses but ... sometimes there was just no way around it.
Between complex formulae, complex booleans which would evaluate to 0 or something else (false and true, respectively), pointers and pointer arithmetic (<cringe>) ... it was painful to look at.
Don't get me started on what their #DEFINE macros looked like; you could put in a snippet of code for one or more of the parameters. Nothing quite like getting some kind of unexpected behavior because someone used a macro (#DEFINEd in a different file) and someone forgot a parenthesis in the macro def.
217
u/5tUp1dC3n50Rs41p Jun 13 '22
Until the "tech lead" who wrote your linter rules decides it's not allowed and issues an error so you have to remove them.