This tweet obviously resonates with many.

I often get asked about debugging when teaching a course...

A ๐Ÿงต

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.

-Kernighan's Law

๐Ÿคฏ
When I teach programming, I emphasize that to me, the most important part is that the code is "readable."

You write code (once or twice), but it is read all the time. Optimize for what happens a lot.

Not:

๐Ÿ˜ฆ Brevity
๐Ÿ˜ฆ Cleverness
๐Ÿ˜ฆ Using all of the features
At some point, we will need to start debugging. This is a skill that young kids can master. (My daughter typoed some code last night and was able to fix it)
Here are my debugging tips:

๐Ÿ’ช Prepare
๐Ÿ’ช Use "print" debugging
๐Ÿ’ช Rubber duck it ๐Ÿฆ†
๐Ÿ’ช Sleep on it
๐Ÿ’ช Debugger
๐Ÿ’ช Simplify/Test
Prepare - Make sure you know what you are trying to do. Read the documentation before diving in. Many problems I see are syntax errors. (See tweet above)
Print debugging - I use this all the time. Programming genius I know also use it. You can bend this into logging for production debugging.
Rubber duck - It turns out that you use a different portion of your brain when you vocalize your problems. Often times in the middle of describing it, you know your misstep.
This is called "rubber duck" debugging because people will speak to an inanimate object to get advice. The important part is to say it OUT LOUD (From "The Pragmatic Programmer")
Sleep on it - Another brain hack is called "incubation". I've slept on problems multiple times and woken up knowing what to do. Your brain will churn on issues even when you step away.

This is why pulling all-nighters trying to fix things is a misguided approach.
Debugger - A tool that allows for breakpoints and inspecting code can be useful. However, I find that the above steps often work before that.
Simplify/Test - "It works for me" is frustrating. You need to come up with the most simple version of the problem sometimes to get help. Writing tests can aid in this (and protect from future problems).
๐Ÿ™ Thanks for reading!

What is your favorite advice for debugging?

Follow me for more programming-related tips.

โ€ข โ€ข โ€ข

Missing some Tweet in this thread? You can try to force a refresh
ใ€€

Keep Current with matt harrison

matt harrison Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @__mharrison__

17 Mar
I'm teaching a Fundamentals of Python class this week.

We talked about tuples, and there was some confusion as to their existence.

Certainly, you could live in a world without them, but...

๐Ÿงต
First of all ... pronunciation.

You can say "two-pull" or "tuh-pull" (both are valid).
A big confusion is when to use a list or tuple?

My basic rule of thumb:

If you have items of the same type and care about the order or re-arranging it, you want a list.
Read 9 tweets
1 Jan
One of the most effective things I did for my career is probably the most difficult.

๐Ÿงต๐Ÿ‘‡
It is not difficult because it requires strength or knowledge, it is difficult because it requires will power.

I'm talking about writing a book. ๐Ÿ“š
Writing a book taught me a bunch of lessons about work, myself, and business. I would say it jumpstarted my career (even though I had been employed for over 13 years by that point). โš’๐Ÿง 
Read 10 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(