[Israel.pm] Number of Indentation Levels in Ruby and Perl

Mikhael Goikhman migo at homemail.com
Mon Jun 1 03:02:41 PDT 2009


On 30 May 2009 22:43:26 +0300, Omer Zak wrote:
> 
> Shlomi Fish observed that Ruby scripts use much more indentation levels

Did I miss the "much more indentation levels" part? How was it observed?
Solely based on a number of spaces used in someone's coding style? :-)

Let's attempt to analyze a bit.

Python actually kind of forces a programmer to use as less indentation
levels as possible (i.e. to define a named function for every small
thing, even such that in other languages, that allow it, would be done by
inline unnamed function). The design choice - absence of closing block
mark - causes all kinds of problems related to visibility, ability to
have certain syntax constructs and error-proneness, especially when we
start to speak about levels 6+. So it is just easier to avoid these
problems in Python by minimizing the number of levels in the code.

But I would think that at least Ruby and Perl are quite comparable
regarding the number of levels.

However Perl has a designed ability not to add the first indentation
level per file. Even Perl 6 leaves this nice feature. Although I saw a
Java-like code in Perl 6 with initial "class {" causing the whole file
code to be on +1 level. Still, it is probably more perlish to use the
"class;" syntax that does not start the block.

So I would say that in large Perl projects there is one less level on
average than in Ruby or Java. But I can't say that the difference is
factor of 2.

Regards,
Mikhael.

-- 
perl -e 'print+chr(64+hex)for+split//,d9b815c07f9b8d1e'


More information about the Perl mailing list