groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: pic anomalies


From: Ralph Corderoy
Subject: Re: pic anomalies
Date: Mon, 30 Dec 2019 18:31:34 +0000

Hi Ingo,

>  * line 1896, while (*form):
>    Testing char as if it were boolean seems dubious style to me;
>    "while (*form != '\0')" would seem clearer because it makes the
>    data type obvious on first sight.

It's idiomatic in C to write just `foo' to test it against its `zero
value' whether it's an int, pointer, etc.

Comparing to '\0' to hint that *form is a char of some sign is
duplicating form's declaration information, and they can drift.
Sometimes the suggestion the hint is required is a sign of a bad name,
but in this case do_sprintf() fits on the screen so form's context is
always apparent.

If I've a `bool b', I don't write `b != false' to hint that b is a bool.
Or `b != false != false'.  :-)  Our brains have to verbalise what we
read and with good names it often reads more fluently and fluidly not to
have to spell out the comparison.  Just as we don't bother verbalising
`open brace', and dislike languages that clutter with `begin...end', so
`if (len != 0)' seems overkill to me, and I'm glad the language's
designers went for the simple rendering.

Getting back on topic, are we sure we want to deviate from GNU pic's
current behaviour without checking historical norms of other pics?

    $ printf '%s\n' \
        .PS 'print sprintf("%.17g %.0f% % %%", 3.14, 42, 99)' .PE |
    > pic >/dev/null
    3.1400000000000001 42% % %%

Though that may seem odd to our modern C-standardised eyes, it's
understandable in that if it isn't a valid %f, etc., format specifier
then it's a literal percent sign.

That example also happens to show GNU pic gives no warning of unused
arguments.

-- 
Cheers, Ralph.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]