On Sun, Jun 07, 2009 at 08:16:34PM +0100, The Holy ettlz wrote:
> On Sun, 2009-06-07 at 20:01 +0100, Hugo Mills wrote:
> > If you were writing a function with a fast path and a slow path,
> > which style would you use to write the function?
> > 
> > 
> > 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...)

   Hugo.

-- 
=== Hugo Mills: h...@... 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."               

Attachment: signature.asc
Description: Digital signature

-- 
Please post to: Hampshire@mailman.lug.org.uk
Web Interface: https://mailman.lug.org.uk/mailman/listinfo/hampshire
LUG URL: http://www.hantslug.org.uk
--------------------------------------------------------------

Reply via email to