[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [gpsd-dev] gpsd style change?
From: |
Eric S. Raymond |
Subject: |
Re: [gpsd-dev] gpsd style change? |
Date: |
Tue, 10 Feb 2015 23:44:28 -0500 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
Gary E. Miller <address@hidden>:
> Yo All!
>
> A lot of changes like this in recent git commit:
> 5b4af8cc002773058ad744f9c2f9975284b09224
>
> diff --git a/monitor_ubx.c b/monitor_ubx.c
> index 8b4101e..f73a06b 100644
> --- a/monitor_ubx.c
> +++ b/monitor_ubx.c
> @@ -260,13 +260,13 @@ static void ubx_update(void)
> if (pps_thread_lastpps(&session, &drift) > 0) {
> /* NOTE: can not use double here due to precision requirements */
> struct timespec timedelta;
> - char buf2[22];
> TS_SUB( &timedelta, &drift.clock, &drift.real);
> if ( 86400 < (long)labs(timedelta.tv_sec) ) {
> /* more than one day off, overflow */
> /* need a bigger field to show it */
> (void)mvwprintw(ppswin, 1, 13, "> 1 day");
> } else {
> + char buf2[22];
> (void)timespec_str( &timedelta, buf2, sizeof(buf2) );
> (void)mvwprintw(ppswin, 1, 13, "%s", buf2);
> }
>
> This is actually my preferred style of coding: to keep local variables
> as local as possible.
>
> But, when I have done this in the past, following commits have hoisted
> the variable declarations to the top of the function.
That's odd. I always move them as close to usage as possible, both
because I share your preference and because cppcheck throws warnings
if the scope of a variable can be reduced.
> Is this now an official style change? I would prefer it that way. If
> so can it be made official somewhere so things don't move back and
> forth.
We don't have an official style guide, but I am 100% behind giving
variables scopes as narrow as possible. Go with your instinct on this.
> Or, bigger picture, maybe a real style guide?
Be careful what you wish for. If we had one, some of your coding
quirks might be agin' it. My eyeballs stumble whenever I see that
"if (0 == foo)" thing you like to do...
--
<a href="http://www.catb.org/~esr/">Eric S. Raymond</a>
- [gpsd-dev] gpsd style change?, Gary E. Miller, 2015/02/10
- Re: [gpsd-dev] gpsd style change?,
Eric S. Raymond <=
- Re: [gpsd-dev] gpsd style change?, Greg Troxel, 2015/02/11
- Re: [gpsd-dev] gpsd style change?, Eric S. Raymond, 2015/02/11
- Re: [gpsd-dev] gpsd style change?, Greg Troxel, 2015/02/11
- Re: [gpsd-dev] gpsd style change?, Eric S. Raymond, 2015/02/11
- Re: [gpsd-dev] gpsd style change?, Greg Troxel, 2015/02/11
- Re: [gpsd-dev] gpsd style change?, Gary E. Miller, 2015/02/11
- Re: [gpsd-dev] gpsd style change?, Eric S. Raymond, 2015/02/11