[Hampshire] Code style

Top Page
Author: Hugo Mills
Date:  
To: Hants LUG
Subject: [Hampshire] Code style

Reply to this message
gpg: failed to create temporary file '/var/lib/lurker/.#lk0x57a77100.hantslug.org.uk.1168': Permission denied
gpg: keyblock resource '/var/lib/lurker/pubring.gpg': Permission denied
gpg: Signature made Sun Jun 7 20:01:47 2009 BST
gpg: using DSA key 20ACB3BE515C238D
gpg: Can't check signature: No public key
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



Assume that the fast path is a single expression, and the slow path
is at least tens of lines of code. Why would you pick one style over
the other? Would you use a different idiom in different languages? If
so, why?

Discuss. :)

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."