Files
nexus/sreweekly/articles/351/08-a-debugging-manifesto.html
2026-09-12 17:23:01 +08:00

291 lines
15 KiB
HTML

<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8">
<title>A debugging manifesto</title>
<meta name="author" content="Julia Evans">
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="description" content="A debugging manifesto">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="og:title" content='A debugging manifesto'>
<meta property="og:type" content="website" />
<meta property="og:url" content="https://jvns.ca/blog/2022/12/08/a-debugging-manifesto/" />
<meta property="og:site_name" content="Julia Evans" />
<link rel="canonical" href="https://jvns.ca/blog/2022/12/08/a-debugging-manifesto/">
<link href="/favicon.ico" rel="icon">
<link href="/stylesheets/screen.css" rel="preload" type="text/css" as="style">
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<link href="/stylesheets/print.css" media="print" rel="stylesheet" type="text/css">
<link href="/atom.xml" rel="alternate" title="Julia Evans" type="application/atom+xml">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.css" integrity="sha384-vKruj+a13U8yHIkAyGgK1J3ArTLzrFGBbBc0tDp4ad/EyewESeXE/Iv67Aj8gKZ0" crossorigin="anonymous">
<script defer data-domain="jvns.ca" src="https://plausible.io/js/script.js"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.js" integrity="sha384-PwRUT/YqbnEjkZO0zZxNqcxACrXe+j766U2amXcgMg5457rve2Y7I6ZJSm2A0mS4" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/contrib/auto-render.min.js" integrity="sha384-+VBxd3r6XgURycqtZ117nYw44OOcIax56Z4dCRWbxyPt0Koah1uHoK0o4+/RRE05" crossorigin="anonymous" onload="renderMathInElement(document.body);"></script>
<script defer type="text/javascript">
window.heap=window.heap||[],heap.load=function(e,t){window.heap.appid=e,window.heap.config=t=t||{};var r=document.createElement("script");r.type="text/javascript",r.async=!0,r.src="https://cdn.heapanalytics.com/js/heap-"+e+".js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(r,a);for(var n=function(e){return function(){heap.push([e].concat(Array.prototype.slice.call(arguments,0)))}},p=["addEventProperties","addUserProperties","clearEventProperties","identify","resetIdentity","removeEventProperty","setEventProperties","track","unsetEventProperty"],o=0;o<p.length;o++)heap[p[o]]=n(p[o])};
heap.load("2242143965");
</script>
</head>
<body>
<div id="skiptocontent">
<a href="#main">Skip to main content</a>
</div>
<div id="wrap">
<header role="banner">
<hgroup>
<h1><a href="/">Julia Evans</a></h1>
</hgroup>
<ul class="header-links">
<li><a href="/about">About</a></li>
<li><a href="/talks">Talks</a></li>
<li><a href="/projects/">Projects</a></li>
<li><a rel="me" href="https://social.jvns.ca/@b0rk">Mastodon</a></li>
<li><a href="https://bsky.app/profile/b0rk.jvns.ca">Bluesky</a></li>
<li><a href="https://github.com/jvns">Github</a></li>
</ul>
</header>
<nav role="navigation" class="header-nav"><ul class="main-navigation">
<li><a href="/categories/favorite/">Favorites</a></li>
<li><a href="/til/">TIL</a></li>
<li><a href="https://wizardzines.com">Zines</a></li>
<li class="subscription" data-subscription="rss"><a href="/atom.xml" rel="subscribe-rss" title="subscribe via RSS">RSS</a></li>
</ul>
</nav>
<div id="main">
<div id="content">
<div>
<article class="hentry" role="article">
<header>
<h1 class="entry-title">A debugging manifesto</h1>
<div class="post-tags">
</div>
<p class="meta sans">
<time class="date" datetime="2022-12-08T12:21:01" pubdate data-updated="true">
December 8, 2022
</time>
</p>
</header>
<main>
<p>Hello! I&rsquo;ve been working on a zine about debugging for the last 6 months with
my friend <a href="https://marieflanagan.com/">Marie</a>, and one of the problems we ran
into was figuring out how to explain the right <em>attitude</em> to take when debugging.</p>
<p>We ended up writing a short debugging manifesto to start the zine with, and I&rsquo;m
pretty happy with how it came out. Here it is as an image, and as text (with
some extra explanations)</p>
<img src="https://jvns.ca/images/manifesto.png">
<h3 id="1-inspect-don-t-squash" class="post-heading">
<a href="#1-inspect-don-t-squash">
1. Inspect, don&rsquo;t squash
</a>
</h3>
<p>When you run into a bug, the natural instinct is to try to <em>fix it</em> as fast as
possible. And of course, sometimes that&rsquo;s what you have to do &ndash; if the bug is
causing a huge production incident, you have to mitigate it quickly before
diving into figuring out the root cause.</p>
<p>But in my day to day debugging, I find that it&rsquo;s generally more effective (and
faster!) to <strong>leave the bug in place</strong>, figure out exactly what&rsquo;s gone wrong,
and then fix it after I&rsquo;ve understood what happened.</p>
<p>Trying to fix it or add workarounds without fully understanding what happened
usually ends up just leaving me <em>more</em> confused.</p>
<h3 id="2-being-stuck-is-temporary" class="post-heading">
<a href="#2-being-stuck-is-temporary">
2. Being stuck is temporary
</a>
</h3>
<p>Sometimes I get really demoralized when debugging and it feels like I&rsquo;ll NEVER
make progress.</p>
<p>I have to remind myself that I&rsquo;ve fixed a lot of bugs before, and I&rsquo;ll probably
fix this one too :)</p>
<h3 id="3-trust-nobody-and-nothing" class="post-heading">
<a href="#3-trust-nobody-and-nothing">
3. Trust nobody and nothing
</a>
</h3>
<p>Sometimes bugs come from surprising sources! For example, in <a href="https://jvns.ca/blog/2018/01/28/mac-freeze/">I think I found a Mac kernel bug?</a> I describe how,
the first time I tried to write a program for Mac OS, I had a bug in my program
that was caused by a Mac OS kernel bug.</p>
<p>This was really surprising (usually the operating system is not at fault!!),
but sometimes even normally-trustworthy sources are wrong. Even it&rsquo;s a popular
library, your operating system, the official documentation, or an extremely
smart and competent coworker!</p>
<h3 id="4-it-s-probably-your-code" class="post-heading">
<a href="#4-it-s-probably-your-code">
4. It&rsquo;s probably your code
</a>
</h3>
<p>That said, <strong>almost all of the time</strong> the problem is not &ldquo;there&rsquo;s a bug in Mac
OS&rdquo;. I can only speak for myself, but 95% of the time something is going wrong
with my program, it&rsquo;s because I did something silly.</p>
<p>So it&rsquo;s important to look for the problem in your own code first before trying
to blame some external source.</p>
<h3 id="5-don-t-go-it-alone" class="post-heading">
<a href="#5-don-t-go-it-alone">
5. Don&rsquo;t go it alone
</a>
</h3>
<p>I&rsquo;ve learned SO much by asking coworkers or friends for help with debugging. I
think it&rsquo;s one of the most fun ways to collaborate because you have a specific
goal, and there are tons of opportunities to share information like:</p>
<ul>
<li>how to use a specific debugging tool (&ldquo;here&rsquo;s how to use GDB to inspect the memory here&hellip;.&rdquo;)</li>
<li>how a computer thing works (&ldquo;hey, can you explain CORS?&rdquo;)</li>
<li>similar past bugs (&ldquo;I&rsquo;ve seen this break in X way in the past, maybe it&rsquo;s that?&rdquo;)</li>
</ul>
<h3 id="6-there-s-always-a-reason" class="post-heading">
<a href="#6-there-s-always-a-reason">
6. There&rsquo;s always a reason
</a>
</h3>
<p>This one kind of speaks for itself: sometimes it <em>feels</em> like things are just
randomly breaking for no reason, but that&rsquo;s never true.</p>
<p>Even if something truly weird is happening (like a hardware problem), that&rsquo;s
still a reason.</p>
<h3 id="7-build-your-toolkit" class="post-heading">
<a href="#7-build-your-toolkit">
7. Build your toolkit
</a>
</h3>
<p>I&rsquo;ve written a LOT about my love for debugging tools like tcpdump, strace, and
more on this blog.</p>
<p>To fix bugs you need information about what your program is doing, and to get
that information sometimes you need to learn a new tool.</p>
<p>Also, sometimes you need to build your own better tools, like by improving your
test suite, pretty printing, etc.</p>
<h3 id="8-it-can-be-an-adventure" class="post-heading">
<a href="#8-it-can-be-an-adventure">
8. It can be an adventure
</a>
</h3>
<p>As you probably know if you&rsquo;re a regular reader of this blog, I love debugging
and I&rsquo;ve learned a lot from doing it. You get to learn something new! Sometimes
you get a great war story to tell! What could be more fun?</p>
<p>I really think of debugging as an investment in my future knowledge &ndash; if
something is breaking, it&rsquo;s often because there&rsquo;s something wrong in my mental
model, and that&rsquo;s an opportunity to learn and make sure that I know it for next
time.</p>
<p>Of course, not <em>all</em> bugs are adventures (that off-by-one error I was debugging
today certainly did not feel like a fun adventure). But I think it&rsquo;s important
to (as much as you can) reflect on your bugs and see what you can learn from
them.</p>
</main>
<footer>
<style type="text/css">
#mc_embed_signup{background:#fff; clear:left; font:14px Helvetica,Arial,sans-serif; display: inline;}
#mc_embed_signup {
display: inline;
}
#mc_embed_signup input.button {
background: #ff5e00;
display: inline;
color: white;
padding: 6px 12px;
}
</style>
<div class="sharing">
<style>
.form-inline {
display:flex; flex-flow: row wrap; justify-content: center;
}
.form-inline input, .form-inline span {
padding: 10px;
}
.form-inline input {
display:inline;
max-width:30%;
margin: 0 10px 0 0;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 5px;
padding: 10px;
}
button {
background-color: #f50;
box-shadow: none;
border: 0;
border-radius: 5px;
color: white;
padding: 5px 10px;
}
@media (max-width: 800px) {
.form-inline input {
margin: 10px 0;
max-width:100% !important;
}
.form-inline {
flex-direction: column;
align-items: stretch;
}
}
</style>
<div align="center">
<form class="form-inline" action="https://app.convertkit.com/forms/1052396/subscriptions" method="post" data-uid="8884355abb" data-format="inline" data-version="5">
<span> Want a weekly digest of this blog?</span>
<input name="email_address" type="text" placeholder="Email address" />
<button type="submit" data-element="submit">Subscribe</button>
</form>
</div>
</div>
<p class="meta">
<a class="basic-alignment left" href="https://jvns.ca/blog/2022/12/07/tips-for-analyzing-logs/" title="Previous Post: Tips for analyzing logs">Tips for analyzing logs</a>
<a class="basic-alignment right" href="https://jvns.ca/blog/2022/12/21/new-zine--the-pocket-guide-to-debugging/" title="Next Post: New zine: The Pocket Guide to Debugging">New zine: The Pocket Guide to Debugging</a>
</p>
</footer>
</article>
</div>
</div>
</div>
<nav role="navigation" class="footer-nav"> <a href="/">Archives</a>
</nav>
<footer role="contentinfo"><span class="credit">&copy; Julia Evans. </span>
<span>If you like this, you may like <a href="https://web.archive.org/web/20181228051203/http://www.uliaea.ca/">Ulia Ea</a> or, more seriously, this list of <a href="https://jvns.ca/blogroll">blogs I love</a> or some <a href="https://jvns.ca/bookshelf">books I've read</a>. <br>
<p class="rc-scout__text"><i class="rc-scout__logo"></i>
You might also like the <a class="rc-scout__link" href="https://www.recurse.com/scout/click?t=546ea46360584b522270b8c3e5d830f8">Recurse Center</a>, my very favorite programming community <a href="/categories/hackerschool/">(my posts about it)</a></p>
</span>
<style class="rc-scout__style" type="text/css">.rc-scout{display:block;padding:0;border:0;margin:0;}.rc-scout__text{display:block;padding:0;border:0;margin:0;height:100%;font-size:100%;}.rc-scout__logo{display:inline-block;padding:0;border:0;margin:0;width:0.85em;height:0.85em;background:no-repeat center url('data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2012%2015%22%3E%3Crect%20x%3D%220%22%20y%3D%220%22%20width%3D%2212%22%20height%3D%2210%22%20fill%3D%22%23000%22%3E%3C%2Frect%3E%3Crect%20x%3D%221%22%20y%3D%221%22%20width%3D%2210%22%20height%3D%228%22%20fill%3D%22%23fff%22%3E%3C%2Frect%3E%3Crect%20x%3D%222%22%20y%3D%222%22%20width%3D%228%22%20height%3D%226%22%20fill%3D%22%23000%22%3E%3C%2Frect%3E%3Crect%20x%3D%222%22%20y%3D%223%22%20width%3D%221%22%20height%3D%221%22%20fill%3D%22%2361ae24%22%3E%3C%2Frect%3E%3Crect%20x%3D%224%22%20y%3D%223%22%20width%3D%221%22%20height%3D%221%22%20fill%3D%22%2361ae24%22%3E%3C%2Frect%3E%3Crect%20x%3D%226%22%20y%3D%223%22%20width%3D%221%22%20height%3D%221%22%20fill%3D%22%2361ae24%22%3E%3C%2Frect%3E%3Crect%20x%3D%223%22%20y%3D%225%22%20width%3D%222%22%20height%3D%221%22%20fill%3D%22%2361ae24%22%3E%3C%2Frect%3E%3Crect%20x%3D%226%22%20y%3D%225%22%20width%3D%222%22%20height%3D%221%22%20fill%3D%22%2361ae24%22%3E%3C%2Frect%3E%3Crect%20x%3D%224%22%20y%3D%229%22%20width%3D%224%22%20height%3D%223%22%20fill%3D%22%23000%22%3E%3C%2Frect%3E%3Crect%20x%3D%221%22%20y%3D%2211%22%20width%3D%2210%22%20height%3D%224%22%20fill%3D%22%23000%22%3E%3C%2Frect%3E%3Crect%20x%3D%220%22%20y%3D%2212%22%20width%3D%2212%22%20height%3D%223%22%20fill%3D%22%23000%22%3E%3C%2Frect%3E%3Crect%20x%3D%222%22%20y%3D%2213%22%20width%3D%221%22%20height%3D%221%22%20fill%3D%22%23fff%22%3E%3C%2Frect%3E%3Crect%20x%3D%223%22%20y%3D%2212%22%20width%3D%221%22%20height%3D%221%22%20fill%3D%22%23fff%22%3E%3C%2Frect%3E%3Crect%20x%3D%224%22%20y%3D%2213%22%20width%3D%221%22%20height%3D%221%22%20fill%3D%22%23fff%22%3E%3C%2Frect%3E%3Crect%20x%3D%225%22%20y%3D%2212%22%20width%3D%221%22%20height%3D%221%22%20fill%3D%22%23fff%22%3E%3C%2Frect%3E%3Crect%20x%3D%226%22%20y%3D%2213%22%20width%3D%221%22%20height%3D%221%22%20fill%3D%22%23fff%22%3E%3C%2Frect%3E%3Crect%20x%3D%227%22%20y%3D%2212%22%20width%3D%221%22%20height%3D%221%22%20fill%3D%22%23fff%22%3E%3C%2Frect%3E%3Crect%20x%3D%228%22%20y%3D%2213%22%20width%3D%221%22%20height%3D%221%22%20fill%3D%22%23fff%22%3E%3C%2Frect%3E%3Crect%20x%3D%229%22%20y%3D%2212%22%20width%3D%221%22%20height%3D%221%22%20fill%3D%22%23fff%22%3E%3C%2Frect%3E%3C%2Fsvg%3E');}.rc-scout__link:link,.rc-scout__link:visited{color:#61ae24;text-decoration:underline;}.rc-scout__link:hover,.rc-scout__link:active{color:#4e8b1d;}</style>
</footer>
<script type="text/rocketscript">
(function(){
var twitterWidgets = document.createElement('script');
twitterWidgets.type = 'text/javascript';
twitterWidgets.async = true;
twitterWidgets.src = 'http://platform.twitter.com/widgets.js';
document.getElementsByTagName('head')[0].appendChild(twitterWidgets);
})();
</script>
</div>
</body>
</html>