[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [lmi] A matter of style
From: |
Ericksberg, Richard |
Subject: |
RE: [lmi] A matter of style |
Date: |
Thu, 22 Feb 2007 15:15:13 -0500 |
On 2007-02-22 13:00 UTC, Greg Chicares wrote:
> Consider:
>
> if(IsVoid())
> return;
>
> Something like that occurs many times in 'database_view_editor.cpp',
> for example. In the past, I would have asked [1] that we write
>
> if(IsVoid())
> {
> return;
> }
>
> instead, but I'm starting to think that
>
> if(IsVoid())
> {return;}
>
> might be better. Reason: by saving two lines, that alternative
> may make function bodies shorter and therefore easier to read,
> particularly if there are multiple early exits.
>
> It's possible, though probably not very likely, that someone
> will want to add a line to an early exit someday:
>
> if(IsVoid())
> {
> message_box("Hey, this shouldn't be void!");
> return;
> }
>
> If so, the block can easily be split into multiple lines:
> that's not much extra work, and fairly unlikely anyway.
I like this idea but would like to clarify when we should use
one format vs. the other? Right now I'm assuming this one would
be used only when it's 'likely' to just be a single line
[e.g. return, fatal_error() etc.]
if(whatever)
{return;}
and this one otherwise
if(whatever)
{
DoSomething();
MaybeDoSomeOtherStuff();
return;
}
and not
if(whatever)
{DoSomething(); MaybeDoSomeOtherStuff(); return;}
Also, what about this format found in main_wx.cpp?
switch(*i)
{
case '\n': {*j++ = ';';} break;
case '\r': { } break;
case '\t': {*j++ = ' ';} break;
default : {*j++ = *i;}
}
Should we pattern switch/case statements after this
[if small enough?]
---------------------------------------------------------
This e-mail transmission may contain information that is
proprietary, privileged and/or confidential and is
intended exclusively for the person(s) to whom it is
addressed. Any use, copying, retention or disclosure by
any person other than the intended recipient or the
intended recipient's designees is strictly prohibited. If
you are not the intended recipient or their designee,
please notify the sender immediately by return e-mail and
delete all copies.
---------------------------------------------------------