Fun easter egg in Python and PHP
A little-known easter egg in Python gives some useful coding mantras of good practice in Python programming:
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.
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!
Find these messages with python -c “import this” at the command line.
A little known fact is that PHP has similar easter egg – just enter this in a new .php file, and run it:
echo “Brackets are better than beautiful \n”;
echo “Implicit odd behavior is to be expected – CONSTNT is a string, right? oops, misspelled. \n”;
echo “Simple is better than multithreaded – you didn’t need that time speedup… \n”;
echo “Simple is better than complex numbers… which are not part of standard library either. \n”;
echo “Flat is better than nested namespaces – so functions are not globals, no os.path…[tab][tab]…\n”;
echo “Sparse is better than too many libraries, for computer vision, GUI development, numpy etc.\n”;
echo “Readability counts… twice as many lines as equivalent Python unfortunately 🙁 \n”;
echo “Special cases are TrUe enough to be not FaLsE!\n”;
echo “So you can have True with a capital T\n”;
echo “Errors must often not bug the developer who is busy debugging the symptoms.\n”;
echo “And if errors keep happening just add @function =0 🙁 \n”;
echo “In the face of ambiguity, make a good guess or even a bad one, probably better than fatal err?? https://github.com/phpmd/phpmd/issues/262\n”;
echo “There must be TWO, or preferrably THREE or more functions, to do the exact same thing\n”;
echo “Though it may not be obvious the similarity unless you remember like an Elephant\n”;
echo “time() is better than never.”;
Just write this to “this.php” and php -a, then “require ‘this.php’;” 🙂
Seriously though, although many dislike PHP, it is the language of WordPress and various other popular tools, and often useful for quick web setups. One often overlooked problem is that the documentations don’t list security warnings as Python docs do – I would recommend this PHP security reading if you use PHP on a regular basis.
Posted in News
Comments are currently closed.