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


Groups > comp.lang.python > #25930

Re: Basic question about speed/coding style/memory

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <dihedral88888@googlemail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'exception': 0.03; '21,': 0.07; 'caller': 0.07; 'means,': 0.07; 'subject:question': 0.08; 'notation': 0.09; 'path.': 0.09; 'processing,': 0.09; 'skip:# 30': 0.09; 'terminates': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'itself.': 0.11; 'passing': 0.15; 'sat,': 0.15; 'bit.': 0.16; 'block:': 0.16; 'callee': 0.16; 'doing,': 0.16; 'dwarfed': 0.16; "function's": 0.16; 'readability.': 0.16; 'subject:coding': 0.16; 'usage,': 0.16; 'wrote:': 0.17; 'jan': 0.18; 'memory': 0.18; 'parameters': 0.20; 'option.': 0.22; 'work,': 0.22; 'cc:2**0': 0.23; '&gt;': 0.23; 'raise': 0.24; 'cc:no real name:2**0': 0.24; 'second': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'checking': 0.27; 'handling': 0.27; 'execution': 0.27; 'functions.': 0.27; 'options': 0.27; 'rest': 0.28; 'subject:/': 0.28; 'chris': 0.28; 'indentation': 0.29; 'style.': 0.29; 'that.': 0.30; 'function': 0.30; 'error': 0.30; 'code': 0.31; 'raising': 0.33; 'skip:d 20': 0.34; 'received:google.com': 0.34; 'from:addr:googlemail.com': 0.35; 'doing': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'level.': 0.36; 'skip:p 20': 0.36; 'keeps': 0.37; 'does': 0.37; 'two': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'little': 0.39; 'think': 0.40; 'your': 0.60; 'most': 0.61; 'matter': 0.61; 'between': 0.63; 'here': 0.65; 'jul': 0.65; 'unnecessary': 0.65; 'conditions,': 0.84; 'idiot': 0.84; 'significance': 0.84; 'subject:Basic': 0.84
Newsgroups comp.lang.python
Date Mon, 23 Jul 2012 14:48:37 -0700 (PDT)
In-Reply-To <mailman.2370.1342861455.4697.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=123.192.83.145; posting-account=5JdMBQoAAABHnS4mjpqEzxnmWtgiiVNw
References <500A5B47.1060805@freenet.de> <mailman.2370.1342861455.4697.python-list@python.org>
User-Agent G2/1.0
X-Google-Web-Client true
X-Google-IP 123.192.83.145
MIME-Version 1.0
Subject Re: Basic question about speed/coding style/memory
From 88888 Dihedral <dihedral88888@googlemail.com>
To comp.lang.python@googlegroups.com
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Message-ID <mailman.2505.1343080119.4697.python-list@python.org> (permalink)
Lines 65
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1343080119 news.xs4all.nl 6901 [2001:888:2000:d::a6]:33779
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:25930

Show key headers only | View raw


Chris Angelico於 2012年7月21日星期六UTC+8下午5時04分12秒寫道:
> On Sat, Jul 21, 2012 at 5:33 PM, Jan Riechers &lt;janpeterr@freenet.de&gt; wrote:
> &gt; Block
> &gt; #----------------------------------
> &gt; if statemente_true:
> &gt;         doSomething()
> &gt; else:
> &gt;         doSomethingElseInstead()
> &gt;
> &gt; #----------------------------------
> 
> This means, to me, that the two options are peers - you do this or you do that.
> 
> &gt; versus this block:
> &gt; #----------------------------------
> &gt; if statement_true:
> &gt;         doSomething()
> &gt;         return
> &gt;
> &gt; doSomethingElseInstead()
> &gt;
> &gt; #----------------------------------
> 
> This would be for an early abort. Don&#39;t bother doing most of this
> function&#39;s work, just doSomething. Might be an error condition, or
> perhaps an optimized path.
> 
> Definitely for error conditions, I would use the second option. The
> &quot;fail and bail&quot; notation keeps the entire error handling in one place:
> 
> def func(x,y,z):
>   if x&lt;0:
>     y+=5
>     return
>   if y&lt;0:
>     raise PEBKAC(&quot;There&#39;s an idiot here somewhere&quot;)
>   # ... do the rest of the work
> 
This is the caller responsible style when passing parameters to 
functions.


Checking types of parameters both in the caller and the callee 
does slow down a little bit.



> Note the similarity between the control structures. Raising an
> exception immediately terminates processing, without polluting the
> rest of the function with an unnecessary indentation level. Early
> aborting through normal function return can do the same thing.
> 
> But this is purely a matter of style. I don&#39;t think there&#39;s any
> significance in terms of processing time or memory usage, and even if
> there is, it would be dwarfed by considerations of readability. Make
> your code look like what it&#39;s doing, and let the execution take care
> of itself.
> 
> ChrisA

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


Thread

Re: Basic question about speed/coding style/memory Chris Angelico <rosuav@gmail.com> - 2012-07-21 19:04 +1000
  Re: Basic question about speed/coding style/memory 88888 Dihedral <dihedral88888@googlemail.com> - 2012-07-23 14:48 -0700
  Re: Basic question about speed/coding style/memory 88888 Dihedral <dihedral88888@googlemail.com> - 2012-07-23 14:48 -0700

csiph-web