Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #103918

Re: Continuing indentation

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Carl Meyer <carl@oddbird.net>
Newsgroups comp.lang.python
Subject Re: Continuing indentation
Date Wed, 2 Mar 2016 17:02:02 -0700
Lines 86
Message-ID <mailman.128.1456964447.20602.python-list@python.org> (permalink)
References <mailman.113.1456951421.20602.python-list@python.org> <0b33c10d-4366-49c7-8416-4d4ecd56ac8b@googlegroups.com> <CAPTjJmpTTsKTkV7XZ5tr-FyPFFRPG49Je6qjK-pce1Z7EwHsGw@mail.gmail.com>
Mime-Version 1.0
Content-Type multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="uOQtHCd9iwcvbiqoK0wh54dk515LSOgOI"
X-Trace news.uni-berlin.de FhD7Np+IjK19hJgu6kBX8QELbqQSr49wh80H5mQ4MzyQ==
Return-Path <carl@oddbird.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.037
X-Spam-Evidence '*H*': 0.93; '*S*': 0.00; 'extracted': 0.07; 'wednesday,': 0.07; 'comment,': 0.09; 'thu,': 0.15; '2016': 0.16; 'char)': 0.16; 'filename:fname piece:signature': 0.16; 'from:addr:carl': 0.16; 'readability.': 0.16; 'received:173.255': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'tempted': 0.16; 'wrote:': 0.16; 'skip': 0.18; 'variable': 0.18; '>>>': 0.20; 'am,': 0.23; 'bit': 0.23; 'header:In-Reply-To:1': 0.24; 'header :User-Agent:1': 0.26; 'chris': 0.26; '(e.g.': 0.27; 'function': 0.28; 'forces': 0.29; 'code': 0.30; 'related': 0.32; 'closely': 0.33; 'extract': 0.33; 'wrap': 0.33; 'add': 0.34; 'improving': 0.35; 'law,': 0.35; 'primarily': 0.35; 'comment': 0.35; 'but': 0.36; 'instead': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'received:org': 0.37; 'names': 0.38; 'to:addr:python.org': 0.40; 'your': 0.60; 'charset:windows-1252': 0.62; 'relatively': 0.63; 'more': 0.63; 'march': 0.64; 'mar': 0.65; 'series': 0.65; 'all!': 0.84; 'clarifies': 0.84; 'guideline': 0.84; 'or:': 0.84; '"how': 0.91; 'improvement': 0.93
X-Enigmail-Draft-Status N1110
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1
In-Reply-To <CAPTjJmpTTsKTkV7XZ5tr-FyPFFRPG49Je6qjK-pce1Z7EwHsGw@mail.gmail.com>
X-Spam-Status No (score -1.0): ALL_TRUSTED=-1
X-Spam-Bar -
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:103918

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On 03/02/2016 04:54 PM, Chris Angelico wrote:
> On Thu, Mar 3, 2016 at 10:46 AM,  <codewizard@gmail.com> wrote:
>> On Wednesday, March 2, 2016 at 3:44:07 PM UTC-5, Skip Montanaro wrote:
>>>
>>>     if (some_condition and
>>>         some_other_condition and
>>>         some_final_condition):
>>>         play_bingo()
>>
>> How about:
>>
>>   continue_playing = (
>>       some_condition and
>>       some_other_condition and
>>       some_final_condition
>>   )
>>
>>   if continue_playing:
>>       play_bingo()
>>
>> or:
>>
>>   play_conditions = [
>>       some_condition,
>>       some_other_condition,
>>       some_final_condition,
>>   ]
>>
>>   if all(play_conditions):
>>       play_bingo()
> 
> Those feel like warping your code around the letter of the law,
> without really improving anything.

Not at all! Taking a series of boolean-joined conditions and giving the
combined condition a single name is often a major improvement in
readability. Not primarily for code-layout reasons, but because it
forces you to name the concept (e.g. "continue_playing" here.)

I often find that the best answer to "how do I wrap this long line?" is
"don't, instead extract a piece of it and give that its own name on its
own line(s)." The extracted piece might be a new variable or even a new
function. The pressure to do this type of refactor more frequently is
one reason I continue to prefer relatively short (80 char) line length
limits.

This is closely related to the XP guideline "when you're tempted to add
a comment, instead extract that bit of code into a function or variable
and give it a name that clarifies the same thing the comment would have."

Names are important!

