mnemonic

J

James Kuyper

Richard said:
Al Balmer said:
Richard wrote:
[...]
“Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.†– Brian W. Kernighan
This quote is maybe sometimes applicable. But not always.

Debugging well structured and documented code is generally quite
easy. [...]
Richard seems to have missed the "if" clause in the above quote.

No. "Cleverly" means many different things and means different things
when coding than when debugging.

But this phrase is trotted out all the time to suggest that good
programmers dont need debuggers.

That interpretation of it is simply garbage.

That's a weird interpretation! The quote is about debugging, not
debuggers. It's about the importance of writing code so it can be
debugged, which implies that debugging is important too, not that it's
unnecessary.

Who's saying this? Can you give an example? I just searched on Google
for messages containing the word "debugger" and that quotation. The
overwhelming majority of the 100 most relevant hits were from quotations
inside signatures, mostly on this newsgroup, and mostly by Mark
Macintyre. However, the handful of messages that actually were about
that quotation included not a single one making the misinterpretation
you describe.
 
R

Richard

James Kuyper said:
Richard said:
Al Balmer said:
On Thu, 01 Nov 2007 21:01:17 -0400, Eric Sosman

Richard wrote:
[...]
“Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.†– Brian W. Kernighan
This quote is maybe sometimes applicable. But not always.

Debugging well structured and documented code is generally quite
easy. [...]
Richard seems to have missed the "if" clause in the above quote.

No. "Cleverly" means many different things and means different things
when coding than when debugging.

But this phrase is trotted out all the time to suggest that good
programmers dont need debuggers.

That interpretation of it is simply garbage.

That's a weird interpretation! The quote is about debugging, not
debuggers. It's about the importance of writing code so it can be
debugged, which implies that debugging is important too, not that it's
unnecessary.

I said the times it is trotted out. There are a few here that think
Debuggers are unnecessary and are only for "poor coders".

Regardless of that, the first line of the quote is simply not true - In
My Opinion.

Yes, I know the usual lickspittles will say "who do we believe? You or
Mr Kernighan?", but funnily enough there are certain issues which do not
have a true or false which is consistent for all people and all
situations.

Again, since there is a trend to try and twist things here : yes, in a
perfect world it would be nice to get the code right the first
time. However, its not always about the code. Its about sets of data
which might cause certain situations which were not considered during
the design and implementation of the code suite. This is where a
debugger is INFINITELY easier than "writing it all from scratch
correctly" since a debugger can be set to trigger during certain data
conditions and is obviously much easier than "doing it all in your head"
for something like a 24 hour simulation....
 
S

Serve Lau

James Kuyper said:
That's a weird interpretation! The quote is about debugging, not
debuggers. It's about the importance of writing code so it can be
debugged, which implies that debugging is important too, not that it's
unnecessary.

Who's saying this?

its in this thread.

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it." - Brian W. Kernighan
 
T

Tor Rustad

Serve said:
its in this thread.

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it." - Brian W. Kernighan

Nope, Kernighan refer to debugging, which is a process not limited to
running a program in a debugger.
 
E

Eric Sosman

Ben said:
I'd say that about half of my bugs I find with printf. Another
half, I find with valgrind. Another 5% are made obvious with
"git bisect". The last 10%, I find with a traditional debugger.

