[Israel.pm] Number of Indentation Levels in Ruby and Perl
migo at homemail.com
Tue Jun 2 03:39:23 PDT 2009
On 01 Jun 2009 23:51:00 +0300, Shlomi Fish wrote:
> On Monday 01 June 2009 23:19:05 Shmuel Fomberg wrote:
> > and if Rudy style encourage large blocks of code in this
> > iterator, then the whole code will shift right significantly.
> I would write it as
> some.chained.call.each do |item|
> [Indent]Something with item.
> With one indentation level inside the loop. I never align code to the
> |item| like that.
As do I.
> And yet, I still tend to run out of indentation.
I suppose you mean that you end up with longer lines in Ruby compared to
your average Perl code. You wrote in your initial messages that you were
not sure that this is because of increased indentation levels. Then the
reason may possibly be something different, say more verbose language
constructs or longer identifiers. Or maybe it is just psychological.
I will try to explain why I think it may be the case.
Based on my not-too-rich experience with Ruby code, I don't see much
difference in the number of levels, but as I said, often you need to work
on +1 level compared to the Perl code that may or may not be less
confortable for someone.
Long lines by themselves should not pose a problem if you may manage them
effectively. I feel that Perl is the best, compared to Ruby and Python
(but has no advantage over C or Java), since you may divide your code in
lines more flexibly for improved visibility, while still keeping the code
integrity and structure. Consider long lines with "+" expression or
postfix "if" or other not less interesting cases. In Ruby and Python you
are relatively limited, you can't just decide to break a line before or
after "+", this will not work in general case, but you may restore the
flexibility by adding trailing backslash. In Ruby you may do it without
backslash with any added indentation, but the Ruby's sloppyness regarding
mandatory end-of-statement mark ";" still makes it not free, you can't
start continuation lines with "+" (it will be taken as unary) and so on.
So some programmers (especially with roots in C) may feel much less
comfortable working with long lines in these two languages.
Do you feel you would write the same code in Perl using shorter lines?
Or using much less indentation levels? It is your code, so only you may
answer these questions. :)
Did you get an answer from Ruby programmers?
perl -e 'print+chr(64+hex)for+split//,d9b815c07f9b8d1e'
More information about the Perl