USEFUL perl SCRIPT: NTP verifier - Networking

This is a discussion on USEFUL perl SCRIPT: NTP verifier - Networking ; Jim Gibson wrote: > In article , Gary L. > Burnore wrote: >> > #print "$server delay=$roundtrip_delay, >> > offset=$local_clock_offset, delta=$delta, >> > duration=$duration\n"; print sprintf( "%-30s %.5f\n", $server, >> ... frankly, missing spaces >> between = symbols is most ...

+ Reply to Thread
Page 2 of 2 FirstFirst 1 2
Results 21 to 24 of 24

Thread: USEFUL perl SCRIPT: NTP verifier

  1. Re: USEFUL perl SCRIPT: NTP verifier

    Jim Gibson wrote:

    > In article , Gary L.
    > Burnore wrote:


    >> > #print "$server delay=$roundtrip_delay,
    >> > offset=$local_clock_offset, delta=$delta,
    >> > duration=$duration\n"; print sprintf( "%-30s %.5f\n", $server,


    >> ... frankly, missing spaces
    >> between = symbols is most annoying.

    >
    > There are spaces around each '=' in every assignment statement. The
    > only '=' without surrounding spaces are in print statements, which
    > appear to be debug statements. I do the same thing in my code --
    > snuggle up the preceding and succeeding characters in a print
    > statement -- to see if there is any whitespace in the variables I am
    > printing. Readability of the output is not the issue; it is done for
    > accuracy of results.


    I use either [] (mostly for debugging) or ''. Both have the added
    advantage that one can see a spurious newline, e.g.

    duration = [10
    ]

    In this case, where numbers are printed, I would use extra spaces but
    neither [] nor ''.

    anyway, as always YMMV :-)

    --
    John

    http://johnbokma.com/mexit/

  2. Re: USEFUL perl SCRIPT: NTP verifier

    On 15 Jan 2008 00:06:16 GMT, John Bokma wrote:

    >Jim Gibson wrote:
    >
    >> In article , Gary L.
    >> Burnore wrote:

    >
    >>> > #print "$server delay=$roundtrip_delay,
    >>> > offset=$local_clock_offset, delta=$delta,
    >>> > duration=$duration\n"; print sprintf( "%-30s %.5f\n", $server,

    >
    >>> ... frankly, missing spaces
    >>> between = symbols is most annoying.

    >>
    >> There are spaces around each '=' in every assignment statement. The
    >> only '=' without surrounding spaces are in print statements, which
    >> appear to be debug statements. I do the same thing in my code --
    >> snuggle up the preceding and succeeding characters in a print
    >> statement -- to see if there is any whitespace in the variables I am
    >> printing. Readability of the output is not the issue; it is done for
    >> accuracy of results.

    >
    >I use either [] (mostly for debugging) or ''. Both have the added
    >advantage that one can see a spurious newline, e.g.
    >
    >duration = [10
    >]


    Agreed. Brackets or pipes work nicely as they're "usually" not in the
    code.

    he's using = and ,. Guess that works.

    >In this case, where numbers are printed, I would use extra spaces but
    >neither [] nor ''.
    >
    >anyway, as always YMMV :-)

    --
    gburnore at DataBasix dot Com
    ---------------------------------------------------------------------------
    How you look depends on where you go.
    ---------------------------------------------------------------------------
    Gary L. Burnore | ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
    | ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
    Official .sig, Accept no substitutes. | ۳ݳ޳ݳۺݳ޳ݳݳ޳ݳ۳
    | 0 1 7 2 3 / ݳ 3 7 4 9 3 0 ۳
    Black Helicopter Repair Services, Ltd.| Official Proof of Purchase
    ================================================== =========================

  3. Re: USEFUL perl SCRIPT: NTP verifier

    On 2008-01-14, Jim Gibson wrote:
    > There are spaces around each '=' in every assignment statement. The
    > only '=' without surrounding spaces are in print statements, which
    > appear to be debug statements. I do the same thing in my code --
    > snuggle up the preceding and succeeding characters in a print statement
    > Readability of the output is not the issue; it is done for accuracy of
    > results.
    >


    I also do it for ease of computer parsing. Name=value pairs are very
    easy top parse correctly.

    i

  4. Re: USEFUL perl SCRIPT: NTP verifier

    ["Followup-To:" header set to comp.lang.perl.misc.]
    On 2008-01-14 18:10, John Bokma wrote:
    > Ignoramus5390 wrote:
    >> On 2008-01-14, John Bokma wrote:
    >>> undef is the default value, I wouldn't assign it explicitly.

    >>
    >> I like this style. Makes it very explicit.

    >
    > IMO Perl programmers should know that the default is undef, and hence no
    > need to assign undef.


    Explicitely assigning undef does tell the reader something, though:
    It means that from this point on the variable *needs* to have this value
    - it isn't just undef because nobody assigned anything to it yet, it is
    undef because the programmer wants it to be undef.


    >>> Also, I recommend to support at least -h / --help.

    >>
    >> Is there some standard way of doing it?

    >
    > Perl Best Practices (recommended) recommends:
    >
    > --usage - one line
    > --help - --usage line followed by one-line
    > summary of each option (in my experience
    > the one-line is to strict)
    > --version
    > --man - complete documentation of the program


    The Pod::Usage module makes implementing that very simple.


    >>> If you need to explain what IDs mean it clearly shows that the names
    >>> of your variables are not chosen well.

    >>
    >> They come from NTP specification.

    >
    > OK, clear. That's something you've read to write this, but someone who
    > reads your program does not always have to be familiar with this
    > documentation, nor has to read it first IMO.


    The whole comment is copied verbatim from the specs. That's something I
    do, too.


    > my $roundtrip_delay = ($T4 - $T1) - ($T2 - $T3);
    >
    > v.s.
    >
    > my $roundtrip_delay = ( $destination_ts - $originate_ts )
    > - ( $receive_ts - $transmit_ts );
    >
    > which is more readable?


    The first, by far. $T1 to $T4 form a logical sequence. It is completely
    clear what they are. I have no idea what the second version means:
    Originated by whom? Received and transmitted by whom? And why is
    "destination" a noun when all others are verbs? Does that mean something
    special?

    (Oh, and BTW, the formula is wrong: It must be

    my $roundtrip_delay = ($T4 - $T1) - ($T2 - $T2);

    RFC 2030 contains the same error - its corrected in 4330)

    hp


+ Reply to Thread
Page 2 of 2 FirstFirst 1 2