Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'cache': 0.04; 'executing': 0.05; 'method,': 0.07; 'conditional': 0.09; 'return,': 0.09; 'sun,': 0.09; 'pm,': 0.11; 'this:': 0.11; 'wrote:': 0.14; '\xa0def': 0.16; 'code': 0.22; 'header:In-Reply-To:1': 0.22; 'gregory': 0.23; 'received:209.85.214.174': 0.23; 'received:mail- iw0-f174.google.com': 0.23; '\xa0if': 0.23; 'subject: -- ': 0.25; 'chris': 0.27; 'message-id:@mail.gmail.com': 0.28; "doesn't": 0.28; 'looks': 0.28; 'string': 0.29; '17,': 0.31; 'ewing': 0.31; 'to:addr:python-list': 0.32; 'difference': 0.35; 'received:209.85': 0.37; 'apr': 0.38; 'received:google.com': 0.38; 'received:209.85.214': 0.39; 'returning': 0.39; 'to:addr:python.org': 0.39; 'received:209': 0.39; 'except': 0.39; 'header:Received:5': 0.40; '2011': 0.62; 'here': 0.65 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=k4SHMh6oQX2C0jyAC5jEMAnpQZyFgvV7Mzm5K9I+dy0=; b=nQQ+Kyd13iXUPty7UmsI55AEJhTOmSWOEMj762rvS9QkPTepUOtO50a+BNztZyyqbf NtA/6vXT9naqi2RaFymESnn6vOemVrxizVfRj8eMVU9Bb7YBScljotq9u4yxw36QFV4R Q0rnt2PWDdga5DkKS28NQGIbhOXRhwnFIzdps= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=saGqZl9r/1droPqnXxr7cPD4pcKTTo1/yoWhTIy8fmiGS47BqP+aPGjQ53yudgSqqj 9A6uHuLfc41HAhKzdUXd57DszZox8OQJDr07wc/LwSK1I4nD4bQOY6C8wYjC295wxFVT CcYSuRVMIvrDUBsNA328Tae2k5bRW7qccviRc= MIME-Version: 1.0 In-Reply-To: <90v871FkuaU1@mid.individual.net> References: <8abff237-5ccd-4eb6-85c8-cdc9e87520b7@bl1g2000vbb.googlegroups.com> <90v871FkuaU1@mid.individual.net> Date: Sun, 17 Apr 2011 14:31:06 +1000 Subject: Re: Feature suggestion -- return if true From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 19 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1303014670 news.xs4all.nl 41114 [::ffff:82.94.164.166]:49979 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:3371 On Sun, Apr 17, 2011 at 2:21 PM, Gregory Ewing wrote: > My idiom for fetching from a cache looks like this: > > =A0def get_from_cache(x): > =A0 =A0y =3D cache.get(x) > =A0 =A0if not y: > =A0 =A0 =A0y =3D compute_from(x) > =A0 =A0 =A0cache[x] =3D y > =A0 =A0return y > > which doesn't require any conditional returns. There's not a lot of difference between conditionally returning and conditionally executing all the code between here and the return, except that when you string three conditional returns together by your method, it gets three indentations. Chris Angelico