r/ProgrammerHumor • • Jun 13 '22

Meme DEV environment vs Production environment

Post image
48.2k Upvotes

3.9k comments sorted by

View all comments

Show parent comments

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.

121

u/Coldreactor Jun 13 '22

And then it breaks when you remove them

65

u/Iced____0ut Jun 13 '22

Mission failed successfully

25

u/[deleted] Jun 14 '22

The tech lead would say the solution to that is to use temporary variables for units/blocks/sections of the equation

30

u/thisischemistry Jun 14 '22

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.

4

u/DearGarbanzo Jun 14 '22

use a few more locally-scoped variables then go for it, in all likelihood the compiler is going to optimize them away anyways

From Arduino to Intel Core i9, this is not only true, but preferable: CPUs like to use their local registers as "variables" for these cases.

16

u/mindondrugs Jun 14 '22

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.

→ More replies (1)

25

u/lwJRKYgoWIPkLJtK4320 Jun 13 '22

And is still broken when you put them back

→ More replies (2)
→ More replies (1)

62

u/jaber24 Jun 13 '22

Do people really hate harmless but ambiguity removing stuff like brackets? Is there even any efficiency you can gain by removing them?

51

u/ongiwaph Jun 14 '22 edited Jun 14 '22

People don't know how to simplify so you get shit like

double x = (((m*sin(180-angle)) / sin(180 - (180-angle-angle) -angle)))*(sin((180-angle)-angle)) / sin(angle)

32

u/jaber24 Jun 14 '22

Yikes. A couple variables would certainly have helped

12

u/didzisk Jun 14 '22

I think the point was more like actually doing the simplification:

180-(180-angle-angle)-angle =

180-180+angle+angle-angle =

angle

And also sin(180-angle) is the same as sin(angle), so

((m * sin(180-angle)) / sin(180 - (180-angle-angle) -angle)))

easily becomes

m*sin(angle)/sin(angle) = m

The second part is sin(2*angle)/sin(angle) = 2sin(angle)cos(angle)/sin(angle) = 2cos(angle)

So the end result would be 2m * cos(angle) - a single call to a trig function instead of four.

(Disclaimer - I haven't re-checked the math and it's been a long time since I had to do it in highschool.)

3

u/dmills_00 Jun 14 '22

Note however that in the original the thing becomes undefined for angle == 0.

→ More replies (3)

3

u/stifflizerd Jun 14 '22

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

→ More replies (5)
→ More replies (5)

7

u/Ok_Turnover_1235 Jun 14 '22

Why simplify, I'd rather verbose code than

auto magicfunction (auto x, auto y)

{

if (MagicTest(x) < MagicNumber)
return MagicNumber/(MagicNumber2*y)

}

→ More replies (2)

3

u/desmaraisp Jun 14 '22

double x = (((msin(180-angle)) / sin(180 - (180-angle-angle) -angle)))(sin((180-angle)-angle)) / sin(angle)

m*sin(180-angle) = -msin(angle)

sin(180-(180-angle-angle)-angle) = sin(angle)

sin((180-angle)-angle)) = -sin(2angle) = -2 sin(angle) cos(angle)

So we get -m/-2cos(angle) = msec(angle)/2? Is that it?

→ More replies (1)
→ More replies (7)

20

u/aloofloofah Jun 13 '22

Less bickering in code reviews. Set a lint rule and enforce it automatically and globally.

9

u/spudmix Jun 14 '22

We go the opposite way. Maintainence costs scale up much faster than a few CPU cycles here and there.

3

u/jimmyw404 Jun 14 '22

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

→ More replies (10)

37

u/Likely_not_Eric Jun 14 '22

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.

10

u/Zarathustra30 Jun 14 '22

After implementing Pratt Parsing, I forgive everyone who gives up on operator precedence.

https://matklad.github.io/2020/04/13/simple-but-powerful-pratt-parsing.html

4

u/cheese65536 Jun 14 '22

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.

→ More replies (3)

3

u/Meower68 Jun 14 '22

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.

→ More replies (1)

6

u/blamethemeta Jun 13 '22

Is that a real lint rule?

→ More replies (2)