views:

56

answers:

5

I'm going to be giving a presentation a little later to a student ACM chapter about how they can utilize debugging tools to solve problems in their code. Any ideas for a (preferably short) bit of example code I can use to demo breakpoints, variable inspection, etc.?

My main worry is that I don't want to patronize them by using "Hello World" but I don't want to show where I'm going wrong in a real-world (thousands-of-lines) program either. I'm trying to find that happy medium.

Thanks to all!

A: 

If it is all Powerpoint material and the likes of that, I suggest just writing something menial that just describes the essence of what you are trying to convey. Once it comes to applying the actual things you are teaching, you either:

  • very quickly get lengthy code listings that make it difficult to (ab)use as an example, or
  • you get code that is stripped to such an extent that it covers one situation perfectly... which in turn means the design of the code itself won't make much sense due to the lack of the bigger picture.

If you want to use some 'real' code, I guess that the example applications that I am sure .NET comes with can serve as an adequate example. Everybody will have those by default, and they are basic enough in nature that they will not be too difficult to understand for someone following a course at the level you are teaching at.

Stigma
A: 

See Tess blog and learn from who knows.

and

Basic Debugging of an Application Crash

lsalamon
+2  A: 

If feasible, I suggest you spend a few hours now writing a program of your choice of non-trivial complexity. Note down precisely how you used a debugger to iron out the real bugs that were introduced, and reproduce the bugs + debugger steps at the presentation. That way, you can be sure you won't be patronizing them with a toy example.

Ani
A: 

Well if you want to go for some simple demos you can try the following:

  • Debugging an infinite loop (always a fun demo)
  • Debugging a null reference exception
  • Debugging a index out of bounds exception
  • Debugging the order of events in a winform or webform (should be pretty educational)

Honestly if you stick with some of the simpler exceptions you should come up with some great material.

Tony Abrams
A: 

I always found re-creating mathematical functions to be a terrific learning example; this is especially true for debugging.

For example, create a function that takes a square root of the input, recreating the math.sqrt abstracted function in your language. This teaching technique was used in the iTunes U podcast for MIT Intro to Comp Science.

Moses