[tz] coding style for tzcode?

Christos Zoulas christos at zoulas.com
Sat Oct 4 20:43:13 UTC 2014


On Oct 4,  1:35pm, eggert at cs.ucla.edu (Paul Eggert) wrote:
-- Subject: Re: [tz] coding style for tzcode?

| Christos Zoulas wrote:
| > This indentation is clearly wrong
| 
| Yes, that indentation-by-16 went off the rails.  We should probably fix that the 
| next time we happen to be changing the neighborhood.
| 
| > I don't any discussion about changing the coding style anywhere.
| 
| I've tried to avoid making global style changes even when I thought they would 
| improve the code.  Part of this is to avoid unwanted differences (diff -bw does 
| not suffice, unfortunately), and part is out of respect to the previous 
| maintainer, who has a distinct style that I'm loath to discard everywhere merely 
| because it has problems somewhere or because it grates on me.  For my own 
| changes, though, I haven't hesitated to use a slightly different style that I 
| think works better; this is not recent practice, as I recall doing that even 
| with code I contributed many years ago.

It would have been good to have had a heads up for that. Now I am torn
on what to do. Follow a consistent style when I import and have to deal
with even more change to the base source, or give up? I doubt it that
the long term solution is to have mixed style indentation. As for the long
staircases, in most cases they can be avoided and you don't have to go
to 2 space indents for that; for example:

static struct state *
zoneinit(struct state *sp, char const *name)
{ 
  if (sp) { 
    if (name && ! name[0]) {
      /*
      ** User wants it fast rather than right.
      */
      sp->leapcnt = 0;          /* so, we're off a little */
      sp->timecnt = 0;
      sp->typecnt = 0;
      sp->ttis[0].tt_isdst = 0;
      sp->ttis[0].tt_gmtoff = 0;
      sp->ttis[0].tt_abbrind = 0;
      strcpy(sp->chars, gmt);
    } else if (! (tzload(name, sp, true)
                  || (name && name[0] != ':' && tzparse(name, sp, false))))
      return NULL;
  }
  return sp;
}                       

Can be written as:

static struct state *
zoneinit(struct state *sp, char const *name)
{ 
	if (! sp) 
		return NULL;

	if (name && ! name[0]) {
		/*
		** User wants it fast rather than right.
		*/
		sp->leapcnt = 0;          /* so, we're off a little */
		sp->timecnt = 0;
		sp->typecnt = 0;
		sp->ttis[0].tt_isdst = 0;
		sp->ttis[0].tt_gmtoff = 0;
		sp->ttis[0].tt_abbrind = 0;
		strcpy(sp->chars, gmt);
		return sp;
	}

	if (! (tzload(name, sp, true)
	    || (name && name[0] != ':' && tzparse(name, sp, false))))
		return NULL;

	return sp;
}                       

christos



More information about the tz mailing list