Re: [Hampshire] Code style

Top Page
Author: Hugo Mills
Date:  
To: Hampshire LUG Discussion List
Subject: Re: [Hampshire] Code style

Reply to this message
gpg: failed to create temporary file '/var/lib/lurker/.#lk0x57e66100.hantslug.org.uk.1985': Permission denied
gpg: keyblock resource '/var/lib/lurker/pubring.gpg': Permission denied
gpg: Signature made Sun Jun 7 20:33:59 2009 BST
gpg: using DSA key 20ACB3BE515C238D
gpg: Can't check signature: No public key
On Sun, Jun 07, 2009 at 08:30:23PM +0100, The Holy ettlz wrote:
> > > > Style A:
> > > >
> > > > if can_use_fast_path:
> > > >     return "fast path result"
> > > > # do slow stuff
> > > > return "slow path result"

> > > >
> > > >
> > > > Style B:
> > > >
> > > > result = "fast path result"
> > > > if !can_use_fast_path:
> > > >     # do slow stuff
> > > >     result = "slow path result"
> > > > return result

> > >
> > > How expensive is evaluating can_use_fast_path?
> >
> >    Does it matter? It's got to be evaluated in either route. Assume
> > that it's cheap compared to the cost of the slow path (otherwise it's
> > not worth doing the test, of course...)

>
> Hmm. I'd choose Style A since with Style B there's a chance I'd have to
> discard one result and evaluate three things. Unless there's some
> parallel funny-stuff... what's the probability of can_use_fast_path?


*shrug* Who knows?

This is entirely hypothetical. The question came to mind while I
was looking at some code someone else had written, in Style B, where I
usually use Style A.

Hugo.

-- 
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
  PGP key: 515C238D from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
    --- "I will not be pushed,  filed, stamped, indexed, briefed, ---    
               debriefed or numbered.  My life is my own."