"Python for readers"

Submitted by albert on Tue, 25/12/2012 - 17:24 (2012-12-25T17:24:05+01:00)

Some time ago I read something like the following:

"Code is primarily meant to be read and understood. Otherwise, we would all be writing in assembler".

In the languages I work most often with - COBOL and Python - there is a strong emphasis on readability (although especially in the former case a lot of production code violates that principle). Also it's a well-known phenomenon that

"Code is more often read than it is written"

From this point of view, I would like to try to write a tutorial based on how we read the code, instead of on how we write it. That'll follow along the way, I'm sure.

Let's start with a few notes on how we obtain code. Because if we need to be able to read code, we need to know how it's stored. If we couldn't store code, we'd have to rewrite it every time we wanted to re-execute it and wouldn't that be a bore (not to mention error-prone and inefficient)?

The basic unit of stored code is what we call a module. It corresponds to a file on our computer - because that's how computers store things.

Modules that belong together can be organized into a package - which is basically an extension of the file system organisation to make importing related stuff somewhat easier. Like directories and files, packages and modules can be organized into higher-order units - also called packages.

Enough on that for now. Let's go to the code itself.

As with any language, what we are reading is a collection of sentences that are related to each other, a story. In a programming language that story is basically a series of instructions to the computer. But since the computer only reads numbers, the instructions are really some kind of translation that enables the programmer to understand what he's telling the computer to do.

Different computer languages have different ways of achieving those translations, and put different demands on what should be put into them. A preliminary with Python is that the code is intended to be easily readable. When it comes to language decisions, it's a criterion that is generally favoured above other criteria and it's why there are so many familiar elements in a Python "story".

Trefwoorden: Python, programming