Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: Sort of trivial code challenge - may be interesting to you anyway
Date: Wed, 11 Mar 2026 12:44:52 -0700
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <86ikb28823.fsf@linuxsc.com>
References: <10n80sc$3soe4$1@dont-email.me> <86v7feei2e.fsf@linuxsc.com> <10o53k6$1i0ef$2@dont-email.me> <86ms0peby6.fsf@linuxsc.com> <10ockdh$3qpk6$1@dont-email.me> <10ocrjn$3qpk6$2@dont-email.me> <10od64s$3qpk6$4@dont-email.me> <86ikb9bmtw.fsf@linuxsc.com> <10oem5t$n5hk$1@dont-email.me> <86o6kz9zng.fsf@linuxsc.com> <10oi72k$1rss6$1@dont-email.me> <10oid0u$1u9aa$2@dont-email.me> <10ok1sl$2e7mc$1@dont-email.me> <10ok6f2$2ejoa$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Wed, 11 Mar 2026 19:44:59 +0000 (UTC)
Injection-Info: dont-email.me; posting-host="5f44bcdbc02769ce6998caa4a4cb2206"; logging-data="1472491"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1903I0d96lEeejgwgQ61zrRwTiuvJfsOfM="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:118Cbi9ZB/rTYr1lQNw6e6KUmz0= sha1:f8iJPz4nZBpEeqh6/zLFBM81oeo=
Xref: csiph.com comp.lang.c:396912
Lew Pitcher writes:
> On Sun, 08 Mar 2026 10:42:34 -0400, DFS wrote:
> [snip]
>
>> Sure it's a bearded-lady novelty, but I think he knocked it out of
>> the park.
>
> I think of it as an educational opportunity. Look at how succinctly
> Tim's code satisfied not only your requirements, but the outrageously
> restrictive constraints his counter-challenge posed.
>
> With his solution, he implemented an 84 line finite state machine
> that matched your 131 line example. I, for one, will spend a fair
> bit of time studying /how/ his code works, and gleaning some
> techniques to improve /my/ coding.
>
>
> Just my $0.02 worth.
My purpose in posing the counter challenge was two fold: one, to
offer an opportunity for an educational exercise; and two, to
illustrate a high-level structural pattern that might not be
familiar to people. Also I had fun writing my program, and it was
a pleasure to post it.
There are some aspects to my posted code that are just byproducts
of some general principles I follow in code writing rather than
meant to illustrate anything in particular. I like code that
looks clean. I generally favor holding state in variables rather
than using control flow. I like code to be succinct, which tends
to mean fewer lines, but there is a tension between number of
lines and line width; for C code I self-impose an upper limit of
79 columns, and try to avoid wrapping lines. I try to write code
that is understandable and self-explanatory, but that is a more
subjective area, and of course there are tradeoffs with other
properties desired. Scale is important: being comprehensible on
a large scale is given as much weight as what is done on a small
scale. People who focus on small scale appearance, especially in
the posted example code, are in danger of missing the point.
Hopefully my commentary in the preceding paragraph will help you
in getting more value out of my little example program.