Source-Changes-D archive

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

Re: CVS commit: src/external/historical/nawk/bin



Am 04.07.2022 um 13:14 schrieb Valery Ushakov:
On Mon, Jul 04, 2022 at 08:04:57 +0200, Roland Illig wrote:

04.07.2022 01:54:16 Valery Ushakov <uwe%stderr.spb.ru@localhost>:
On Mon, Jul 04, 2022 at 00:07:23 +0200, Roland Illig wrote:

Am 03.07.2022 um 21:55 schrieb Valery Ushakov:
On Sun, Jul 03, 2022 at 10:56:22 +0000, Roland Illig wrote:

Module Name:    src
Committed By:   rillig
Date:       Sun Jul  3 10:56:22 UTC 2022

Modified Files:
     src/external/historical/nawk/bin: awk.1

Log Message:
awk.1: remove trailing space in output of 'echo' example program

This is cure worse than the desease.  Please revert.

Why is it worse?

It's ugly

Why is it ugly?

and complicated (for an example),

Why is it complicated? It's still only 3 lines of code.

it obscures the point this example tries to make.

What is this (single?) point this example tries to make? To me, it
was how to write a BEGIN program that uses ARGV, and my rewritten
code still illustrates this.

You have turned a trivial for loop that requires no mental bandwidth
to skim over into a code review errand with complex case analysis and
ugly inverted 1 < ARGC to boot.

I intentionally wrote '1 < ARGC' instead of 'ARGC > 1' to make the
condition as close as possible to the condition in the 'for' loop.  If
it weren't for this symmetry, I would of course have written it in the
subject-first manner.

I realize this is de gustibus and if you don't see this new code that
way I probably cannot make you see it that way,

That's a tough assumption.  I precisely asked 'Why' because I couldn't
guess your reasons for calling this code bad and ugly, and I wanted to
understand them.

but this case is not
about code doing something specified with aesthetic considerations
being secondary to its actually doing the job.  Here taste is an
important factor b/c it's not code, but a man page - a literally work
really.

That's exactly my point.  The manual page is our reference
documentation, and as such, it should demonstrate and teach best
practices.  Presenting a program that is _almost correct_ misses this
point, and I don't want to see any code derived from an _almost correct_
example.  Mixing such code with other _almost correct_ example code will
quickly lead to programs with bugs everywhere.

An example for this would be the common usage of <ctype.h> functions,
which really many people get wrong, either by reading sloppily produced
teaching material or incomplete documentation or by copying code
snippets that seem to work.

Well, what *was* your goal?  To be "technically correct, the best kind
of correct"?

Yes, exactly that.  The comment above that snippet mentions echo(1),
which does not print a space after its last argument, so I chose to make
this example snippet implement this as well.  After all, it was just one
more line of code, demonstrating an 'if' condition, something that's not
yet in the other examples.

I'm pretty sure that whoever wrote that example did know how to write
a "proper" echo in awk, but chose not to deliberately.

Maybe, maybe not.  I don't know who wrote that example and when, and
what the motivation was back then.  That argument of "did know" does not
hold always though.

PS: BTW, you also eliminated the "exit" at the end of the BEGIN
action.  This is not specified by POSIX and happens to work on all
major three - nawk, mawk, gawk, though only gawk seems to document
this and only in the info file, not its man page (though its man page
has exampes that rely on this behaviour).

E.g. solaris /usr/bin/awk will still wait for input to consume and
discard it.

Ouch, thanks for telling me.  I was so sure that POSIX had specified
this that I didn't bother to look it up again.  Now I did, and I will
revert my changes.

Roland


Home | Main Index | Thread Index | Old Index