E
Ed Prochak
Hi Mr Tirkin
First, thanks for your contribution. It was a very interesting read.
David said:[snip]
Now, question for the people that keep a small part of common
sense here:
Is *reading* a program the *same* as *DEBUGGING* a program?If you mean by "reading," "reading with understanding," then I'd
guess I'd have to answer "yes" to this. When I read code and can't
understand why something is done or why something is done the way it
is, I've oftern found a problematic section of code which contains
bugs. I basically execute the code mentally as I read it. If you
mean to ask whether you can debug a program just by reading the
source code, the answer is also (obviously) yes. I have often found
that an algorithm was incorrectly implemented, just by looking at the
source code of the implementation.
This is of course possible, I will never deny this. But, as you read
lines and lines of code, your attention suffers, and you *think* you
understand what the code is doing but you actually don't because you
failed to see that
if (smp < smpGoal)
should have been
if (smp <= smpGoal)
and you are doomed.
Yes, you are doomed, but NOT for the reasons you give of brain limits.
You seem to think that on reading the wrong code, the reader mistakes
it for correct because of the volume of details around it. That may
sometimes be the case, but it is not the real source of the problem.
I have a saying I often repeat that describes the real cause of many
problems like this:
Self documenting code isn't.
On reading a large program there may be hints in the code that one or
the other of those two IF statements is the correct one. But the only
way to be sure is to have the requirements documented. Source code
cannot be self documenting. Source code can, by definition, only tell
you what it DOES, not what it is SUPPOSED to do. This is a stumbling
block for many, keeping them at skill levels of programmers versus
advancing to skills of software engineers. (This discussion might be
more rightly placed in comp.programming or comp.software-eng).
Maybe getting into a bit of psychology, we observe that the brain, with
ALL its power, can't do things that a lowly computer can easily do.
That is why BRAINS make computers in the first place!!!
Because they can do things that brains can't. And one of them is that
they have the capacity of doing things, and repeating them "ad nauseum"
without ever getting fed up with it.
You are attributing emotions to computers
Brains can't do that. They just CAN'T.
But brains with paper and pencil and time can. You place limits that
do not really exist.
... It is not a matter of will, it
is a fact of the circuit (the brain's circuit). It gets tired easily
with repetitive tasks and just shuts down. This is a reflex that is
common to all circuits based on neural networks: they learn to ignore
repetitive things and concentrate into CHANGE.
You THINK you understand the code, but after 867 lines you MISS the
deadly detail that will kill you later on.
Specially if there is a lot of repetition and not much redundancy.
Maybe on a casual reading of the code. If we are looking for a bug, a
difference issue comes into play which is: we see what we expect to
see. That is a problem. It is not the code repetition per se.
But knowing why something is written is a better way of finding the
bug than just reading source code in isolation.
C is not designed to be read by normal people.
I already know I'm not normal. 8^)
..... You *can* read it of
course if you are a programmer, but it is missing all the normal
parts of language that makes a human language easier to read and
understand. C must be understood by the programmer of course ( at
least the one that writes it for the first time ) but it ALSO has
to be understood by the machine. This makes C repetitive, and hard
to swallow in big quantities.
That's why modularization was invented and included in C.
Let's not make a fool of ourselves. I *know* that you can read a
lot of code, and I *do* read a lot of code. But I know that I can
pass 20 times over
strcmp(foo, "foo");
without noticing that it was Foo and not foo what should have been
written there.
The best proof of what I am saying is that (as you know) BUGS
exist. And they exist BECAUSE only BRAINS make mistakes and
introduce errors when building software.
okay.
What I am trying to point out is that automatic tools for following
the code when it is running are a VERY useful tool for understanding
foreign code.
This conclusion does not follow from your remarks in this post. Manual
tools (e.g. paper and pencil) may be effective as well. Sometimes just
another pair of eyes can see the bug. So your post did not make the
case for automated tools.
In fact you fall into the trap: if we cannot write bug free programs
without automated tools, then how do we write the programs to
implement those automated tools?
Obviously you have to know how to read C, if not, even the best
debugger is useless. But I would NOT rely so much in the capacity
of the brain. It is just not *done* for that kind of task.
It can be a matter of training. (experience is a kind of training).
And after writing that, I take it away of course. There are
people that can compute the 12th root of a 25 digit number in
a few minutes or sometime less. I heard in the radio last month of a
championship being held somewhere, where all those people did
*amazing* feats.
Don't give in so easily. Did they find your bug? (Foo vs foo?)
[]
And I know that if I have to, I can do without any debugger, because
I know the code I am working with, its failure modes, what I have
changed lately, etc. But I know that if I have a debugger
it is better (and MUCH faster) to use it.
Tools are made to be used. The issue seems to be, by analogy, whether
a hand saw is better than a power saw.
I stick to my limit, and I find a confirmation of this in your sentence:
That's the point I am making. 1500-2000 lines is the maximum
the brain can handle.
So then keep you code size below that limit and you will not need the
debugger.
for the saw analogy, stay with smaller dimension boards (half inch
plywood versus 6x6 pine) and a hand saw is just fine. But you still
will need blueprints to get the job done right.
But your post is so interesting (at least for me) in that you bring
many good ideas about why modularity is necessary, and how to structure
the code to preventively avoid bugs. It is a very welcome contribution
in a discussion (and it is my fault too) that we should have in a
much more *relaxed* manner. I agree that I make to much polemic
sometimes.
Excuse me.
Yes, David, thanks for the post.
Ed