Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Carl Meyer Newsgroups: comp.lang.python Subject: Re: Continuing indentation Date: Wed, 2 Mar 2016 17:02:02 -0700 Lines: 86 Message-ID: References: <0b33c10d-4366-49c7-8416-4d4ecd56ac8b@googlegroups.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: 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: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:103918 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --uOQtHCd9iwcvbiqoK0wh54dk515LSOgOI Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable On 03/02/2016 04:54 PM, Chris Angelico wrote: > On Thu, Mar 3, 2016 at 10:46 AM, 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 =3D ( >> some_condition and >> some_other_condition and >> some_final_condition >> ) >> >> if continue_playing: >> play_bingo() >> >> or: >> >> play_conditions =3D [ >> some_condition, >> some_other_condition, >> some_final_condition, >> ] >> >> if all(play_conditions): >> play_bingo() >=20 > 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 --uOQtHCd9iwcvbiqoK0wh54dk515LSOgOI Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAEBCAAGBQJW1379AAoJEC0ft5FqUuEhrt0P/RPZZ2VkUwl5smly4VYvgyeu CySb4ViGGKIrnTyxwF5kc8syotIXRexB8cbMxrzyVAs6WFGkEpAOhXhwLQM/T7gf +aA3cllZEzpJRLhLCU6+FTRBp3rqHmaEQ90/x9PnDjgmX55b3uFNOd/XA3txX+B2 mAHdFz445vwwd2ISN5VWqBWpg2c5LilIxJ9DCBvgR7m6fqimnYZTT+LHOGONE5Bz ffLQHbr5y7WMdhfoYC2dg78W85/gSctq20JQJ5g/7YDKxt8JFCh9/NpE2ord1cmh 0qka+1OFU7kGtyq3zIPPMg3xzY9BzjR1dxt0gBWf4hQ5Ts8pA+cIcY/iyv8BNWUE pDCbSjnO6RNlGhRhyvWuVsEKHe16qUoyDuwgDZreTH40Xez4moGFReQmUkbZfgwM LnCDsFXmU6LSRUhwxzBWO+oyZ7E9z9aXfjHNRCRdb+Kana65bQ9/WbrH35krtwmo AOLLR0+YY1+71/mX3AGvItfwXJucRlZi8AwnDm0PRylHk7LBgXoTj58h/yUGGuLC RUn9ltsymuN5rwpRufA0f66noTufU2sSk0j/050EA53q4syycVWfKTsWxHYCBWUq fl1fLQ19/vJ/kO3ahOltUa0aaSZYeaw6qF37oaBwR/J+JaMRJUqmqnhLNjwHl9iL bZF+qTOuvPR4cspFLN4K =eZp3 -----END PGP SIGNATURE----- --uOQtHCd9iwcvbiqoK0wh54dk515LSOgOI--