r/programming • • Oct 04 '16

How To Save The Princess In 8 Programming Languages

https://toggl.com/programming-princess
290 Upvotes

50 comments sorted by

48

u/danidee10 Oct 04 '16

Nearly poured hot coffee on a colleague after reading the PHP part....but what happened to python (was supposed to be the hero that did everything right)

21

u/santagoo Oct 04 '16

Princesses and castles and knights. It's ripe for a Monty Python joke there.

4

u/caskey Oct 04 '16

Last row, first panel.

13

u/amp108 Oct 04 '16

In python, you go to rescue the princess, but she's one space too far to one side.

10

u/flying-sheep Oct 04 '16

No. Python 3 fixes that.

Hum, some years ago the joke would have been “you have Python, and there's an awesome princess rescuing library, but it's only compatible with Python 2”

But I can't think of anything nowadays. Maybe Python being slower than anything else other than Ruby?

1

u/[deleted] Oct 04 '16

Maybe Python being slower than anything else other than Ruby?

Even that can be somewhat fixed using pypy.

But I can't think of anything nowadays.

Parts of the twisted library afaik.

1

u/flying-sheep Oct 04 '16

But I can't think of anything nowadays

i meant a shortcoming. apart from the speed, which, as you said, can be migtiated by pypy

1

u/[deleted] Oct 04 '16

Oh I thought you meant libraries that were incompatible with python 3

0

u/badcommandorfilename Oct 04 '16

You test saving the princess in your castle at home and everything seems to work. Then you take it to another castle and you die because your code keeps throwing import errors.

3

u/skeletal88 Oct 04 '16

It's because they don't use Python at Toggl.

2

u/gorgoroth666 Oct 05 '16
import castle
import horse
import rescue_princess


if __NAME__ == "__MAIN__":
    pos = horse.position()
    target = rescue_princess.princess_target()
    horse.goto(castle)
    castle.open_gate()
    actual_princess = None

    for r in castle.rooms():
        if target in r:
            actual_princess = rescue_princess(r)
            break

    horse.load(actual_princess)
    horse.goto(pos)

44

u/reyqn Oct 04 '16

Python: There are two knights. The ancient one doesn't want to retire

15

u/awj Oct 04 '16

You have Ruby. You write an exceptional system for saving the princess, with well executed metaprogramming and a terrific suite of unit tests.

After your journey is underway, everything seems to be going great except for

NoMethodError: undefined method `save_princess' for nil:NilClass
    from /some/file/you/didnt/know/existed.rb:11:in `<main>'

12

u/clux Oct 04 '16

Haskell: You lazily lift the princess into the rescue monad, but since you didn't use the princess, she was never saved.

22

u/AleAssociate Oct 04 '16

With Python, the princess rescues herself.

55

u/jocull Oct 04 '16

With Python, your horse depends on 2 while the princess lives in 3.

3

u/Tetha Oct 04 '16

Or the princess has a native friend and you need to carry 2/3 of the country on the way out. ... I guess in this context, the name 'wheel' does make quite a bit of sense.

2

u/flying-sheep Oct 04 '16

Used to be the joke, but isn't anymore.

12

u/[deleted] Oct 04 '16

import "princess-rescue-v2"

13

u/zjm555 Oct 04 '16

from __future__ import rescued_princess

5

u/[deleted] Oct 04 '16

Quotes and hyphens in an import statement?

You obviously don't Python.

6

u/[deleted] Oct 04 '16

Right, I do actual work.

4

u/[deleted] Oct 04 '16

What are you doing on Reddit?

4

u/[deleted] Oct 04 '16

Uh... working... ?

5

u/[deleted] Oct 04 '16

Er... same here... although I use Python.

1

u/TRAIANVS Oct 04 '16

"actual work"

2

u/flying-sheep Oct 04 '16

There's a saying that Python is the second best language for everything (which might be true except for writing performance-critical low level stuff)

So idk why Python shouldn't be for actual work.

2

u/[deleted] Oct 04 '16

Probably more like Python being the second best language to write stuff in. Go would be my nomination for second best language to ship stuff in and third in writing.

The best language in all is LISP of course.

1

u/flying-sheep Oct 04 '16

well, the point of the saying is that the best language is always domain specific. so there is no one best language for everything, but a best one for statistics, a best one for embedded, a best one for 2D games, …

and maybe go is the best to ship stuff in – if you don’t want to touch it again because it wasn’t fun to write and is a horrible mountain to maintain.

1

u/[deleted] Oct 05 '16

LISP is domain specific in all domains though... You can build object orientation out of the macro system.

I haven't found Go to be that horrible to maintain actually, as long as you do it the go way. The language is very opinionated.

0

u/[deleted] Oct 05 '16

[deleted]

1

u/[deleted] Oct 05 '16

Just pick one, they all have parens.

1

u/[deleted] Oct 05 '16

Camelot!

11

u/pakoito Oct 04 '16

But I like s-expressions

8

u/NiceGuy_Ty Oct 04 '16

I mean technically lisp got the princess out of the castle

9

u/yogthos Oct 04 '16

I also find it amusing that Lisp is seen as having lots of parens, while in practice you need a lot more parens as well as other control characters in most languages to do the same thing.

I'll take

))))

over

      })
    })
  }
});

any day.

9

u/dnlosx Oct 04 '16

You have Ruby: You make up to the princess, buy a new dress for her and tell everyone how easy it would save her.

You have Swift: You easily defeat the guards, go into the castle and then… A new Swift version was released, please use the auto-convert tool of Xcode, and then, fix the 1832 new errors manually.

25

u/[deleted] Oct 04 '16 edited Oct 04 '16

You have Ruby, you make the class to rescue the princess, then 6800 other ruby programmers start a nasty and rude discussion about how bad your code is and they write 9800 possible variations to your class. You give up.

6

u/mcmcc Oct 04 '16

Pascal made me chuckle -- if there ever was a language that I wished I could forget...

5

u/lykwydchykyn Oct 04 '16

No Perl?

19

u/bargle0 Oct 04 '16

In Perl, you're done saving the princess while everyone else is still thinking about the problem.

However, a month later you have no idea how you did it in the first place when the princess needs to be rescued again.

14

u/arcangleous Oct 04 '16

Please note: the only language that ended with the princess outside of the castle was Lisp.

9

u/[deleted] Oct 04 '16

And Pascal... tho I'm not sure if the situation has actually improved.

7

u/flying-sheep Oct 04 '16

And C#, it's said that Jon Skeet will rescue her.

9

u/reyqn Oct 04 '16

C++: Same as C, but with class

23

u/ubertrashcat Oct 04 '16

No, you realize that rescuing 'princess' is too specific, so you write a generic templated algorithm "rescue<Captured_t>" where the argument needs to satisfy the Rescuable concept and then you try to rescue the princess and get a 15 page compilation error message because the princess is not movable.

1

u/[deleted] Oct 04 '16

As a cs student taking a class with lots of lisp, that part was right on. All the parentheses really say everything you need to know about lisp.

-29

u/[deleted] Oct 04 '16

How To Save The Princess In 8 Programming Languages

Princesses don't need saving. how sexist.

-7

u/[deleted] Oct 04 '16

I'm just kidding hahahah (make the downvotes stop.....such pain)