From: Tim Hammerquist Date: 2002-09-01T23:18:26+09:00 Subject: Re: Ruby aesthetics Gavin Sinclair graced us by uttering: > "Tim Hammerquist" wrote: > > But this is also the greatest way in which Python has > > contributed to the modern coding community. For example, > > I've never, ever, ever seen a Python function definition like > > this. > > > > def foo(arg1, arg2) > > do_stuff() > > do_some_more_stuff() > > while some_condition: > > do_some_conditional_stuff() > > for var in some_list: > > do_more_stuff_with(arg1) > > > > ....I wish I could say the same for Perl. ;) > > Since Perl has braces-as-syntax instead of > invisible-undetectable-because-its-not-there-whitespace-as-syntax, > you can get vim/emacs/whatever to reindent Perl for you. > > Of course, you never need to reindent Python code, except for > when: > - you want to change the indent level from 8 to 3, e.g. Vim: block in VISUAL mode and use < or > keys works for me. > - you cut and paste some code into a loop Vim: with a sufficiently detailed indent spec, Vim's specialized put routines should help, namely ']p' and ']P'. Also see :help i_CTRL-R and related commands. > My objection may not play out much in practice (I'd never > practice it because of the explicit self parameter!), but it is > a very strong (and stubborn) philosophical objection for me. We've all got some. You're among friends. :) > I'll conclude with one (new) feature from Python that makes me > green with envy: list comprehensions. For those who don't know > what that means, here's an example: > > Ruby: squares_less_than_10 = numbers.find_all{|i| i<10}.map{|i| i^2} > > Python: squares_less_than_10 = [x^2 for x in numbers if x < 10] > > Don't get me wrong, I love Ruby's powerful array-manipulation > capabilities. But list comprehensions are soooo cooool! I think this illustrates one of several instances where Pythonistas recognized how difficult Python made it to do something many other languages took for granted. This nice little shortcut was added, but I also agree that list comprehensions are very not-Pythonesque. And I have no problem with Ruby's solutions. They tend to be more consistent, in any case. ;) Tim Hammerquist -- A successful [software] tool is one that was used to do something undreamed of by its author. -- S. C. Johnson