Main Contents

The Good, the Bad and the Ugly

Development, Python | Comments (1)

I’m sure you have watched the spaghetti Western by Sergio Leone. For those of you who haven’t, its about 3 guys going after a treasure in the Wild West. The Good is of course played by Clint Eastwood, the Bad is Lee Van Cleef, and the Ugly bandito is played by Eli Wallach. Tarantino calls it “the best-directed film of all time”, so if you haven’t seen it, just go watch it.

Anyway, this post is not about discussing legendary movies. It is about development, and about 3 programming languages in particular - Python, PHP and Perl. It just so happens that the title of the movie is one of the shortest, and most accurate descriptions of these 3 languages ;p. Let me tell you why.

The Oogly

The Ugly: [trying to read a note] “See you soon, id…” “id…” “ids…”
The Good
: [taking the note] “Idiots. It’s for you. “

You guessed it - this is Perl. One of the popular answers to the question “Why should I learn Python instead of Perl?” is “Because it is spelled correctly.”

The prevalent opinion is that Perl is way uglier than Python, as hard as the Perl devs try to refute it. Fact is, Perl is full of “syntax poison”. That is, it uses a lot of non-alphabetical system characters (like $, @, _, etc). This makes it harder to read, and comprehend. Check this out:

map{($_[0])?s/ss+/,/gs:$_;($?)?push(@M,$_):$_;(/wap:/)?$?=$$:$_;}split($/,`cat file`);

This line does not look very friendly, does it? Tons of special symbols, and almost no text. Admittedly, it performs quite a lot of operations, and as far as one-liners go, it is quite powerful. In Python, I would probably spread this to 5-10 lines.

Perl developers tend to stack multiple operations on the same line, in order to achieve smaller line count.  Such coding is IMO inspired by the language itself. Shorter does not mean better. If you don’t believe me go ask your wife :)

Don’t get me wrong, it is not impossible to write readable, and well-structured code in Perl. It simply requires much more  experience and discipline, which most developers lack.

The Bad

The Bad: You’re smart enough to know that talking won’t save you.

In case you didn’t know it, PHP is an acronym for Personal Home Page. This is how the language started - as a simple way to embed small snippets of code into your HTML pages.  This is also the usual way people start to use PHP - for example, by adding a small piece of PHP code showing the current date on the web page.  Then, step-by-step, with a lot of copy/pasting from different sources, lots of trial-and-error, and with just a little understanding of what actually happens, people learn some “cool tricks”, and after a while become full-time PHP developers. This process is fundamentally wrong. 

What makes it even more wrong in my opinion, is the way PHP is embedded in HTML. The correct approach to web development is to separate the programing code from the presentation (e.g. the HTML documents). This is the way to make your program “skinable”, easy to maintain and update. Additionally, while debugging a coding problem, you don’t have to plow through thousands of lines of HTML code, and vice versa.

Another PHP “flaw” is that it is very dependent on the server side setup. Dozens of PHP options are configured on the server side, and changing these may change the behavior of your PHP application. Some of these options can be effectively changed from within your PHP code, but others cannot. In the end, you get a PHP application, which works only if certain server-side configuration is present. What’s more, most PHP developers don’t give a flying duck about unorthodox PHP configurations. Having multiple PHP configuration options just add another layer of incompatibility and confusion.

The lack of formal introduction to PHP, the way it is plugged into HTML, and the multiple configuration options, which are usually disregarded, lead to an amazingly high rate of security vulnerabilities. It is hard to say whether the language is at fault, because it makes it so easy to leave security holes open, or the developers are to be blamed, because they are not careful/knowledgeable enough to avoid the security pitfalls. It is certain that PHP is nowadays regarded as the most insecure web technology.

The Good

The Good: Put your drawers on, and take your gun off.

Python is my favorite, but you should have guessed this by now :) What makes it the Good guy in our story?

Python is very easy to read, write and maintain. Not surprisingly, prototypes of larger applications are written in Python as proof of concept. Python is almost self-documenting (you can embed docstrings in each module/object/method), and allows you to easily create automated tests for each piece of code you write (using unittest for example). Of course you can document and test all your code in PHP and Perl as well, but Python makes it *easy* for you to do it, hence Python developers are more inclined to document their code, and write automated tests.

When people try Python for the first time, they are usually quite baffled by Python’s indentation - the way it marks different programing blocks. Instead of using special symbols (like {}) , or reserved words (like ‘begin’/'end’), Python marks the different blocks by different amount of whitespace on the left (indentation). Although this is quite strange, there is some reason behind the indentation. First, the code is not polluted by unreadable characters, or by unnecessary begin/end statements - the block markers in Python are transparent. Second, indentation of blocks forces at least a basic level of coding style. Both effects improve the readability of the code - as a result, Python code is pretty by design.

Before you dismiss all this as pure fanboyism (for more fanboyism, check this), I will admit that there are some things I don’t like about Python. For example, I don’t like the direction the web development under Python is heading to, the lack of control over the .pyc files, and some other minor issues. These will be the subject of some other rant however, as there is a lot to discuss.

The End

This is by no means serious review of the 3 languages. I have only picked up the traits which fit the title of our story. These 3 languages differ in many ways, and this post is just a scratch on the (quite controversial) surface.

tie @ June 4, 2007

First public release of Script Wizard

Script Wizard | Comments (0)

The first publicly available Script Wizard version is now a fact. In case you missed it, Script Wizard is a tool allowing you to easily install various scripts on your website. If you have ever heard of Fantastico, or Elephante, then you will know what I am talking about.
As you might expect, there are some differences between […]

tie @ May 21, 2007

Hullo world! Hmm, it’s not responding…

All Around | Comments (0)

The world lacks manners. For all the times I have seen ‘Hello world’ printed out, I haven’t seen the world replying back even once. It’s quite impolite, isn’t it?
Even without a reply, people keep throwing Hello-s at the world. This is another one. Welcome to my blog, where I will post my thoughts about ScriptWizard, Python, development, […]

tie @ May 17, 2007


RSSFeed