
How to debug small programs - bhaumik
http://ericlippert.com/2014/03/05/how-to-debug-small-programs/#
======
brudgers
The degree to which it is acceptable to shit on students is a result of the
prohibitions on laughter stackOverflow's moderators love. All the meanness and
tribalism finds it's way oit and is vented upon the weakest members of the
community.

Yes, students can be rude asshats. But hang around 'regex' and asshattery is
no more unusual than 'SML'.

This article captures the smug prickishness that stackOverflow increasingly
celebrates. JustFuckingGoogleIt was clever a decade ago. It's quick and to the
point and the pain is over.

Learning to program is hard. A non-working program with a looming deadline is
genuinely and legitimacy stressful. And so what does the article do? It begins
by belittling the student, telling them their question was not worthy of the
great community. Let's be honest, the intended audience isn't students, its
other StackOverflow contributors and its purpose isn't to teach but belittle.

And that's the shame of it. A good article on debugging could be useful. Hell
a teacher might even incorporate it into the class. But of course the
StackOverflow community could not produce such a document. It violates their
unfortunate tribal mores.

~~~
MikeTaylor
"And that's the shame of it. A good article on debugging could be useful."

This _is_ a good article on debugging. It has a lot of specific, actionable,
helpful advice. I can only assume you stopped reading after first couple of
paragraphs.

~~~
brudgers
If I had stopped reading after a couple of paragraphs, I would not have been
aware the article contained any "actionable advice." Likewise if I had stopped
after 3 paragraphs or four or even five. It is only after six paragraphs of
putting the student in their place - instead of just linking to
StackOverflow's own prose describing good questions - that _" First, turn on
all compiler warnings"_ makes an appearance.

Is this good advice? Not really. Manipulating compiler setting is a homework
task in itself for a student. What could be simpler than setting compiler
warnings? It's all right here:

[http://gcc.gnu.org/onlinedocs/gcc/Warning-
Options.html](http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html)

However, there's a bit of a logical error in this method. [0] Apparently what
a student is supposed to do after turning them on is return to stackOverflow
and ask another question. Well at least the author recognizes that turning on
compiler warnings isn't really progress toward debugging except in the sense
that debugging consists of asking questions on StackOverflow.

Yet in fairness, it is hard to call this bad advice to a student struggling to
finish an assignment given the next piece of "helpful advice" is:

 _" If your program still has a bug, obtain a rubber duck."_

The reason I struggle with this being better or worse than the first piece of
advice is that at least rubber ducks don't make sport of trolling students
with homework questions. [1] According to the article, obtaining a rubber duck
will allow the student's code to compile. All that's left is to refactor,
write some tests, and a specification. Wasn't that helpful? Someonw has
already made and posted a video presentation of the method. [2]

[0] OK, it's not really a logical error, it's just a way to keep the victims
coming back for more. See next footnote.

[1] [http://codegolf.stackexchange.com/questions/16226/i-need-
a-p...](http://codegolf.stackexchange.com/questions/16226/i-need-a-program-
where-the-user-inputs-an-array-of-doubles-and-the-program-outpu)

[2]
[https://www.youtube.com/watch?v=tNfGyIW7aHM](https://www.youtube.com/watch?v=tNfGyIW7aHM)

~~~
ds9
I actually think the article has some value (rubber ducking is good :), but
continuing the parent's line of criticism: "Now step through the code using a
debugger".

That's all he says about that! Even for experienced developers, and depending
on the language, editor and other factors, installing and configuring a
debugger is often non-trivial. In fact setting up a working environment is a
whole other adventure for a newbie, and a different set of knowledge and
skills than programming. Yet this author merely recommends the debugger
without giving clues.

Of course he can't give directions for every situation, but recognizing the
big leap in the advice would be more considerate of the intended audience.

~~~
brudgers
Rubber Ducking is good for someone who writes code all day all year. It's
something a person can do if they aren't struggling with syntax and logic and
EMACS shortcuts while under a short deadline while having no team for support.

I suspect most students wind up at StackOverflow via websearch. Their
background is writing text messages and formulating good questions conforming
to StackOverflow's style guide is a skill unto itself. Most programming
education is sink or swim. It doesn't start with writing tests and specs - let
alone learning to use a debugger (call stacks are part of data structures and
algorithms courses not introductory programming classes).

The people who have more of it right than anyone are the PLT group. Their
curriculum is not designed to weed out the weak. It optimizes on preventing
false negatives rather than false positives. It's not as if there is a
scarcity of computational resources any more.

Likewise, it's not like StackOverflow will run through its supply of webpages
unless students are actively discouraged and abused. It is only because a
focus on preventing false positives ego strokes those who have been identified
as positive, that the practice sees so much love at StackOverflow. There's a
back button on the browser for anyone who doesn't like helping students with
homework. The site would be better if using it was the preferred behaviour.

------
ZoFreX
> StackOverflow is not about to debug your programs for you.

Could not disagree more. Students: submit your homework to StackOverflow.
You'll get yelled at, but someone will be desperate enough for imaginary
internet points that they will give you an answer regardless (just make sure
you keep your accept rate high enough).

(NB: This is facetious. I don't condone submitting your homework to
StackOverflow: You won't learn that way.)

~~~
jwdunne
LOL you think this is bad and StackOverflow has it hard?

I founded a number if groups on Facebook a few years ago and they're primarily
a QA sort of community, like SO but purely on FB. We don't just get the "help
me find the error questions" but also:

\- have u got free PDF for <expensive book> \- please give me code for
<trivial project> (often be explicit that its a student project) \- what
programming language should I learn? (Often its java or PHP. I literally know
one guy who has been trying to decide for 3 fucking years)

Sometimes I will get "I am just 2 gud at java coding" and also group/page
spam.

Sometimes questions like the above, especially the free pirated PDFs! Can't
believe people would be rude enough to try and throw all my hard work over the
years down the pan because they don't want to pay for education.

I don't make money from this. Nor has it improved my career prospects. How
dies StackOverflow sound now?

------
unwind
This is great, both as actual content and advice to (beginner) programmers but
also as "link-bait" in the best sense of the word, i.e. content that is very
likely to gather a lot of inbound links.

As a very active Stack Overflow user, I immediately start thinking about how
many questions that are going to get links to this as comments. :)

Well done, I hope it helps although I guess the supply of beginner programmers
won't dry up over night.

------
mopedDreams
Print("If you're reading this, that means the program got to this point!")

~~~
cooper12
Yep. This can be very useful. You could even print out the values of variables
at certain points. It become less useful though as the output of the program
increases, or as your program becomes more complex. that's when the things
mentioned in the OP are helpful.

------
collyw
Turn on all compiler warnings. _Read them carefully._

I wish my end users would actually read the error messages at all.

------
userbinator
That is a rather long way of saying "figure out _exactly_ what the program is
doing, and whether it matches what you _think_ it should be doing."

~~~
moistgorilla
Some people need this sort of explanation.

------
oneeyedpigeon
that link points to a google ad at the bottom of the page ...

