Python and Ruby

Nobody nobody at
Sun Jan 31 21:14:47 CET 2010

On Sat, 30 Jan 2010 16:58:34 +0000, tanix wrote:

>>I'm not familiar with Ruby, but most languages are cleaner than Python
>>once you get beyond the "10-minute introduction" stage.
> I'd have to agree. The only ones that beat Python in that department are
> Javascript and PHP. Plus CSS and HTML if you can call those languages.
> The very idea of using a number of blanks to identify your block level is
> as insane as it gets.

I don't have a problem with layout (indentation level as a syntax element).

> First of all, combinations of blanks and tabs,
> depending on how your ide is setup to expand tabs, may get you bugs, you'd
> never imagine in your wild dreams.

If you IDE places tab stops other than every 8 columns, it's broken.

Configurable tab stops in a text editor is one of those "features" that
differentiates a "coder" from a software engineer. A coder implements it
because it's easy to implement, without giving a moment's thought to the
wider context (such as: how to communicate the non-standard tab stops to
any other program which needs to read the file).

Even so, it's quite simple to implement layout in a way which doesn't
care about tab widths:

1. If the current line begins with exactly the same sequence of whitespace
characters as the last non-blank line, it's part of the same block.

2. If the sequence of whitespace characters at the beginning of the
current line is an extension of that for the last non-blank line
(i.e. it starts with the previous sequence, then adds some more
whitespace), then it's the first line of a inner block.

3. If the current line begins with a left substring of the sequence for
the last non-blank line, then it belongs to an outer block (whichever one
has that sequence).

4. If none of the above are true, it's a syntax error.

> Braces is the most reliable way to identify blocks.

No they aren't. Indentation is much easier for humans to process than
scanning the file for braces (and not missing any). If you have any
indentation in the code, humans will interpret it as indicating the
nesting, even if the compiler doesn't. E.g.:

	if(x) {

See the problem? The compiler will match the else with if(y), but a human
will tend to match it with if(x).

Layout ensures that a human sees what the compiler "sees".

Given that any sane program uses indentation to reflect the program's
structure, braces (or "begin", or "end" (or endif/endwhile/etc)) are

More information about the Python-list mailing list