[ntp:questions] sntp code: what pack_ntp is doung,

Pg toarunpg at gmail.com
Tue Apr 15 08:29:28 UTC 2008


On Apr 11, 5:45 pm, "Richard B. Gilbert" <rgilber... at comcast.net>
wrote:
> David J Taylor wrote:
> >> Pg wrote:
>
> >>>     for (i = 0; i < 8; ++i) {
> >>>         if ((k = (int)(d *= 256.0)) >= 256) k = 255;
> >>>         packet[NTP_TRANSMIT+i] = k;
> >>>         d -= k;
> >>>     }
> >>> in this what is happening after deviding by NTP_SCALE and what is
> >>> happening inside for loop.
>
> > Shouldn't there be a comment near the code saying what it does?
>
> > David
>
> If I had written it there would be a comment.  But some people believe
> that the code says what it's doing!
>
> It's not easy to wrap your mind around 70,000 (give or take a few
> thousand) lines of code!  It's less easy when the code is not well
> commented.
>
> Perhaps it's obvious to "old hands" what is being done and, especially,
> why.  People looking at the code for the first time might perhaps figure
> out that the order of two bytes is being reversed but probably would
> have more difficulty understanding why.  It costs only a few seconds to
> type "/* Put it in network byte order. */" and it saves far more of the
> reader's time than it costs the writer!  It also makes the code easier
> to maintain.
>
> "A program is not just a set of instructions to be executed by a
> computer; it is also a document that must be understood by human beings!"- Hide quoted text -
>
> - Show quoted text -

thanks to all,
arun




More information about the questions mailing list