Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: David Palao Newsgroups: comp.lang.python Subject: Re: Guido sees the light: PEP 8 updated Date: Mon, 18 Apr 2016 13:35:42 +0200 Lines: 108 Message-ID: References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <8ff10001-1c49-4490-b873-018507243ea3@googlegroups.com> <04721fe6-5feb-49c8-b5b2-beb12f6ff495@googlegroups.com> <5714522d$0$1622$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de O9WAmBSj/naS5udte+FVKgdVEfAz3+3rmqNgIrYwz68g== 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; 'lines,': 0.05; 'badly': 0.07; 'expressions': 0.07; 'lines.': 0.07; 'subject:PEP': 0.07; 'width': 0.07; 'cc:addr:python-list': 0.09; '"my': 0.09; 'created,': 0.09; 'exceptions,': 0.09; 'indication': 0.09; 'lengths': 0.09; 'likewise': 0.09; 'tends': 0.09; 'read.': 0.13; 'def': 0.13; '(but': 0.15; 'variables': 0.15; '2016': 0.16; 'cases)': 0.16; 'columns': 0.16; 'elsewhere.': 0.16; 'excellent!': 0.16; 'func():': 0.16; 'losing': 0.16; 'perhaps:': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'resist': 0.16; 'routinely': 0.16; 'skip:g 50': 0.16; 'to:addr:pearwood.info': 0.16; "to:name:steven d'aprano": 0.16; 'verbose': 0.16; 'wrote:': 0.16; 'instance,': 0.18; 'tells': 0.18; 'try:': 0.18; 'variable': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'saying': 0.22; 'text,': 0.22; 'am,': 0.23; 'code,': 0.23; 'code.': 0.23; 'fit': 0.23; '(or': 0.23; '(you': 0.23; 'errors': 0.23; 'unlike': 0.23; 'somewhere': 0.24; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; "i've": 0.25; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'fine': 0.28; '(it': 0.29; '120': 0.29; 'indentation': 0.29; 'themselves': 0.29; 'allows': 0.30; 'too.': 0.30; 'url:mailman': 0.30; 'creating': 0.30; 'code': 0.30; 'becomes': 0.30; 'certainly': 0.30; 'programmers': 0.30; 'strongly': 0.30; 'extend': 0.31; 'another': 0.32; 'especially': 0.32; 'problem': 0.33; 'url:python': 0.33; "d'aprano": 0.33; 'errors,': 0.33; 'rule': 0.33; 'shorter': 0.33; 'steven': 0.33; 'though.': 0.33; 'url:listinfo': 0.34; 'languages': 0.34; 'received:google.com': 0.35; 'returning': 0.35; 'problem.': 0.35; 'sometimes': 0.35; 'but': 0.36; 'too': 0.36; 'should': 0.36; 'there': 0.36; 'url:org': 0.36; 'lines': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'agree': 0.37; 'beyond': 0.37; 'doing': 0.38; 'received:209': 0.38; 'names': 0.38; 'thank': 0.38; 'end': 0.39; 'subject:the': 0.39; 'takes': 0.39; 'url:mail': 0.40; 'still': 0.40; 'chance': 0.60; 'your': 0.60; 'close': 0.61; 'maximum': 0.61; 'avoid': 0.61; 'entire': 0.61; 'eye': 0.61; 'further': 0.62; 'total': 0.62; 'back': 0.62; 'per': 0.62; 'yes': 0.62; '(that': 0.63; 'more': 0.63; 'hear': 0.64; 'our': 0.64; 'here': 0.66; 'eyes': 0.70; 'levels': 0.70; 'eight': 0.72; 'further,': 0.72; 'physical': 0.72; 'increase': 0.73; 'increasing': 0.76; '100': 0.79; '(also,': 0.84; 'characters.)': 0.84; 'complexity': 0.84; 'western': 0.89; 'afford': 0.91; 'urge': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=c3xdIfmMauTl5ZZneXZpjhXW1093yJrJ+Vjt+zveods=; b=kuSYsXsrZCs/ZLPqOabnQbkMiPxtvpkgCCAP2caFtFNgUPcWRHJ+XHQ7jXJJ/iynXj Ee5PdnZIZ/grVIHb2GEX7B2f/ZVn5DNKme58pwm66e7h0AfuAfzEBkf5DAfmVniCM5Xm VzlSwZqwfzlTsfzg2mtiHYtWWpssIoETExE8QFGvY8Q8XQe0CbAZrynprxt15AIWTOIG XJGW1GWKGsqjaOd2WyQ5yCul73R+nQEI+gNG48ZKKKlR0c1GFSGyvD1hLs4HUx/LNWDP ghPXIsWT+/2uesK8rDUGzW9aoFPMmHi3bNIPKKza6UcGKaGcIYsXDSDLsmejfIgLpyVV J7HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=c3xdIfmMauTl5ZZneXZpjhXW1093yJrJ+Vjt+zveods=; b=NGLmZJEoWRVF5Ch/U5pSwsG9FAwciAGloSktR7uWQ9hMX9P0kG8Otk5FHOXlkjrYKt QW87d2vAqYsYM5KJQ8i3i9Sh7Tl+iRgqyBZCypSQkmi78Zf2G38/RoHYdPCc259yHil6 BPvRqs5r25ii7uz9HpdQcVPVZ7JTplGJ164hL7CFQgQfoMmPQMaUuIy5NzNRKinkCGmt gjpiEIxABjqUgIwm6gi8f1mnUPpfwsOFjhUc+k3VsBbktIVQiuPPXPDsPaKjuYWvR+i0 Y0gV37+TCTDyqgKRvuRmXOktXyDkceTT0TwCj7PhY0pZU5S4d6bfoOXKHQ98l/l5uymk Wa+A== X-Gm-Message-State: AOPr4FXncKWMOpyJjFaP/Zcj5yB4dzu7qXu65G4yzR/ccFi0uU9a7U2lYu9BfMDWOZ4y4wFNHRwhwM0EhYhWQg== X-Received: by 10.140.225.199 with SMTP id v190mr36760470qhb.4.1460979342551; Mon, 18 Apr 2016 04:35:42 -0700 (PDT) In-Reply-To: <5714522d$0$1622$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <5711c1b3$0$1596$c3e8da3$5496439d@news.astraweb.com> <87shym6kpo.fsf@elektro.pacujo.net> <87h9f26ioa.fsf@elektro.pacujo.net> <1460809922.1918014.580580553.0AE05EE4@webmail.messagingengine.com> <878u0d7az5.fsf@elektro.pacujo.net> <8ff10001-1c49-4490-b873-018507243ea3@googlegroups.com> <04721fe6-5feb-49c8-b5b2-beb12f6ff495@googlegroups.com> <5714522d$0$1622$c3e8da3$5496439d@news.astraweb.com> Xref: csiph.com comp.lang.python:107267 2016-04-18 5:19 GMT+02:00 Steven D'Aprano : > On Mon, 18 Apr 2016 11:39 am, Rustom Mody wrote: > >> yes we can agree on this -- arbitrary line lengths are almost certainly >> unreadable. >> The problem then becomes so what is optimal? > > I really don't think it is a problem. We have about 400 years > of experience with printed text, and that experience tells us > that the optimal width for reading prose in Western languages > is about 60 characters, give or take. This width is optimal > for eye movement, and minimizes the number of errors and > reduces eye-strain. > > There's only so far that our eyes can follow a line to the > right without increasing stress or reading errors, and > likewise when returning back to the left margin. The longer > the line, the higher the chance of losing track, and the > physical effort it takes to read. (You have to move the eyes > further, and for extremely long lines, you may have to move > your entire head.) > > Long lines are simply harder to read because you have to > move your eyes more, and the longer the lines, the greater > the tendency to wander across the lines. Especially if the > lines are close together and the height of the lines is > small. (It boggles my mind how many programmers I've met who > routinely view their code in tiny physical heights, even > when reading it in fine detail.) > > The optimal width for eye-tracking (that is, the maximum > width for which the rate of such errors can be disregarded) > is somewhere about sixty characters per line. > > The same eye-tracking considerations apply to code, but: > > when it comes to code, we don't always have to track all the > way back to the left-hand margin. If we start (say) up to > twenty columns in, then we can afford to write up to twenty > columns further to the right too. > > > (Also, code tends to have VERY ragged right-hand margins. > Not all lines end up even close to sixty characters wide.) > > There are other considerations though. Unlike prose, with > code, shorter lines *may* sometimes force an increase in > complexity. For instance, temporary variables need to be > created, or new functions created, just to avoid otherwise > excessively long lines. So one might be willing to accept a > little more eye-movement for a little less code complexity. > > So allowing a total width of 80 (give or take) is already a > compromise from the optimal sixty characters. This compromise > allows for indented code, and allows up to 20 characters > extra to avoid creating more complexity elsewhere. > > > But there's another factor: long lines of code are themselves > a code-smell. Perhaps: > > - you have indented too deeply, suggesting that your function > is doing too much or has too much internal complexity: > > def func(): > if a: > for b in seq: > while c: > with d: > try: > try: > for e in it: > block # only 48 columns available here > > (But note also that even with this extreme example, eight > indentation levels deep, you can still fit almost > characters per line without breaking the 80-char limit. > You can do a lot in 50 characters.) > > > - you have too many expressions on one line, suggesting that > the over-all complexity of the line is excessive; > > - your variable or function names are needlessly verbose or > are doing too much or are too specific > ("calculate_number_of_pages_and_number_of_semicolons_in_chapter_one"); > > - or you are violating the rule of Demeter: > get(customer.trousers.pocket.wallet).open().money.pay(1) > > > In other words, long lines of code are themselves an > indication of poorly-designed code. Even though there are > exceptions, we should resist strongly the urge to extend > beyond the 60-80 (or perhaps 90 in extreme cases) limit. > Whenever I hear people saying that they regularly need to > use 100 or even 120 columns for their code, what I hear is > "my code is badly written". > > > > -- > Steven > > -- > https://mail.python.org/mailman/listinfo/python-list Excellent! Thank you for this contribution.