Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: Coding style for small if statements
Date: Sat, 22 Feb 2020 01:19:14 -0800
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <86v9nzc73h.fsf@linuxsc.com>
References: <20200131234613.59047e037939ceb549b8e6d6@gmail.com> <65de5d07-838a-4a5f-bd70-b8a263fc61d6@googlegroups.com> <87imkkobdm.fsf@bsb.me.uk> <726b2209-ca7e-40fe-b429-fbc062f5b6bd@googlegroups.com> <874kw3nq6s.fsf@bsb.me.uk> <87k14ym0lg.fsf@bsb.me.uk> <875zggms21.fsf@bsb.me.uk> <87zhdrlqns.fsf@bsb.me.uk> <87lfpblaxo.fsf@bsb.me.uk> <87y2tbjksq.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="a1e79922b2c02e9149a52088916eaff2"; logging-data="16325"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/jWycJxvI/bm/0vr3mFJG6DHJWb3rqCqE="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:+tDQB9O4cF4ZnMkCDSQHh1AiAMY= sha1:ipFuwNddOhmsPz4G5BfaSDgXcxw=
Xref: csiph.com comp.lang.c:150140
Ben Bacarisse writes:
>> [...]
>
> Yes, I know that making that sort of inference was being
> suggested. I've not found it useful. I can't think what I'd do
> with that information. How does it help to infer (unreliably)
> that the author wrote correct code but intended to write incorrect
> code, or conversely, that they intended to write incorrect code
> but happened to get it right? What matters is what was written.
> [...]
I have found this conversation interesting but confusing. I have a
few comments I would like to share, in reaction to the discussion
generally, and I guess here is as good a place as any.
When I read code I want to know more than just what is being done.
I look for what might be called a narrative, to understand the
reasoning of what's going on, in addition to the nuts and bolts of
how it gets done. Ideally the code will convey a narrative closely
along the lines of what the author was thinking. However I would
not call this intent necessarily. Whether I discover or somehow
reconstruct the author's thoughts, or construct anew a narrative
independent of those thoughts, having a narrative is something
important for my reading and understanding.
Invariants are an essential tool, of course. OTOH they aren't
always present in my thinking when I am writing, or reading,
code. I'm not sure even what all the tools are that I use to
produce and confirm code that is correct. Testing is one of
those tools, naturally. Another tool is what I might call
"signposts", which are logical statements known or believed or
shown to be true, usually at a particular point of execution.
These aren't the same as invariants because they might, for
example, apply down only one branch of an if/else. Still they
can help simplify the reasoning process. A key point is that I
use different reasoning modes at different times, and never all
at once, but normally at most one or two at a time. Part of why
it is hard to describe or discuss them is because I'm not always
conscious of what mental tools I'm using at any given time, let
alone over all times.
So fwiw there are some of my thoughts. Please note that I am not
suggesting that tools I find useful are ones that others should
use. Part of the problem with topics like this is they turn from
discussion into argument, with more emphasis on convincing than
on simply stating and explaining. I would rather avoid the
convincing/arguing mode if possible.