Circa 2002-Mar-02 21:34:35 -0800 dixit Sean 'Shaleh' Perry:

: > You *are* bracket-happy though, you know. ^_^
:
: the else could safely lose the {}.  However I find the else then
: gets lots easily.  It is also my experience that every time i have a
: place where I can get away without braces I end up needing them
: later.  Since I code in python a lot, I find that I forget to add
: them.  So as compensation I just add them by default.

This is merely good coding practice.  Even experienced C programmers
forget to add braces, especially in places such as:

  if (blah)
    haha();
  else
    heehee();
    woohoo(); /* New statement, looks like it's part of 'else', */
              /* but really it's not: it gets executed regardless */
              /* of whether 'blah' is true or false. */

Or:

  for (blah = 0; blah < haha; blah++)
    something();
    something_else();  /* <-- This looks like it's part of a for() */
                       /* loop, but it's not.  It only gets done once, */
                       /* after the loop is finished. */

The indentation is misleading.  If you *really* don't want to use
brackets around a single statement, i recommend this style:

  if (blah) haha();
  if (heehee) woohoo(); else wheee();
  for (a; b; c) something();

so that it's fully clear there's exactly one statement there.

--
jim knoble | [EMAIL PROTECTED]   | http://www.pobox.com/~jmknoble/
(GnuPG fingerprint: 31C4:8AAC:F24E:A70C:4000::BBF4:289F:EAA8:1381:1491)

Attachment: msg05686/pgp00000.pgp
Description: PGP signature

Reply via email to