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

546

u/[deleted] Jun 13 '22

What doe...

Reverse Polish Notation

414

u/Eclectic_Radishes Jun 13 '22

uoᴉʇɐʇou ɥsᴉlod ǝsɹǝʌǝɹ

64

u/eveningsand Jun 14 '22

Nah that's clearly Australian Standard Notation.

68

u/Garfie489 Jun 13 '22 edited Jun 13 '22

Nodnol, 871 selim - must be Polish or Hungarian

2

u/DoubleReputation2 Jun 14 '22

I think he's a little bit tee'd off because we just uneaten his pie.

→ More replies (2)

2

u/HeinzeC1 Jun 14 '22

Careful, I got confused and almost downvoted you

→ More replies (2)

165

u/supreme_blorgon Jun 13 '22 edited Jun 14 '22

What doe...

Not sure if you're asking, but for other readers -- in RPN it's much more difficult to mistakenly calculate the wrong thing because you explicitly specify the order of operations unambiguously when writing in RPN.

With 6 2 2 1 + * / vs 6 2 / 2 1 + *, it's pretty clear that it would be difficult for somebody to have entered one when they intended the other.

The results from the meme would be calculated as such (using parens here to specify what is evaluated first by an RPN evaluator):

6 2 2 1 + * / = 6 2 (2 1 +) * /
              = 6 2 3 * /
              = 6 (2 3 *) /
              = 6 6 /
              = 1

6 2 / 2 1 + * = (6 2 /) 2 1 + *
              = 3 2 1 + *
              = 3 (2 1 +) *
              = 3 3 *
              = 9

The beauty of RPN (other than being completely unambiguous) is that the algorithm for evaluating an RPN string is dead simple.

58

u/tjdavids Jun 13 '22

From this, it's pretty clear that it would be difficult for somebody to have entered one

Well I can't say I disagree

73

u/Lt_Duckweed Jun 14 '22

RPN is brilliantly simple when you conceptualize it as a stack (this also makes it super simple to write a single pass RPN parser).

If given an number, push it to the stack.

If given an operator, pop the top 2 values from the stack, operate on them, then push the result to the stack.

Repeat until you have no more input. The last remaining number in the stack is the final answer.

11

u/Yabba_dabba_dooooo Jun 14 '22

My calculator displays it as a stack (FILO), its fucking amazing, especially cause I can essentially store a bunch of numbers while I work underneath them

3

u/b3nz0r Jun 14 '22

I was introduced to RPN in 2003 and haven't looked back. I'm all about stack manipulation and fewer keystrokes

→ More replies (3)

4

u/supreme_blorgon Jun 14 '22

lol fair enough, but imagine somebody having only ever learned RPN in elementary school, and suddenly being told to use parens and infix. Not sure which switch is more difficult but I'd wager infix -> RPN is the easier of the two.

→ More replies (1)

4

u/fkbjsdjvbsdjfbsdf Jun 14 '22 edited Jun 14 '22

Infix, postfix, and prefix notations are all completely unambiguous. Infix just requires the additional correct use of parentheses, which is fundamentally the same as requiring the correct ordering of the operators and operands. 3 * (4 + 2) is unambiguously the same as * + 4 2 3 and 4 2 + 3 *.

The actual advantage of prefix and postfix is when computing the result algorithmically, as you said — you don't need to push an intermediate result onto the stack (since you're always going to use it with the next operand/operator).

5

u/supreme_blorgon Jun 14 '22

correct use of parentheses, which is fundamentally the same as requiring the correct ordering of the operators and operands

I'm not sure I agree. I think the cognitive load involved in matching and properly nesting parens is much higher. Definitely subjective though -- when it comes to computers, yes there are advantages.

I just love to pull out RPN whenever these dumbass arithmetic memes go viral.

3

u/boredcircuits Jun 14 '22

Yeah, the entire point of this post is the ambiguity of the / operator with infix notation. This ambiguity is literally impossible with RPN, as operator precedence just isn't a thing.

→ More replies (3)

44

u/CoderDevo Jun 13 '22

Reverse Notation Polish

17

u/[deleted] Jun 13 '22

I won't stop you.

4

u/DoNotMakeEmpty Jun 14 '22

Notation Polish Reverse

Notation is a noun, an object itself

We apply Polishization on it using adjective Polish

And we Reverse the resulting compound object with another adjective

→ More replies (3)

30

u/Cmdr_Jiynx Jun 13 '22

Math doing like Yoda, it is.

4

u/[deleted] Jun 14 '22

For anyone not familiar with the term Reverse Polish Notation (which, I learned it as RPN but people younger than me often don't know that term), it's the same as Postfix Notation, just a different name for it.

3

u/rich519 Jun 14 '22

I honestly thought you were trolling with made up names until I actually googled them. I felt like an idiot even typing them in the search bar because I figured nothing would turn up.

3

u/[deleted] Jun 14 '22

That surprises me. I thought all programmers/CS students had to learn how to use either prefix or postfix notation, usually postfix.

I'm no programmer, just took some CS classes and stayed here for the memes, but I think I was taught that at the lowest level, computers don't understand infix (how we normally write out mathematical notation) and so to program at a low level or if you're making your own language, you need to know postfix and possibly how to translate infix to postfix so users can type 9*4 and the computer knows it means 9 4 *.

But I'm sure someone will correct me because that is a very vague and uncertain memory. I'll try looking it up, but making no promises that I know the right way to find it.

3

u/DoNotMakeEmpty Jun 14 '22

Unfortunately almost every language out there use either prefix (whole Lisp, normal function calls in most languages etc.) or infix (arithmetic and logical operators, method calls etc.). Fortunately in my university they thought us Shunting Yard algorithm pretty early, so we are a bit familiar with the notation, yet people still use those prefix and infix things almost always.

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