Re: Silly question
Re: Silly question
- Subject: Re: Silly question
- From: "Craig S. Cottingham" <email@hidden>
- Date: Fri, 21 Dec 2001 08:30:49 -0600
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Friday, December 21, 2001, at 07:55 , Ondra Cada wrote:
I think it's a matter of personal preferences.
I agree for the most part, though I think it's a balance between
personal preference and readability. A friend of mine, when
first switching from Pascal to C years ago, would put "#define
BEGIN {" and "#define END }" at the top of his source files, so
his blocks would look more like Pascal. That was obviously a
personal preference, but I wouldn't recommend it. :-)
I don't like unnecessary
parentheses; I also found that
if (a && b || c && d) command;
is for me _much_ more readable (and thus easily and more safely
maintainable) than the equivalent others here seem to prefer:
if ((a && b) || (c && d))
{
command;
}
A long time ago, I adopted simplified rules of operator
precedence (from Steve Oualline's "C Elements of Style"?):
1. Multiplication and division come before addition and subtraction.
2. Put parentheses around everything else.
To use your example as, well, an example, when I first look at
the conditional, I don't instantly know if it will be evaluated
as
( (a && b) || (c && d) )
or
( ( (a && b) || c) && d)
I could memorize the precedence tables, I suppose, or look them
up every time, but it's so much easier and clearer (for me) to
be explicit with parentheses.
- --
Craig S. Cottingham
email@hidden
PGP key available from:
<
http://pgp.ai.mit.edu:11371/pks/lookup?op=get&search=0xA2FFBE41>
ID=0xA2FFBE41, fingerprint=6AA8 2E28 2404 8A95 B8FC 7EFC 136F
0CEF A2FF BE41
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (Darwin)
Comment: For info see
http://www.gnupg.org
iD8DBQE8I0efE28M76L/vkERAgnpAJ48N4jRYbRwNYQlte45PgdY0MqsmACfeE9+
JpCtZ/J1xMmORdCxiT71BbY=
=Ac7r
-----END PGP SIGNATURE-----