Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 23 Feb 2001 19:34:42 +0100
From:      Rahul Siddharthan <rsidd@physics.iisc.ernet.in>
To:        j mckitrick <jcm@FreeBSD-uk.eu.org>
Cc:        freebsd-chat@FreeBSD.ORG
Subject:   Re: bad programming practice?
Message-ID:  <20010223193442.A23185@lpt.ens.fr>
In-Reply-To: <20010223180321.A33329@dogma.freebsd-uk.eu.org>; from jcm@FreeBSD-uk.eu.org on Fri, Feb 23, 2001 at 06:03:33PM %2B0000
References:  <20010223180321.A33329@dogma.freebsd-uk.eu.org>

next in thread | previous in thread | raw e-mail | index | archive | help
j mckitrick said on Feb 23, 2001 at 18:03:33:
> 
> I recently posted an example showing a simple C rule my company uses that
> eliminates a simple error.
> 
> if(var == CONST)
> 
> can generate a bug if you forget an equals sign.
> 
> But using
> 
> if(CONST == var)
> 
> will create an error if you forget an equals sign.
> 
> Obviously, this is just a trick to prevent a sloppy coding error, but why is
> it so disdained?  What is wrong with using such tricks to make our job
> easier?

In this particular case -- convention?  It just seems more ``natural''
to me to say if (var==CONST) rather than if (CONST==var).  (Perhaps
because it's more in line with regular math usage -- when writing
something in English I'll always write "if n is 1" and never "if 1 is
n": the latter just sounds weird, what can 1 be other than 1?)  That
in turn makes the code (and the English text) more readable -- one
such occurrence is ok, just makes you stop a bit while reading, but
many such strange usages will just annoy the reader.  And anyway, as
someone pointed out earlier, most compilers will warn you if you
forget an = (you may need a compiler flag like -Wall).

Any other examples of such tricks, where perhaps compiler warnings
won't help?

-Rahul.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-chat" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010223193442.A23185>