Rubber Duck Debugging and code walk-throughs.

in #programming7 years ago

I'm currently about 29% through the Udemy course on Machine Learning using Python and R. Their forums aren't very active, so I tried my hand at tutoring someone who had an interesting question there.

This question interests me not so much because it pertains to machine learning (it doesn't really, that is just the subject of the code in question), but because I am only familiar with one line by line code walk-through technique.

If you are familiar with other code walk-through techniques or if you have any tips on how to deal with foreign code, please drop me a comment and share the knowledge love!

The Question

I'm fairly new to Python and I want to make sure that I understood each line of the "Backward Elimination with p-values only".

Can anyone please help with this?(I especially could not nail the two loops and understand how the sequence follows).

My Answer

There is a technique for this sort of thing called Rubber Duck Debugging. The idea is that you should pretend that you are explaining the code to someone else, even though you may not really know what is going on there, and in the process, you will gain new insights into the code. This someone else is often a rubber duck, if nobody else is around, and from there the name. I have a rubber duck on my desk that I use for debugging code line by line, and also to alienate co-workers.

By Tom Morris - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=16745966
A rubber duck assisting with debugging.

My suggestion would be:

  • Describe the code line by line, as if you were explaining it to your rubber duck. Don't try too hard to understand what is going on. Just describe each line. Do this a couple of times, until you are certain that you can describe each line accurately.
  • List syntax that you do not understand completely. For example, if you do not know about p-values, take note of this. If you do not know about the api part that gets imported, then make note of these. Just make a list of specifics, a little bit further down than just the nested loops. In other words, do this primarily at the lexical level, forget about phrases and contexts.
  • Research the syntax that you did not understand 100%. It might take a while, but it is worth it.
  • Comment each line in your own words. You should notice that your description would have changed by now, because you are more knowledgeable on what each line does, plus you are familiar with the inner workings of formerly unfamiliar syntax.

My answer on the forums included code too but I did not include that here for two reasons:

  • It's not my code and it may be under copyright of the course.
  • It's not relevant here, I'm merely fishing for more suggestions on how to make code walk-throughs a bit more methodological.

Feel free to drop some comments!