Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.01; 'example:': 0.03; 'one?': 0.05; 'perl,': 0.05; 'subject:Python': 0.05; 'does.': 0.07; 'python': 0.08; 'comparisons': 0.09; 'notation.': 0.09; 'polish': 0.09; 'readable': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'syntax.': 0.09; 'url:manning': 0.09; 'def': 0.13; 'python?': 0.15; '();': 0.16; 'beginners.': 0.16; 'ed.)': 0.16; 'hackers': 0.16; 'idioms': 0.16; 'misrepresent': 0.16; 'perl.': 0.16; 'pushes': 0.16; 'readability.': 0.16; 'teacher,': 0.16; "would've": 0.16; 'syntax': 0.16; 'language': 0.16; 'wrote:': 0.18; 'example.': 0.18; 'perl': 0.18; 'that?': 0.18; 'written': 0.19; 'programming': 0.20; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; '+0100,': 0.23; 'guess': 0.26; 'code.': 0.26; 'code': 0.26; 'function': 0.27; 'code,': 0.28; 'somebody': 0.28; 'compare': 0.28; "i'm": 0.28; 'onto': 0.29; 'problem': 0.29; 'seen,': 0.30; 'sub': 0.30; '(the': 0.30; 'quite': 0.31; '---': 0.31; 'version': 0.32; 'pure': 0.32; 'thu,': 0.32; 'word.': 0.32; "i've": 0.32; 'rest': 0.32; 'that,': 0.32; 'actual': 0.32; 'scientific': 0.32; 'idea': 0.32; 'languages': 0.32; 'there': 0.33; 'header:User-Agent:1': 0.33; 'it.': 0.33; 'instead': 0.33; 'test': 0.34; 'header:X-Complaints- To:1': 0.34; 'from:addr:yahoo.co.uk': 0.34; 'showing': 0.34; 'steven': 0.34; 'wondering': 0.34; 'rather': 0.34; 'especially': 0.34; 'anything': 0.34; 'to:addr:python-list': 0.35; 'received:org': 0.36; 'example,': 0.37; 'comparing': 0.37; 'push': 0.37; 'but': 0.37; 'using': 0.37; 'not,': 0.38; 'enough': 0.38; 'could': 0.38; 'some': 0.38; 'think': 0.38; 'should': 0.38; 'easier': 0.38; 'concepts': 0.39; 'speaking': 0.39; 'point': 0.40; 'missing': 0.40; 'received:78': 0.40; 'put': 0.40; 'might': 0.40; 'to:addr:python.org': 0.40; 'quick': 0.61; 'more': 0.61; 'your': 0.61; 'teach': 0.61; 'link': 0.62; 'life': 0.63; 'making': 0.64; 'here': 0.64; 'overall': 0.66; 'show': 0.66; 'direct': 0.67; 'match,': 0.67; 'gone': 0.68; 'contrary': 0.73; 'doing.': 0.73; 'reverse': 0.73; 'virtually': 0.73; 'claims': 0.80; 'idiomatic': 0.84; 'opposition': 0.84; 'received:as13285.net': 0.84; 'show,': 0.84; 'light.': 0.91; 'sir.': 0.91; 'conclude': 0.95 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: Python is readable Date: Fri, 16 Mar 2012 02:16:34 +0000 References: <4f612b19$0$1379$4fafbaef@reader2.news.tin.it> <4f629d27$0$29981$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-78-147-30-52.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 In-Reply-To: <4f629d27$0$29981$c3e8da3$5496439d@news.astraweb.com> X-Antivirus: avast! (VPS 120315-1, 15/03/2012), Outbound message X-Antivirus-Status: Clean X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 113 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1331864214 news.xs4all.nl 6928 [2001:888:2000:d::a6]:56107 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:21731 On 16/03/2012 01:53, Steven D'Aprano wrote: > On Thu, 15 Mar 2012 00:34:47 +0100, Kiuhnm wrote: > >> I've just started to read >> The Quick Python Book (2nd ed.) > > Is this the one? > > http://manning.com/ceder/ > > >> 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; > > I don't understand the reason for $arg1 and $arg2. Is there some reason > why the code couldn't do this instead? > > my(@list1, @list2) = @_; > > >> 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. > > On the contrary -- it is quite clear that you are missing the point of > the comparison, which is not to compare the most idiomatic Perl with the > most idiomatic Python, but to make a direct comparison of syntax for the > purpose of teaching beginners. > > The problem with idiomatic comparisons is that they often don't give you > a feel for the overall language syntax. Instead they end up comparing > built-ins. For example, here is how I would write the above pairwise > addition using idiomatic RPL, the Forth-like programming language used on > some Hewlett-Packard scientific calculators: > > ADD > > That's it. One word. Would you conclude from this that RPL is easier to > read and write than Python? I can tell you that it is not, and I *like* > stack-based languages that use reverse Polish Notation. > > >> 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. > > Speaking as somebody who doesn't know Perl, I think that your version > would do a great disservice to Perl. Your version is shorter, but > conciseness is often in opposition to readability. Without the author's > version above, and the function name, I would have literally NO IDEA what > your version does. It is virtually pure line-noise. I know enough Perl to > guess that @result might be an array, and so guess that push pushes a > value onto the array, but the rest might as well be written in Martian. > Or APL. > > The author's version above, which you denigrate, is *much* more > understandable than your more idiomatic Perl, especially since I can > compare it feature to feature with the Python code. > > Far from misrepresenting Perl, he has gone out of his way to show Perl in > the best possible light. Idiomatic Perl code, written by experts, is even > more incomprehensible and unreadable to non-Perl hackers than his example. > > >> Now I'm wondering whether the author will show me "good" or "bad" Python >> code throughout the book. Should I keep reading? > >> From what you have show, and the sample chapters on the link above, I am > impressed. The author is aiming to teach basic concepts and impart > *understanding* rather than just force-feed the reader idioms which would > be incomprehensible to them. Vern Cedar (the author) is an actual > professional teacher, and from the samples I have seen, he knows what he > is doing. > > Well put Sir. And (seriously) when making your comments you show the killer instincts of a great bowler in an Ashes Test Match, now could there be anything more important in life or showing greater esteem than that? -- Cheers. Mark Lawrence.