[H-GEN] Which is better?

Greg Black gjb at gbch.net
Tue May 4 06:31:09 EDT 2004

I'm leaving this in general, because that's where the original
question was (wrongly) posted and where the major discussion has
taken place.  But it would be great if the original poster and
anybody else with such interests could learn to use the dsig
list in future, as that's what it is there for.

On 2004-04-28, Adrian Sutton wrote:

> 1. Think through your design and choose appropriate algorithms.
> 2. Write clean maintainable code.
> 3. If the application isn't fast enough, profile it.
> 4. Fix the performance bottle necks.
> 5. Go to step 3.

I think there was some agreement that this was a reasonable
statement, but it has occurred to me that we never did really
cover step 2.

I express this one slightly differently, using "readable" as the
criterion of interest.  But that still needs to be explained.

I'm going to illustrate in C, because it's a splendid tool for
demonstrating the interesting stuff here.

If you write

    int c;

    while ((c = getchar()) != EOF)

some people will tell you that it's hard to understand, and they
will have various reasons for that.  But you, as a C programmer,
won't be at all interested in their complaints because it will
be apparent to you that these people are not C programmers and
therefore their difficulty with the code is simply irrelevant.

If I write in English and a French speaker complains that I'm
hard to understand, I don't care; it's only meaningful if the
complaint comes from an English speaker.  Similarly, complaints
about C idioms from people who don't speak C don't mean anything.

Here's a different example:

    if ((x < n) || (y > p))

This is wrong because it has meaningless parentheses.  True,
they don't change the code, but they do force somebody who is
fluent in C to stop and check to see if there was some reason
for the noise.  Of course, a real example will be harder to
verify than this one which won't really trouble anybody.  The
point is this: every language, whether a human language like
English or French or a computer language like C or Lisp, has its
idioms; and it's the job of the speaker to learn them.

To wind this up, the most critical thing for any programmer is
to learn to write code that both she and any other person fluent
in the language will be readily able to understand on reading.
The computers will manage fine, no matter how ugly or beautiful
our code; but we humans have to be able to be comfortable with
it in order to construct it so that it can perform its work as
it should and so that we can see what to change when the code
needs to be fixed or extended.

Cheers, Greg
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 249 bytes
Desc: not available
URL: <http://lists.humbug.org.au/pipermail/general/attachments/20040504/41bc7b2a/attachment.sig>

More information about the General mailing list