From: ImpalerCore on
On Feb 24, 7:30 pm, Lorenzo Villari <vll...(a)tiscali.it> wrote:
> On 24 Feb 2010 22:09:43 GMT
>
> sc...(a)slp53.sl.home (Scott Lurndal) wrote:
>
> >    if (condition) {
>
> > is preferred over
>
> >    if (condition)
> >    {
>
> > Makes it much more likely that a properly written function will fit
> > on a single page/screen.
>
> Hmmm...
>
> if (condition) {    <-- one line
>
> if (condition)      <-- one line
> {                   <-- and another one, makes two lines
>
> Does that really make a BIG difference?  
>

The only time it bugs me is when I have a single line of code for an
if and else statement.

if ( condition )
{
// line
}
else
{
// other line
}

I used to use this for a while. But I tried the other convention and
ended up liking it better. Again, this is for my personal stuff; if a
style is already in place in a project, I follow that standard.

I also don't leave out braces though for single lines since I've been
bitten by that in the past.

if ( condition )
// line

I always do this

if ( condition ) {
// line
}

>
> > In 30 years of C programming, no employer or project has used the
> > latter form.
>
> Really? What's so bad about that? I prefer the latter btw...

From: Stefan Monnier on
> Indeed.

> if (condition) {

> is preferred over

> if (condition)
> {

> Makes it much more likely that a properly written function will fit on
> a single page/screen.

> In 30 years of C programming, no employer or project has used the
> latter form.

The standard GNU style (i.e. recommended for GNU projects) is to use

if (condition)
{
blabla
}

so Emacs uses this style. I personnally prefer the single-line form (my
windows never have enough lines), so I hacked up some .emacs thingy that
makes the two-line form display as the one-line form.


Stefan
From: Anand Hariharan on
On Feb 24, 4:09 pm, sc...(a)slp53.sl.home (Scott Lurndal) wrote:
>
>    if (condition) {
>
> is preferred over
>
>    if (condition)
>    {
>
> Makes it much more likely that a properly written function will fit on a single
> page/screen.
>
> In 30 years of C programming, no employer or project has used the latter form.
>
> scott


You've gotten some strong reactions to your not-seen-in-30-years
comment above.

FWIW I use the latter form myself. However, one good reason I got
from an ex-colleague for using the first style was that if you are
scrolling upward in source code, and get to the closing brace of a
block, using the keyboard shortcut in your editor for jumping to the
matching brace will get you to see the if (or while or for)
condition. Otherwise, it will only scroll upward to a point where the
opening brace is shown as the first line, and one has to go up one
line more. To me, this is not a big inconvenience.

- Anand
From: BruceS on
On Feb 24, 2:54 pm, la...(a)ludens.elte.hu (Ersek, Laszlo) wrote:
> In article <7f8b94fc-a78e-4c64-becf-f70a3843d...(a)o3g2000yqb.googlegroups.com>, James Harris <james.harri...(a)googlemail.com> writes:
>
> > On 24 Feb, 20:53, BruceS <bruce...(a)hotmail.com> wrote:
>
> > ...
>
> >> I would like to add that, as long as you're trying to use good style,
> >> for God's sake don't use the wrong indentation style.  If you put your
> >> opening braces on the same line as your conditional, you'll just look
> >> like a fool in front of your friends and colleagues.
>
> > Snobbish nonsense!
>
> I've actually laughed out loud when I've read Bruce's part above; it's
> so blatant that I'm almost completely sure it was meant as irony.
> (Perhaps so is your response, too.)
>
> Cheers,
> lacos

Well *someone* laughed anyway. Yes, this was intended ironically, and
I thought it was so obvious that I didn't put in an emoticon. This is
one of the oldest pointless battles in C. Now it looks like I've
started it again, rather than the intended humor. I would have said
something about the inferiority of little-endianism, but I'm afraid
few people really get that.

Years ago, I had my one and only protest shirt. It said, in big
letters, "STOP PLATE TECTONICS". So many people were confused by it I
almost gave up wearing it. Then one Saturday, a manager at my work
started to walk past me, stopped to double-check what my shirt said,
and walked on laughing heartily.
From: Tom St Denis on
On Feb 24, 7:30 pm, Lorenzo Villari <vll...(a)tiscali.it> wrote:
> On 24 Feb 2010 22:09:43 GMT
>
> sc...(a)slp53.sl.home (Scott Lurndal) wrote:
>
> >    if (condition) {
>
> > is preferred over
>
> >    if (condition)
> >    {
>
> > Makes it much more likely that a properly written function will fit
> > on a single page/screen.
>
> Hmmm...
>
> if (condition) {    <-- one line
>
> if (condition)      <-- one line
> {                   <-- and another one, makes two lines
>
> Does that really make a BIG difference?  
>
>
>
> > In 30 years of C programming, no employer or project has used the
> > latter form.
>
> Really? What's so bad about that? I prefer the latter btw...

The only reason I don't use the two-liner is that it's two lines. If
you write functions with a lot of conditionals (e.g. you're calling
functions that can fail) it adds up really quickly. It's also another
line you have to indent properly [something a lot of people don't do].

There is no technical reason beyond that for favouring either.

Personally I use the one-liner but I'll work on code that uses the
other. If I take ownership of code that uses the two liner I might
switch it back to one-liner but beyond that I'm not that petty :-)

my two cents...

Tom
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Prev: integer
Next: shared memory question