Re: [Hampshire] Code style

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

Reply to this message
gpg: failed to create temporary file '/var/lib/lurker/.#lk0x57492100.hantslug.org.uk.12658': Permission denied
gpg: keyblock resource '/var/lib/lurker/pubring.gpg': Permission denied
gpg: Signature made Mon Jun 8 12:20:08 2009 BST
gpg: using DSA key 20ACB3BE515C238D
gpg: Can't check signature: No public key
On Mon, Jun 08, 2009 at 11:45:29AM +0100, Victor Churchill wrote:
> On Hugo's second question, well yes different languages have different
> capabilities.
>
> So in perl one could boil the whole thing down to
> my $result = ($fast_path_applicable?) $fast_path() : $slow_path() ;
> return $result;


However, use of the ternary operator is almost always a big mistake
in my opinion. It's pretty much unreadable, unless all three operands
are trivial and atomic, and even then an if statement is frequently
preferable.

I happily thought that the ternary operator had been put to death
in Python, until I saw this little gem in some code yesterday:

(is_forward and "F" or "B")

The perpetrator has been given a good talking-to. :)

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 lost my leg in 1942.  Some bastard stole it in a ---       
                            pub in Pimlico."