Re: strcpy warning
From: Arthur J. O'Dwyer (ajo_at_nospam.andrew.cmu.edu)
Date: 01/03/04
- Next message: Christopher Benson-Manica: "Re: print out a file?"
- Previous message: Peter Pichler: "Re: hash table"
- In reply to: Keith Thompson: "Re: strcpy warning"
- Next in thread: Keith Thompson: "Re: strcpy warning"
- Reply: Keith Thompson: "Re: strcpy warning"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 2 Jan 2004 18:24:55 -0500 (EST)
On Fri, 2 Jan 2004, Keith Thompson wrote:
>
> "Arthur J. O'Dwyer" <ajo@nospam.andrew.cmu.edu> writes:
> [...]
> > if (foo) {
> > int bar;
> > baz();
> > }
> > else
> > quux();
> > [I also make a rule of 2-space indentation for the bodies of
> > control statements without enclosing braces, like 'quux' above
> > -- but that's not a widespread usage, AFAIK.]
>
> I *always* use braces on control statements, except in rare cases
> where the whole thing is short enough to fit on one line. It's a
> habit I picked up from Perl, which requires the braces, but I find it
> useful [...]
> else {
> quux();
> }
>
> I'm not arguing that everyone must do this, it's just the style I like
> to use.
I completely agree with you as far as the example I chose -- in a
real program, I would almost always put braces around the body of
an 'else' clause, especially in cases where the matching 'if' clause
had them. But I often write things like
int foo(void)
{
FILE *fp = fopen("bar", "r");
if (fp == NULL)
return -1;
...
In that case I find it more convenient *not* to add braces; and
if I'm not going to add braces, I find it more consistent *not* to
indent the body a full level. That way, whenever I'm maintaining
my own style of code, I can tell instantly if a closing brace is
missing: e.g., if I see
}
}
or
}
}
then I immediately *know* that there's a problem. Of course,
being able to rely on this "gimmick" in my own code means that I
have a harder time with other people's code than I might if I just
wrote awfully-formatted code to begin with. ;-)
> In rare cases I might compress the layout to something like this:
>
> if (foo) do_foo_stuff();
> elsif (bar) do_bar_stuff();
^^^^^
Assuming, of course, that you were programming in CPerl. :)
> but I often regret it later when I'm maintaining the code (which I
> spend a lot more time on than writing it in the first place).
Yes; I used to do this, but then realized that it was going to
take up a lot of space on the page no matter how I indented it,
so I might as well be consistent.
-Arthur
- Next message: Christopher Benson-Manica: "Re: print out a file?"
- Previous message: Peter Pichler: "Re: hash table"
- In reply to: Keith Thompson: "Re: strcpy warning"
- Next in thread: Keith Thompson: "Re: strcpy warning"
- Reply: Keith Thompson: "Re: strcpy warning"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|