That pretty much matches my experience. Debuggers are
useful when I'm starting from a position of cluelessness,
knowing only the bug's symptom but having no idea about its
cause. (This usually means that I'm debugging a program I
know squat about, or I'm debugging a badly-organized program.)
Debuggers can also be helpful when you've reasoned your way
back to a cause that's really just a symptom of an Ur-cause;
stack traces (something you can't get from C) are very helpful
here.

'course, I'm biased. I started learning to program back
in the days when you handed decks of punched cards through a
window and got them back with a printout some hours later.
Interactive debuggers simply didn't exist, so one was forced
to learn other approaches. The interesting thing is that the
"primitive" techniques are plenty good enough for most bugs;
the more "advanced" tools push the debugging frontier a little
further forward, but not by an extraordinary distance.
 
R

Richard

Tor Rustad said:
Nope, Kernighan refer to debugging, which is a process not limited to
running a program in a debugger.

Of course it isn't. But it would be fairly ridiculous to suggest that
any form of debugging an existing code base is NOT done with a
"debugger" of some description. People who advocate littering code with
printfs are plain wrong IMO. Yes, it might have its uses occasionally,
but any changing of the code to "debug" is generally considered a bad
thing.

From some of the comments I read here, I often wonder if the people
knocking debuggers have any idea whatsoever of just what they are, how
they work and the results they can achieve.

One of my favorite uses of a debugger is simply to step through code to
get a feel for the control flow. Ability to step over calls and just
examine the returned data etc is much easier than "imagining" it by
reading code no matter how well and clearly that code is written and
annotated.
 
J

James Kuyper

Serve said:
its in this thread.

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it." - Brian W. Kernighan

I wasn't asking who was quoting that statement; I asked who was
misinterpreting it in the fashion that (e-mail address removed) described.
 
J

Joe Wright

Ben said:
I'm not as old as CBFalconer.

Nobody is. I thought I was but have been convinced otherwise. That RJH
would allude to 'Face down, nine edge first?' makes me wonder how long
in the tooth he is.
 
R

Richard

Joe Wright said:
Nobody is. I thought I was but have been convinced otherwise. That RJH
would allude to 'Face down, nine edge first?' makes me wonder how long
in the tooth he is.

I'll post this again as it is interesting and a good read for newbies.

http://www.dirac.org/linux/gdb/01-Introduction.php

Still, all to their own.

Here is a quote from the above link

,----
| You'll be able to find and fix your bugs faster using a symbolic
| debugger like GDB. However, this isn't to say that printf() has no use
| in debugging. Sometimes it's the best way to go. However, for real code,
| a debugger can almost always get the job done orders of magnitude faster
| and easier. And using a debugger is always more elegant, and if you
| don't care about elegance, you should quit programming on Linux and
| start using Visual C++.
`----

Having got the PC "yah, if it works for you" out of the way : I would
personally be hard to convince on any project I was working on that
using printf offered anything over a proper debugger for tracking down
issues.

Using printf is the resort of the hobbyist programmer or the lone Guru
(who hasn't mastered a decent debugger ... :-;)
 
B

Ben Bacarisse

Joe Wright said:
Nobody is. I thought I was but have been convinced otherwise. That RJH
would allude to 'Face down, nine edge first?' makes me wonder how long
in the tooth he is.

One hardly has to be ancient. I am 46 and my first programs were
written on coding forms and posted to Dundee. The printout came back
the next week. Punching my own cards was came a year later. Of
course, interactive systems were available at the time, but they were
considered expensive compared to the batch systems.

I must say, an hourly turn round does alter ones attitude to typos and
bugs of all sorts. To link this to another thread, I was trilled when
interactive debuggers arrived, and bowled over by source-level
debugging, but the infatuation wore off after a few years. They have
their place, but all debugging ultimately happens in the brain even if
some of the data comes from a debugger.
 
M

Martien Verbruggen

Again, since there is a trend to try and twist things here : yes, in a
perfect world it would be nice to get the code right the first
time. However, its not always about the code. Its about sets of data

I get the feeling you might have misread the first sentence ofthe quote.
At least you see to be arguing as if it said: "Debugging is twice as hard
as getting the code right int he first place.". rather than what it
really says.
which might cause certain situations which were not considered during
the design and implementation of the code suite. This is where a
debugger is INFINITELY easier than "writing it all from scratch
correctly" since a debugger can be set to trigger during certain data

Again, this leads me to believe you've read something different to
what's actually written..

Martien
 
M

Martien Verbruggen

Again, since there is a trend to try and twist things here : yes, in a
perfect world it would be nice to get the code right the first
time. However, its not always about the code. Its about sets of data

I get the feeling you might have misread the first sentence of the quote.
At least you seem to be arguing as if it said: "Debugging is twice as hard
as getting the code right in the first place.", rather than what it
really says.
which might cause certain situations which were not considered during
the design and implementation of the code suite. This is where a
debugger is INFINITELY easier than "writing it all from scratch
correctly" since a debugger can be set to trigger during certain data

Again, this leads me to believe you've read something different to
what's actually written.

Martien
 
C

CBFalconer

Ben said:
I'm not as old as CBFalconer.

Who hasn't fired up a debugger in at least two or three years. For
me, printf seems to do the job when combined with head-scratching.
And yes, I am considerably older than the C language.
 
T

Tor Rustad

Richard said:
From some of the comments I read here, I often wonder if the people
knocking debuggers have any idea whatsoever of just what they are, how
they work and the results they can achieve.

We are old. Debugging a 300.000 line monster, wasn't very practical on a
VT100 terminal. Something like 24 lines of code on the screen... so a
program listing was usually nearby.

IDE is nice to have these days, but I mainly use the debugger before the
unit test phase is over. After that, the hard-to-find bugs, are usually
located via other methods.
 
J

jacob navia

Tor said:
We are old. Debugging a 300.000 line monster, wasn't very practical on a
VT100 terminal. Something like 24 lines of code on the screen... so a
program listing was usually nearby.

IDE is nice to have these days, but I mainly use the debugger before the
unit test phase is over. After that, the hard-to-find bugs, are usually
located via other methods.

Yeah of course.

True programmers drink beer and use Fortran.

All others are pimps.

Or similar...

Let me present a dissenting view. For me, a debugger is essential.
Without it you can't debug a complex program, isn't it obvious?
A debugger lets you debug a program.

But of course I use a debugger because I have bugs, contrary to
the super heroes in this group that never do any mistake.

I remember a certain Dan Pop that would say that he never had a crash in
his programs... Of course he did not need a debugger then!
 
S

santosh

Let me present a dissenting view. For me, a debugger is essential.
Without it you can't debug a complex program, isn't it obvious?
A debugger lets you debug a program.

As others mentioned there are other ways to debug a program too.
Debugging is a name given to a collection of strategies for locating
and quashing bugs, one component of which is using a debugger.

Everything from printf to assert to good comments to static source
checkers to compilers to profiling tools to debuggers all have their
part.

The relative applicability of each method to a source code base depends
on many factors, not least of which is the design of the code itself. A
poorly designed program may render some debugging strategies useless.

<snip>
 
I

Ian Collins

jacob said:
Let me present a dissenting view. For me, a debugger is essential.
Without it you can't debug a complex program, isn't it obvious?
A debugger lets you debug a program.
Maybe you should try using a language without a debugger, it does
wonders for your testing and debugging skills.

C developers are spoilt rotten with decent debuggers, they have their
uses and they are an excellent means of proving the cause of a problem,
but I think overall they blunt rather than sharpen ones skills.
But of course I use a debugger because I have bugs, contrary to
the super heroes in this group that never do any mistake.
We all make mistakes, we just use different strategies for fixing them.
I prefer my unit tests, if I have to use my debugger, I know my tests
are too coarse. A year of PHP development without a debugger taught me
that lesson.
 
J

James Kuyper

Richard said:
I said the times it is trotted out. There are a few here that think
Debuggers are unnecessary and are only for "poor coders".

Regardless of that, the first line of the quote is simply not true - In
My Opinion.

Yes, I know the usual lickspittles will say "who do we believe? You or
Mr Kernighan?", but funnily enough there are certain issues which do not
have a true or false which is consistent for all people and all
situations.

Mr. Kernighan was making a short, pithy statement, which was worded to
be easily remembered for the important point that it is making. It's not
a precise statement of a fixed law of nature. It was not meant to be
interpreted as a hard and fast rule with an exactly measured ratio of
difficulty. Would you be any happier with the statement if I messed it
up by inserting all kinds of qualifiers like "tends to", "generally",
"typically", "for most people", and the like? Those qualifiers, while
technically necessary to make the statement literally true, would make
it hard to understand, and harder to remember. In practice, those
qualifiers should not be needed, because he should have been able to
count on reasonable people to infer those qualifiers, even though
they're not explicitly stated.

I think it's equally a mistake to interpret that statement as suggesting
that there's only a single skill, which is used for both coding and for
debugging, and that the relative difficulty of the two tasks is exactly
the same for everyone. Technically, that's what the words say, but they
were not intended to be taken literally, but only as a simplification of
reality to make his point clearer.

....
the design and implementation of the code suite. This is where a
debugger is INFINITELY easier than "writing it all from scratch
correctly" since a debugger can be set to trigger during certain data
conditions and is obviously much easier than "doing it all in your head"
for something like a 24 hour simulation....

That paragraph addresses an approach being advocated in the thread about
XP, but doesn't seem to be relevant to either this thread or to the
quotation you're objecting to. Mr. Kernighan's quotation is about
writing your code simply and clearly so it's easy to debug (whether you
use desk checking, printf()s, a debugger, or any other technique to
perform the debugging).

The particular message by Al Balmer on this thread which cited that
quote, thereby triggering your original objection, was about writing the
code with sufficient simplicity that it can be clearly understood. The
"well-structured and documented" code you were talking about in your
response would be a prime example of code that is NOT too complicated to
be easily understood.

Neither Kernighan's quote nor Al's message was about performing a
re-write from scratch instead of using a debugger.
 
K

Keith Thompson

jacob navia said:
Yeah of course.

True programmers drink beer and use Fortran.

All others are pimps.

Or similar...

Yeah, of course. If a couple of people describe their own personal
experiences and preferences, they must really be saying what all "true
programmers" do. Or maybe they were just speaking for themselves.
Let me present a dissenting view. For me, a debugger is essential.
Without it you can't debug a complex program, isn't it obvious?
A debugger lets you debug a program.

A debugger is one of many tools that can be used to debug a program.
It's certainly possible to debug a complex program without using one.

Debuggers work for you. That's terrific.
But of course I use a debugger because I have bugs, contrary to
the super heroes in this group that never do any mistake.

Your attempts at sarcasm are quite annoying. I don't recall anyone
here claiming that they never make mistakes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top