On Thu, 15 Mar 2012 00:34:47 +0100, Kiuhnm wrote: > I've just started to read > The Quick Python Book (2nd ed.) > The author claims that Python code is more readable than Perl code and > provides this example: > > --- Perl --- > sub pairwise_sum { > my($arg1, $arg2) = @_; > my(@result) = (); > @list1 = @$arg1; > @list2 = @$arg2; > for($i=0; $i < length(@list1); $i++) { > push(@result, $list1[$i] + $list2[$i]); > } > return(\@result); > } > > --- Python --- > def pairwise_sum(list1, list2): > result = [] > for i in range(len(list1)): > result.append(list1[i] + list2[i]) > return result > --- --- > > It's quite clear that he knows little about Perl. > Here's what I would've written: > > sub pairwise_sum { > my ($list1, $list2) = @_; > my @result; > push @result, $list1->[$_] + $list2->[$_] for (0..@$list1-1); > \@result; > } > > Having said that, the Python code is still more readable, so there's no > need to misrepresent Perl that way. > Now I'm wondering whether the author will show me "good" or "bad" Python > code throughout the book. Should I keep reading? > > Kiuhnm
I have a simple experience which to me demonstrates python must be fairly readable. I gave a copy of a small utility to a friend of mine, whilst running it he found an obscure case that would cause a crash, he has only limited programming experience of any sort but from the python trace-back he was able to read my code & made a suggestion of what he thought would fix the issue, this suggestion was spot on. -- Necessity is a mother. -- http://mail.python.org/mailman/listinfo/python-list