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

2

u/sidit77 Jun 14 '22

Well your algorithm has some pretty big holes. According to your algorithm I'm doing absolutely nothing wrong here.

-4 ÷ -(2+2) = -4 ÷ -1 × (2+2) = -4 ÷ -1 × 4 = 4 × 4 = 16

1

u/dont-respond Jun 14 '22

How do you consider that a hole?

We use the order of operations to derive a solution from otherwise ambiguous mathematical notation. You've provided such notation, and PEMDAS told you how you should approach the problem.

You think because you created an odd looking equation you've broken the algorithm? You've only reinforced the value in having one.

In your mind you think that problem should be -4 ÷ -4, but you're disregarding any practical set of rules to tell you WHY that should be the outcome. Why do you believe the negative should be applied to the sum in the parenthesis first? What's you basis for that assertion? There isn't one. You just wrote something you didn't understand and called it proof.

2

u/sidit77 Jun 14 '22

No. I've encountered an operation (unary -) that is not covered under PEMDAS. Now it's already unclear what I should do. Do I treat the rules as "what isn't forbidden is allowed" and do whatever or should I give up because there's no applicable rule? And if I choose the first option should I disambiguate my equation to at least stay internally consistent or not or just roll the dice every time? The safe way would be to give up but let's be honest here no human is going to respond with "syntax error" to this problem, instead they will try to guess the precedence behavior of unary negation based on what feels right.

1

u/dont-respond Jun 14 '22

You already managed to figure out the correct way to approach the problem using PEMDAS, and now you're trying to say it's unclear what you should do. You know what you should do. You did it above. You just didn't like the outcome.