<?xml version="1.0" encoding="UTF-8" standalone="yes"?><oembed><version><![CDATA[1.0]]></version><provider_name><![CDATA[The ryg blog]]></provider_name><provider_url><![CDATA[https://fgiesen.wordpress.com]]></provider_url><author_name><![CDATA[fgiesen]]></author_name><author_url><![CDATA[https://fgiesen.wordpress.com/author/fgiesen/]]></author_url><title><![CDATA[Negative space in&nbsp;programming]]></title><type><![CDATA[link]]></type><html><![CDATA[<p>There&#8217;s a lot of material out there about code; how to design it, write it, document it, build it and test it. It is, after all, the primary artifact we programmers produce (okay, that and long rants about why we&#8217;re right and almost everyone else is wrong). Considerably less attention is paid to what&#8217;s not there &#8211; the design alternatives that were rejected, the features that were omitted, the interfaces that got changed because they were too complicated/subtle to explain properly in the docs, the lack of excessive dependencies that helps keep build times down, the tests that aren&#8217;t necessary because certain types of errors are made impossible by the design of a system.</p>
<p>I think that&#8217;s a mistake. In my experience, the main way we actually give our programs shape is not by putting things in, but by leaving them out. An elegant program is not one that checks off all the bullet points from some arbitrary feature list; it&#8217;s one that solves the problem it&#8217;s meant to solve and does so concisely. Its quality is not that it does what it&#8217;s supposed to; it&#8217;s that it does almost nothing else. And make no mistake, picking the right problem to solve in the first place is hard, and more of an art than a science. If you&#8217;ve ever worked on a big program, you&#8217;ve probably experienced this first-hand: You want to &#8220;just quickly add that one feature&#8221;, only to discover hours (or days, or even weeks) later that it turns out to be the straw that breaks the camel&#8217;s back. At that point, there&#8217;s usually little to do except take one last glance at the wreckage, sigh, and revert your changes.</p>
<p>So here&#8217;s my first point: Next time you get into that situation, write down what you tried and why it didn&#8217;t work. No need to turn it into an essay; a few short paragraphs are usually plenty. If it&#8217;s something directly related to design choices in the code, put it into comments in that piece of code; if the issues stem from the architecture of your system, put it into your Docs/Wiki or at least write a mail. But make sure it&#8217;s documented somewhere; when working on any piece of code, knowing what doesn&#8217;t work is at least as important as knowing what does. The latter is usually well-documented (or at least known), but the former often isn&#8217;t &#8211; no one even knows the brick wall is there until the first person runs into it and gets a bloody nose.</p>
<p>Second point: If you&#8217;re thinking about rewriting a piece of code, be very aware that the problem is not one of deleting X lines of code and writing Y lines to replace it. Nor is it one of understanding the original data structures and implementation strategies and improving of them; even if the approach is fine and you&#8217;re just re-implementing the same idea with better code, it&#8217;s never that simple. What I&#8217;ve consistently found to be the biggest problem in replacing code is all the unspoken assumptions surrounding it: the API calls it doesn&#8217;t use because they don&#8217;t quite do the right thing, the unspecified behavior or side-effects that other pieces of code rely on, the problems it doesn&#8217;t need to deal with because they&#8217;re avoided by design.</p>
<p>When reading code, looking at what a program does (and how it does it) is instructive. But figuring out what it doesn&#8217;t do (and why) can be positively enlightening!</p>
]]></html></oembed>