El Zen de Python i el mestre Yoda.

Confesso que el Python m’agrada molt. L’he fet servir en posts del bloc més d’un cop i m’ho vaig passar molt bé al curs de Python de Coursera. repetixo, m’agrada molt.

Doncs bé, fa molt temps vaig llegir una història curta, es tractava d’una escena de la pel·lícula “L’imperi contraataca” però amb els textos canviats. Luke Skywalker carrega amb Yoda a l’esquena tot entrenant-se però no en els camis de la força, si no en els camins de la programació.

EL Python és el llenguatge dels jedis, i el Perl, dels siths. El diàleg es genial.

Voltant per la web de Pyhton he trobat la historia a l’apartat Python humor, on també s’hi poden trobar d’altres històries i bromes sobre Python.

Pel seu interès, reprodueixo un parell de texts: el primer, “el Zen de Python” de Tim Peters, Val a dir que aquest es pot llegir a qualsevol interpret de python, només cal fer import this. És un ou de pasqua. O potser no. Doncs, en veritat us dic, que paraules poderoses són aquestes.

albert@athena:~$ python
Python 2.7.3 (default, Jan  2 2013, 13:56:14) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
>>> 

I el segon text, és “Python vs. Perl, segons Yoda”

Subject: Python versus Perl: A humorous look
From: larry (funkster@midwinter.com)
Date: 10 Jul 1999 01:45:07 -0700

This has been percolating in the back of my mind for a while.
It's a scene from _The Empire Strikes Back_ reinterpreted to serve
a valuable moral lesson for aspiring programmers.

--

EXTERIOR: DAGOBAH -- DAY
           With Yoda strapped to his back, Luke climbs up one of
        the many thick vines that grow in the swamp until he
        reaches the Dagobah statistics lab. Panting heavily, he
        continues his exercises -- grepping, installing new
        packages, logging in as root, and writing replacements for
        two-year-old shell scripts in Python.

YODA: Code!  Yes.  A programmer's strength flows from code
      maintainability.  But beware of Perl.  Terse syntax... more
      than one way to do it...  default variables.  The dark side
      of code maintainability are they.  Easily they flow, quick
      to join you when code you write.  If once you start down the
      dark path, forever will it dominate your destiny, consume
      you it will.

LUKE: Is Perl better than Python?

YODA: No... no... no.  Quicker, easier, more seductive.

LUKE: But how will I know why Python is better than Perl?

YODA: You will know.  When your code you try to read six months
      from now.

May the force be with you!