Carl

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Continuing indentation Skip Montanaro <skip.montanaro@gmail.com> - 2016-03-02 14:43 -0600
  Re: Continuing indentation Marko Rauhamaa <marko@pacujo.net> - 2016-03-02 22:50 +0200
    Re: Continuing indentation Ethan Furman <ethan@stoneleaf.us> - 2016-03-02 14:01 -0800
      Re: Continuing indentation Marko Rauhamaa <marko@pacujo.net> - 2016-03-03 00:10 +0200
        Re: Continuing indentation Skip Montanaro <skip.montanaro@gmail.com> - 2016-03-02 16:44 -0600
        Re: Continuing indentation Ethan Furman <ethan@stoneleaf.us> - 2016-03-02 14:51 -0800
        Re: Continuing indentation Ethan Furman <ethan@stoneleaf.us> - 2016-03-02 14:56 -0800
        Re: Continuing indentation Chris Angelico <rosuav@gmail.com> - 2016-03-03 10:46 +1100
        Re: Continuing indentation Steven D'Aprano <steve@pearwood.info> - 2016-03-03 13:15 +1100
        Re: Continuing indentation John Gordon <gordon@panix.com> - 2016-03-03 16:16 +0000
          Re: Continuing indentation Marko Rauhamaa <marko@pacujo.net> - 2016-03-03 18:47 +0200
            Re: Continuing indentation Rob Gaddi <rgaddi@highlandtechnology.invalid> - 2016-03-03 18:06 +0000
              Re: Continuing indentation Marko Rauhamaa <marko@pacujo.net> - 2016-03-03 21:36 +0200
            Re: Continuing indentation Steven D'Aprano <steve@pearwood.info> - 2016-03-04 11:13 +1100
              Re: Continuing indentation INADA Naoki <songofacandy@gmail.com> - 2016-03-04 09:45 +0900
              Re: Continuing indentation Erik <python@lucidity.plus.com> - 2016-03-04 01:06 +0000
              Re: Continuing indentation INADA Naoki <songofacandy@gmail.com> - 2016-03-04 10:23 +0900
                Re: Continuing indentation Steven D'Aprano <steve@pearwood.info> - 2016-03-04 14:48 +1100
                Re: Continuing indentation cl@isbd.net - 2016-03-04 10:12 +0000
                Re: Continuing indentation alister <alister.ware@ntlworld.com> - 2016-03-04 14:03 +0000
                Re: Continuing indentation Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-04 08:25 -0700
                Re: Continuing indentation Ethan Furman <ethan@stoneleaf.us> - 2016-03-04 09:36 -0800
                Re: Continuing indentation sohcahtoa82@gmail.com - 2016-03-04 13:14 -0800
                Re: Continuing indentation Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-04 21:20 +0000
                Re: Continuing indentation Erik <python@lucidity.plus.com> - 2016-03-04 23:31 +0000
                Re: Continuing indentation Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-04 23:45 +0000
                Re: Continuing indentation Ethan Furman <ethan@stoneleaf.us> - 2016-03-04 15:53 -0800
                Re: Continuing indentation Simon Ward <simon+python@bleah.co.uk> - 2016-03-05 00:23 +0000
                Re: Continuing indentation sohcahtoa82@gmail.com - 2016-03-04 17:17 -0800
                Re: Continuing indentation Ethan Furman <ethan@stoneleaf.us> - 2016-03-04 18:14 -0800
                Re: Continuing indentation Ben Finney <ben+python@benfinney.id.au> - 2016-03-05 13:22 +1100
                Re: Continuing indentation Tim Chase <python.list@tim.thechases.com> - 2016-03-04 20:49 -0600
                Re: Continuing indentation srinivas devaki <mr.eightnoteight@gmail.com> - 2016-03-05 10:25 +0530
                Re: Continuing indentation Ben Finney <ben+python@benfinney.id.au> - 2016-03-05 16:10 +1100
                Re: Continuing indentation Erik <python@lucidity.plus.com> - 2016-03-05 00:52 +0000
                Re: Continuing indentation Ben Finney <ben+python@benfinney.id.au> - 2016-03-05 12:05 +1100
                Re: Continuing indentation Erik <python@lucidity.plus.com> - 2016-03-05 01:45 +0000
                Re: Continuing indentation Steven D'Aprano <steve@pearwood.info> - 2016-03-05 18:17 +1100
                Re: Continuing indentation alister <alister.ware@ntlworld.com> - 2016-03-04 13:59 +0000
                Re: Continuing indentation Ben Finney <ben+python@benfinney.id.au> - 2016-03-05 10:41 +1100
                Re: Continuing indentation sohcahtoa82@gmail.com - 2016-03-04 16:06 -0800
                Re: Continuing indentation Ben Finney <ben+python@benfinney.id.au> - 2016-03-05 11:30 +1100
                Re: Continuing indentation Ethan Furman <ethan@stoneleaf.us> - 2016-03-04 17:01 -0800
              Re: Continuing indentation Erik <python@lucidity.plus.com> - 2016-03-04 02:24 +0000
              Re: Continuing indentation Marko Rauhamaa <marko@pacujo.net> - 2016-03-04 08:28 +0200
  Re: Continuing indentation codewizard@gmail.com - 2016-03-02 15:46 -0800
    Re: Continuing indentation Chris Angelico <rosuav@gmail.com> - 2016-03-03 10:54 +1100
      Re: Continuing indentation Pete Forman <petef4+usenet@gmail.com> - 2016-03-03 00:23 +0000
    Re: Continuing indentation Carl Meyer <carl@oddbird.net> - 2016-03-02 17:02 -0700
      Re: Continuing indentation Steven D'Aprano <steve@pearwood.info> - 2016-03-03 13:22 +1100
        Re: Continuing indentation Ben Finney <ben+python@benfinney.id.au> - 2016-03-03 13:30 +1100
        Re: Continuing indentation Chris Angelico <rosuav@gmail.com> - 2016-03-03 13:33 +1100
        Re: Continuing indentation Ethan Furman <ethan@stoneleaf.us> - 2016-03-02 18:57 -0800
    Re: Continuing indentation Ben Finney <ben+python@benfinney.id.au> - 2016-03-03 11:30 +1100
    Re: Continuing indentation cl@isbd.net - 2016-03-03 10:22 +0000

csiph-web