Hi Marty,
I agree that un-braced one-line if or else blocks may be a problem when changing them to more than one line. Even more when this happens invivibly when doThis() is a macro that expands to multiple statements ( and is not wrapped with do { ... } while(0) ).
I only wanted to express that I am a bit agnostic about these one liners.
However, I prefer them without braces when they are a single return, break, continue, or goto statement.
Anyway, I will not touch braces for now because of the git blame thing. But it would be nice to have an agreement on a preference for future code.
Dirk
-----Ursprüngliche Nachricht-----
Von: Core-talk <core-talk-bounces at aps.anl.gov> Im Auftrag von Marty Kraimer via Core-talk
Gesendet: Donnerstag, 16. April 2020 13:17
An: core-talk at aps.anl.gov
Betreff: Re: [Merge] ~dirk.zimoch/epics-base:CleanupWhitespace into epics-base:7.0
In Dirk's message the following appears:
> if (i<10)
> doThis(i);
> else
> {
I have seen this cause problems when
doThis(i);
is changed from a single statement to multiple statements.
Better is
if (i<10) {
doThis(i);
} else {
...
}
Marty
On 4/16/20 3:42 AM, Dirk Zimoch via Core-talk wrote:
> What is your favorite coding style, mine looks like this:
>
> int function(int a, int b)
> {
> int i;
>
> for (i=a; i<b; i++)
> {
> if (i<10)
> doThis(i);
> else
> {
> switch (i)
> {
> case 42:
> doSomethingSpecial();
> break;
> default:
> {
> doTheNormalThing(i, a, b);
> break;
> }
> }
> }
> }
> return 0;
> }
- References:
- Re: [Merge] ~dirk.zimoch/epics-base:CleanupWhitespace into epics-base:7.0 Dirk Zimoch via Core-talk
- Re: [Merge] ~dirk.zimoch/epics-base:CleanupWhitespace into epics-base:7.0 Marty Kraimer via Core-talk
- Navigate by Date:
- Prev:
Build failed: EPICS Base base-7.0-586 AppVeyor via Core-talk
- Next:
[Merge] ~dirk.zimoch/epics-base:CleanupWhitespace into epics-base:7.0 Dirk Zimoch via Core-talk
- Index:
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
<2020>
2021
2022
2023
2024
- Navigate by Thread:
- Prev:
Re: [Merge] ~dirk.zimoch/epics-base:CleanupWhitespace into epics-base:7.0 Marty Kraimer via Core-talk
- Next:
Re: [Merge] ~dirk.zimoch/epics-base:CleanupWhitespace into epics-base:7.0 Ralph Lange via Core-talk
- Index:
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
<2020>
2021
2022
2023
2024
|