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

Richard B. Gilbert rgilbert88 at comcast.net
Fri Apr 11 12:45:08 UTC 2008


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!"




More information about the questions mailing list