<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Code Simplicity &#187; Laws of Software</title>
	<atom:link href="http://www.codesimplicity.com/post/category/laws-of-software/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codesimplicity.com</link>
	<description></description>
	<lastBuildDate>Thu, 17 Nov 2011 19:00:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Readability and Naming Things</title>
		<link>http://www.codesimplicity.com/post/readability-and-naming-things/</link>
		<comments>http://www.codesimplicity.com/post/readability-and-naming-things/#comments</comments>
		<pubDate>Tue, 25 Jan 2011 19:00:38 +0000</pubDate>
		<dc:creator>Max Kanat-Alexander</dc:creator>
				<category><![CDATA[Laws of Software]]></category>

		<guid isPermaLink="false">http://www.codesimplicity.com/?p=797</guid>
		<description><![CDATA[Many people think that the readability of code has to do with the letters and symbols used. They believe it is the adding, removing, or changing of those symbols that makes code more readable. In some sense, they&#8217;re right. However, the underlying principle is:

  Readability of code depends primarily on how space is occupied [...]]]></description>
			<content:encoded><![CDATA[<p>Many people think that the readability of code has to do with the letters and symbols used. They believe it is the adding, removing, or changing of those symbols that makes code more readable. In some sense, they&#8217;re right. However, the underlying principle is:</p>
<blockquote><p>
  <strong>Readability of code depends primarily on how <em>space</em> is occupied by letters and symbols.</strong>
</p></blockquote>
<p>What does that mean? Well, it means two things: <span id="more-797"></span></p>
<h3>Code should have the proper amount of white space around it. Not too much, not too little.</h3>
<p>There should be the proper amount of space within a line of code to separate out the different parts. Separate actions should generally be on separate lines. Indentation should be used appropriately to group blocks of code.</p>
<p>With this principle, it&#8217;s actually the <em>absence of code</em> that makes things readable. This is a general principle of life&#8211;for example, if there was no space <em>at all</em> between letters and words in a book, it would be hard to read. On the other hand, it&#8217;s easy to see the moon against the clear night, because there&#8217;s a lot of clear black space that <em>isn&#8217;t</em> the moon. Similarly, when your code has the right amount of space in it, you can tell where and what the code is easily.</p>
<p>For example, this code is hard to read:</p>
<pre>x=1+2;y=3+4;z=x+y;print"hello world";print"z is"+z;if(z>y+x){print"error";}</pre>
<p>Whereas with the proper spacing in, around, and between the lines, it becomes easy to read:</p>
<pre>x = 1 + 2;
y = 3 + 4;
z = x + y;
print "hello world";
print "z is" + z;
if (z > y + x) {
    print "error";
}</pre>
<p>There can also be <em>too much</em> or <em>wrong</em> space, however. This code is also hard to read:</p>
<pre>    x            =          1+        2;
y = 3            +4;

  z = x    +      y;
print    "hello world"         ;
 print "z is " + z;
if (z  >     y+x)
 {        print "error" ;
        }</pre>
<h3>Code itself should take up space in proportion to how much meaning it has.</h3>
<p>Basically, tiny symbols that mean a <em>lot</em> make code hard to read. Very long names that don&#8217;t mean much also make code hard to read. The <em>amount</em> of meaning and the space taken up should be closely related to each other.</p>
<p>For example, this code is unreadable because the names are too small:</p>
<pre>q = s(j, f, m);
p(q);</pre>
<p>The space those names take up is very little compared to how much meaning they have. However, with appropriately-sized names, it becomes more apparent what that block of code is doing:</p>
<pre>quarterly_total = sum(january, february, march);
print(quarterly_total);</pre>
<p>On the other hand, if the names are too long compared to how much meaning they represent, then the code becomes hard to read again:</p>
<pre>quarterly_total_for_company_x_in_2011_as_of_today = add_all_of_these_together_and_return_the_result(january_total_amount, february_total_amount, march_total_amount);
send_to_screen_and_dont_wait_for_user_to_respond(quarterly_total_for_company_x_in_2011_as_of_today);</pre>
<p>This principle applies just as well to entire blocks of code as it does to individual names. We could replace the entire block of code above with a single function call:</p>
<pre>print_quarterly_total();</pre>
<p>And that is even more readable than any of the previous examples. Even though the name we used&#8211;<code>print_quarterly_total</code>&#8211;is a bit longer than our other names for things, that&#8217;s okay because it represents <em>more</em> meaning than other pieces of code do. In fact, it&#8217;s even <em>more</em> readable than our block of code was, by itself. Why is that? Because the code block took up a lot of space for, effectively, very little meaning, and the function takes up a more reasonable amount of space for the same meaning.</p>
<p>If a block of code takes up a lot of space but doesn&#8217;t actually have much meaning, then it&#8217;s a good candidate for refactoring. For example, here&#8217;s a block of code that handles some user input:</p>
<pre>x_pressed = false;
y_pressed = false;
if (input == "x") {
    print "You pressed x!";
    x_pressed = true;
}
else if (input == "y") {
    if (not y_pressed) {
        print "You pressed y for the first time!";
        y_pressed = true;
        if (x_pressed) {
            print "You pressed x and then y!";
        }
    }
}</pre>
<p>If that were our whole program, that would probably be readable enough. However, if this is within a lot of other code, we could make it more readable like this:</p>
<pre>x_pressed = false;
y_pressed = false;
if (input == "x") {
    handle_x(x_pressed);
}
else if (input == "y") {
    handle_y(x_pressed, y_pressed);
}</pre>
<p>And we could make it even more readable by reducing it to this:</p>
<pre>handle_input(input);</pre>
<p>Reading &#8220;handle_input&#8221; in the middle of our code is much easier than trying to read that whole first block, above, because &#8220;handle_input&#8221; is taking up the right amount of space, and the block is taking up too much space. Note, however, if we&#8217;d done something like <code>h(input)</code> instead, that would be confusing and unreadable because &#8220;h&#8221; is too short to properly tell us what the code is doing. Also, <code>handle_this_input_and_figure_out_if_it_is_x_or_y_and_then_do_the_right_thing(input)</code> would not only be annoying for a programmer to type, but would also make for unreadable code.</p>
<h3>Naming Things</h3>
<p>It was once said by a famous programmer that naming things was one of the hardest problems in computer science. These principles of readability give us some good clues on how to name things, though. Basically, the name of a variable, function, etc. should be long enough to fully communicate what it is or does, without being so long that it becomes hard to read.</p>
<p>It&#8217;s also important to think about how the function or variable is going to be used. Once we start putting it into lines of code, will it make those lines of code <em>too long</em> for how much meaning they actually have? For example, if you have a function that is only called once, on one line all by itself, with no other code in that line, then it can have a fairly long name. However, a function that you&#8217;re going to use frequently in complex expressions should probably have a name that is short (though still long enough to fully communicate what it does).</p>
<p>-Max</p>
<p><a href="http://www.codesimplicity.com/post/readability-and-naming-things/#comments">Comments: 24</a></p><hr style="margin: 0; margin-top: 0.5em; border: none; border-top: 1px solid black; width: 1.5em"><p>Code Simplicity is brought to you by <a href="http://www.codesimplicity.com/about/">Max Kanat-Alexander</a> and <a href="http://www.bugzillasource.com">BugzillaSource</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.codesimplicity.com/post/readability-and-naming-things/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Software Design, In Two Sentences</title>
		<link>http://www.codesimplicity.com/post/software-design-in-two-sentence/</link>
		<comments>http://www.codesimplicity.com/post/software-design-in-two-sentence/#comments</comments>
		<pubDate>Thu, 13 May 2010 19:00:29 +0000</pubDate>
		<dc:creator>Max Kanat-Alexander</dc:creator>
				<category><![CDATA[Laws of Software]]></category>

		<guid isPermaLink="false">http://www.codesimplicity.com/?p=495</guid>
		<description><![CDATA[In the context of The Equation of Software Design, it is now possible to reduce the primary principles of software design into just two statements:

It is more important to reduce the Effort of Maintenance than it is to reduce the Effort of Implementation.
The Effort of Maintenance is proportional to the complexity of the system.

And that [...]]]></description>
			<content:encoded><![CDATA[<p>In the context of <a href="/post/the-equation-of-software-design/">The Equation of Software Design</a>, it is now possible to reduce the primary principles of software design into just two statements:</p>
<ol style="font-weight: bold; font-size: 120%">
<li style="margin-bottom: 1em">It is more important to reduce the Effort of Maintenance than it is to reduce the Effort of Implementation.</li>
<li>The Effort of Maintenance is proportional to the complexity of the system.</li>
</ol>
<p>And that is pretty much <em>it</em>. If all you knew about software design were those two principles and <a href="/post/the-purpose-of-software/">the purpose of software</a>, you could evolve every other general principle of software development.</p>
<p>-Max</p>
<p><a href="http://www.codesimplicity.com/post/software-design-in-two-sentence/#comments">Comments: 8</a></p><hr style="margin: 0; margin-top: 0.5em; border: none; border-top: 1px solid black; width: 1.5em"><p>Code Simplicity is brought to you by <a href="http://www.codesimplicity.com/about/">Max Kanat-Alexander</a> and <a href="http://www.bugzillasource.com">BugzillaSource</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.codesimplicity.com/post/software-design-in-two-sentence/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>The Equation of Software Design</title>
		<link>http://www.codesimplicity.com/post/the-equation-of-software-design/</link>
		<comments>http://www.codesimplicity.com/post/the-equation-of-software-design/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 20:31:53 +0000</pubDate>
		<dc:creator>Max Kanat-Alexander</dc:creator>
				<category><![CDATA[Laws of Software]]></category>

		<guid isPermaLink="false">http://www.codesimplicity.com/?p=463</guid>
		<description><![CDATA[So today I was playing around with a little equation that may in fact explain nearly all of the principles of software design.  I don&#8217;t know that it&#8217;s actually mathematically solvable in terms of numbers, but it does demonstrate the factors present in software development decisions and how they relate to each other. Before [...]]]></description>
			<content:encoded><![CDATA[<p>So today I was playing around with a little equation that may in fact explain nearly all of the principles of software design. <span id="more-463"></span> I don&#8217;t know that it&#8217;s actually mathematically solvable in terms of numbers, but it does demonstrate the factors present in software development decisions and how they relate to each other. Before I go into the equation, though, I have to define the factors that are present when a designer is deciding whether or not to implement something, or how to implement it:</p>
<ul>
<li><strong>Potential Value of Implementation</strong> (V<sub>i</sub> for short): How &#8220;valuable&#8221; <em>could</em> it be to implement this? For example, if we add something to the program that <em>could</em> directly prevent somebody from dying, that&#8217;s very valuable. If it simply <em>might</em> prevent a future  typo in a single error message, that&#8217;s hardly valuable at all.
<p>The &#8220;value&#8221; can be for the end user or for other programmers. When we&#8217;re talking about design decisions that affect only code, and not the end user, <em>flexibility</em> is one of the major values&#8211;how important <em>could</em> this flexibility be?</p>
<p>The potential value is separate from how <em>likely</em> it is that the situation will occur where you will need it. That&#8217;s the next issue.</p>
</li>
<li><strong>Probability of Value</strong> (P<sub>v</sub> for short): What is the chance that this value will be, in fact, realized by an end user (for a feature or functional change) or by another developer (for some design decision)? If we&#8217;re adding in code flexibility to allow for potential contact with extraterrestrial apes, that&#8217;s not a very <em>probable</em> occurrence. If we&#8217;re adding in a feature that is immediately useful to every single user, that&#8217;s 100% probability. (The number of users that a feature will be useful to is also part of the Probability of Value.)</li>
<li><strong>Effort of Implementation</strong> (E<sub>i</sub> for short): How hard will it be to implement this? This is a one-time cost&#8211;the immediate difficulty of performing the work required to create this thing the very first time. This would probably be measured in person-hours.</li>
<li><strong>Effort of Maintenance</strong> (E<sub>m</sub> for short): How much effort will it require to maintain this in the future? (This includes any effort added to maintaining the entire program by implementing this.) Will this complicate maintenance for the whole system? This is an amount that increases over time. Similar to Effort of Implementation, this would be most likely measured in person-hours.</li>
</ul>
<p>What we&#8217;re trying to determine is the <strong>Desirability Of Implementation</strong> (D for short). This answers the questions &#8220;Is this something we should do or not?&#8221; and &#8220;What should the priority of implementing this be?&#8221;</p>
<p>The simplest form of the equation is:</p>
<blockquote><p>
D = (P<sub>v</sub> * V<sub>i</sub>) / (E<sub>i</sub> + E<sub>m</sub>)
</p></blockquote>
<p>Or, in English:</p>
<blockquote><p>
The Desirability of Implementation is directly proportional to the Probability of Value and the Potential Value of Implementation, and inversely proportional to the total effort, consisting of the Effort of Implementation plus the Effort of Maintenance.
</p></blockquote>
<p>However, there is a critical factor missing from the simple form of this equation: <em>time</em>. What we actually want to know is <strong>the limit of this equation as time approaches infinity</strong>, and that gives us the true Desirability of Implementation. So let&#8217;s look at this from a logical standpoint:</p>
<p>The Effort of Implementation is a one-time cost, and never changes, so is mostly unaffected by time.</p>
<p>The Value of Implementation may increase or decrease over time, depending on the feature. It&#8217;s not predictable, and so we can assume for the sake of this equation that it is a static value that does not change with time (though if that&#8217;s not the case in your situation, keep this factor in mind as well). One could even consider that the Effort of Maintenance is actually &#8220;the effort required to maintain this exact level of Value,&#8221; so that the Value would indeed remain totally fixed over time.</p>
<p>The Probability of Value, being a probability, approaches 1 (100%) as time goes to infinity.</p>
<p>The Effort of Maintenance, being based on time, approaches infinity as time goes to infinity.</p>
<p>At first glance, that might sound as though design is hopeless, because maintenance becomes infinite effort&#8211;an amount that no Potential Value could surpass&#8211;and it seems like <em>every</em> possibility must be accounted for, because given infinite time the probability seems to indicate that every possibility will occur. Those are not true statements, though, because you have to think about the <em>rate</em> at which both of those items increase. If the fundamental effort of maintenance is very small, then even as time goes on, it will remain small. You could say that there is a &#8220;coefficient of maintenance&#8221; on any design decision or feature, and that that determines how rapidly maintenance effort will accumulate over time. As far as the Probability of Value goes, if it is a very tiny number, it may remain tiny until thousands or millions of years have passed&#8211;so if the Effort of Maintenance increases at a great rate, then it will easily outstrip the Probability of Value and the Desirability of Implementation will approach zero as time approaches infinity.</p>
<p>What this equation <em>actually</em> tells us is that the most important factors to balance, in terms of time, are probability of value vs. effort of maintenance. If the probability of value is high and the effort of maintenance is low, the desirability is then dependent only upon the Potential Value of Implementation vs. the Effort of Implementation&#8211;a decision that a product manager can easily make. If the probability of value is low and the effort of maintenance is high, the only justification for implementation would be a near-infinite Potential Value of Implementation.</p>
<p>This interestingly indicates why small improvements in programming languages and development frameworks result in such enormous changes in the resulting products&#8211;because tiny reductions in the Effort of Maintenance can make tremendous changes in the Desirability of Implementation. Features that otherwise would be thrown away by a product manager as impossible become part of the basic design plan. Polishing the UI becomes more desirable, because it requires less effort for both implementation and maintenance.</p>
<p>And finally, I think that this communicates most exactly and truthfully why simplicity is so important&#8211;because <em>simplicity</em> is what determines the &#8220;coefficient of maintenance&#8221; that I talked about above. The effort involved in maintaining simple code increases very slowly over time&#8211;sometimes so slowly that you <em>never</em> will have to put any maintenance effort into it in your lifetime.</p>
<p>There&#8217;s a lot more that could be said about this equation. What are your thoughts on it? Anybody have any ideas of how Value of Implementation could be numerically calculated, or if it might break down into a set of other numerically-calculable factors? Anything you have to say about it, I&#8217;m interested.</p>
<p>-Max</p>
<p><a href="http://www.codesimplicity.com/post/the-equation-of-software-design/#comments">Comments: 24</a></p><hr style="margin: 0; margin-top: 0.5em; border: none; border-top: 1px solid black; width: 1.5em"><p>Code Simplicity is brought to you by <a href="http://www.codesimplicity.com/about/">Max Kanat-Alexander</a> and <a href="http://www.bugzillasource.com">BugzillaSource</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.codesimplicity.com/post/the-equation-of-software-design/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Features, Simplicity, and the Purpose of Software</title>
		<link>http://www.codesimplicity.com/post/features-simplicity-and-the-purpose-of-software/</link>
		<comments>http://www.codesimplicity.com/post/features-simplicity-and-the-purpose-of-software/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 18:50:25 +0000</pubDate>
		<dc:creator>Max Kanat-Alexander</dc:creator>
				<category><![CDATA[Laws of Software]]></category>

		<guid isPermaLink="false">http://www.codesimplicity.com/?p=98</guid>
		<description><![CDATA[One of the best ways to keep an app simple is, of course, to limit how many features you implement. Twitter, for example, has very few features, but is enormously successful. The limited number of features of Twitter make it really easy to keep the application simple, which lets the developers focus a lot on [...]]]></description>
			<content:encoded><![CDATA[<p>One of the best ways to keep an app simple is, of course, to limit how many features you implement. <a href="http://twitter.com/">Twitter</a>, for example, has very few features, but is enormously successful. The limited number of features of Twitter make it really easy to keep the application simple, which lets the developers focus a lot on the quality of the system, the polish of each individual feature, etc.</p>
<p>Twitter&#8217;s just one of the many proofs that you don&#8217;t have to have lots of features to be successful. In fact, many successful apps have <em>fewer</em> features than their less-successful competitors.</p>
<p>Still, you&#8217;ve got to have <em>some</em> features. <img src='http://www.codesimplicity.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  After all, it&#8217;d be pretty silly to be programming, otherwise. But how do you decide which features you <em>should</em> have? Is it just up to the Chief Architect&#8217;s intuition, or how many users demand that you give them &#8220;feature X&#8221;? Does whoever shouts the loudest in the development meeting get their feature implemented first? </p>
<p>Well, no, there is a way to decide whether or not you should implement a feature, and it comes out of one of our most basic principles: the <a href="/archives/21">purpose of software</a>. This principle (that the purpose of software is &#8220;to help people&#8221;) isn&#8217;t just some fancy-sounding gibberish I made up to make myself happy&#8211;I wrote it because it&#8217;s something that can actually be really useful to think about in everyday programming, and this question of &#8220;Should we implement this feature?&#8221; gives us a great opportunity to show how it can be applied.  <span id="more-98"></span></p>
<p>So, let&#8217;s say that the purpose of your software is &#8220;to help people learn to type,&#8221; and you have to decide, &#8220;Should we add New Feature X?&#8221; Well, here&#8217;s what you can ask yourself about the feature: &#8220;Does this <em>help people learn to type</em>?&#8221; Simple. <img src='http://www.codesimplicity.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  If the answer is no, then you don&#8217;t implement the feature. Also, &#8220;Does this harm people learning to type, or get in the way of learning to type?&#8221; If it harms people more than it helps them, then it shouldn&#8217;t be implemented.</p>
<p>Now, quite often, you&#8217;ll find that you can&#8217;t really say whether or not a proposed feature actually helps your users (or helps them more than it hinders them). You can&#8217;t stand there with certainty and say, &#8220;Yes, this absolutely helps people learn to type.&#8221; In that case, just skip it. Don&#8217;t implement the feature. There are plenty of features out there in the world where you can be <em>sure</em> that it will help your users&#8211;implement those instead. Perhaps some more data will come along in time that will make your decision clearer about this uncertain feature, but until then, you don&#8217;t have to implement it. Just wait (or go collect data to make your decision easier).</p>
<p>This whole idea is also very handy for prioritizing features. You ask yourself, &#8220;Out of all these features, which ones will <em>most</em> help people learn to type?&#8221; That sounds perhaps like an overly-simple suggestion, but I think that for <a href="http://www.bugzilla.org/">Bugzilla</a>, if we really looked at all our requested features and said, &#8220;Which one of these will most help people <em>track bugs</em>?&#8221; we&#8217;d come up with a pretty good priority list, and probably have some interesting discussions, too.</p>
<p>The higher you set the bar for certainty on these questions, the fewer features you will have, and the simpler your application will be. That is, you could say, &#8220;We have to only be kinda certain it will help people,&#8221; and that&#8217;s your standard (or &#8220;bar&#8221;) for helpfulness. Or you could say, &#8220;We only implement features that we are <em>totally certain</em> will help people,&#8221; and you&#8217;d probably have an enormously simple and very well-designed application. But it&#8217;s  a judgment call&#8211;sometimes it&#8217;s hard to get data, and you have to implement features that you&#8217;re only <em>pretty sure</em> will be helpful. That can be the right decision, though, sometimes&#8211;different situations require different solutions.</p>
<p>Overall, <em>how</em> you make these decisions is up to you. What really matters is that you <em>ask the questions</em>. That&#8217;s one of the keys to keeping your product focused, simple, and polished.</p>
<p>-Max</p>
<p><a href="http://www.codesimplicity.com/post/features-simplicity-and-the-purpose-of-software/#comments">Comments: 5</a></p><hr style="margin: 0; margin-top: 0.5em; border: none; border-top: 1px solid black; width: 1.5em"><p>Code Simplicity is brought to you by <a href="http://www.codesimplicity.com/about/">Max Kanat-Alexander</a> and <a href="http://www.bugzillasource.com">BugzillaSource</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.codesimplicity.com/post/features-simplicity-and-the-purpose-of-software/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>(I)SAR Clarified</title>
		<link>http://www.codesimplicity.com/post/isar-clarified/</link>
		<comments>http://www.codesimplicity.com/post/isar-clarified/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 20:00:43 +0000</pubDate>
		<dc:creator>Max Kanat-Alexander</dc:creator>
				<category><![CDATA[Laws of Software]]></category>

		<guid isPermaLink="false">http://www.codesimplicity.com/?p=75</guid>
		<description><![CDATA[In my previous post, I said that there are three major parts to any computer program: Structure, Action, and Results. Also, a program has Input, which could be considered a fourth part of the program, although usually it&#8217;s not the programmer who&#8217;s creating the input, but the user. So we can either abbreviate this as [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="/archives/49">previous post</a>, I said that there are three major parts to any computer program: <em>Structure</em>, <em>Action</em>, and <em>Results</em>. Also, a program has <em>Input</em>, which could be considered a fourth part of the program, although usually it&#8217;s not the <em>programmer</em> who&#8217;s creating the input, but the user. So we can either abbreviate this as <abbr title="Structure, Action, Results">SAR</abbr> or <abbr title="Input, Structure, Action, Results">ISAR</abbr>, depending on whether or not we want to include &#8220;Input.&#8221;</p>
<p>Now, some people misunderstood me and said, &#8220;Oh, SAR is just another name for <a href="http://en.wikipedia.org/wiki/Model-view-controller">MVC</a>.&#8221; No, I used MVC as an example of SAR, but SAR is a much, much broader concept than MVC&#8211;they are not comparable theories. MVC is a pattern for designing software, whereas SAR (or ISAR) is a statement of the three (or four) components that are present in <em>all software</em>.</p>
<p>The fascinating thing about SAR is that it applies not only to a whole program, but also to any <em>piece</em> of that program. A whole program has a Structure, just as a function or single line of code has a Structure. Same for Action and Results.</p>
<p>Here&#8217;s a little more about each of the pieces, and some examples to help explain:</p>
<h3>Structure</h3>
<p>Here are some examples of things that would be considered &#8220;Structure&#8221; for the whole program:<span id="more-75"></span></p>
<ul>
<li>The directory layout of your code.</li>
<li>All of the classes and how they relate to each other.</li>
<li>The structure (schema) of the database, if your program uses a database.
<p>    Note here that the actual data <em>in</em> the database isn&#8217;t part of the Structure, though. If your program is <em>producing</em> the data and then sticking it into the database, then that&#8217;s part of the <em>Result</em>. If the data is sitting in the database and your program is supposed to process it, then that data is part of the <em>Input</em>.
  </li>
</ul>
<p>Then an individual class (and I mean a &#8220;class&#8221; in the object-oriented sense) would also have a Structure:</p>
<ul>
<li>The names of methods in the class and the types/names of parameters that they take.</li>
<li>The names and types of variables (member variables) in the class.</li>
</ul>
<p>Whether or not a function (or variable) is private or public would also be part of the Structure, because Structure describes what something <em>is</em> (as opposed to what it <em>does</em> or <em>produces</em>), and &#8220;private&#8221; or &#8220;public&#8221; are words that describe what something <em>is</em>.</p>
<p>A Structure is sort of &#8220;the components of the program&#8221; or &#8220;the pieces you make the program out of.&#8221; Function names and types, variable names and types, classes&#8211;these things are all <em>Structure</em>.</p>
<p>Structure just &#8220;sits there.&#8221; It doesn&#8217;t <em>do</em> anything unless there&#8217;s some part of your program that <em>uses</em> it. For example, a method doesn&#8217;t call <em>itself</em>, it just sits there waiting to be called. A variable doesn&#8217;t put data into itself, it just sits there waiting for you to do something with it.</p>
<h3>Action</h3>
<p>The <em>Action</em> of a whole program is very easy to understand. A tax program &#8220;does taxes.&#8221; A calculator program &#8220;does math.&#8221;</p>
<p>An Action is always a <em>verb</em> of some sort. &#8220;Calculates.&#8221; &#8220;Fixes.&#8221; &#8220;Adds.&#8221; &#8220;Removes.&#8221; Those are <em>actions</em>. Usually they&#8217;re a little more descriptive and specific, though, like, &#8220;Calculates how much rainfall there will be in Africa next year,&#8221; or &#8220;Fixes broken hard drives.&#8221;</p>
<p>Inside of a class, the <em>Action</em> is the code <em>inside</em> of the methods. That&#8217;s all some sort of <em>action</em>&#8211;something going on, something happening. In many programming languages, you can also have code outside of any class or function&#8211;code that just <em>runs</em> when you start the program. That&#8217;s <em>Action</em>.</p>
<h3>Results</h3>
<p>Every program, every function, and every line of code has some <em>effect</em>. It produces some <em>result</em>. </p>
<p>A Result can always be talked about in the <em>past tense</em>&#8211;it&#8217;s something that <em>has been</em> done or created. &#8220;Calculated rainfall,&#8221; or &#8220;Fixed hard drives.&#8221;  In a tax program, we&#8217;d call the Result either <em>filed taxes</em> or <em>filled-out tax forms</em>. As you can see, it sounds a lot like the Action, just <em>completed</em>.</p>
<p>You don&#8217;t <em>have</em> to describe a Result in the past tense, though. I&#8217;m just saying it always <em>can be</em> described that way. For example, in a calculator program, normally we&#8217;d call the Result of addition &#8220;the sum,&#8221; (not past-tense, just a noun) but you could also say that the Result is &#8220;added numbers&#8221; (which is past-tense). Same thing, just a different way of describing it.</p>
<p>Individual pieces of your program have Results, too. When you call a method or function, it has a very specific Result. It gives you back some data, or it causes some data to be changed.</p>
<p>Whatever your program (or any part of your program) <em>produces</em>, that&#8217;s the Result.</p>
<h3>ISAR in a Single Line of Code</h3>
<p>So, I said that SAR applies to a single line of code, but I didn&#8217;t give you any examples. So here&#8217;s a single line of code:</p>
<blockquote><p>
  <code>x = y + z</code>
</p></blockquote>
<p><code>y</code> and <code>z</code> in that line are part of the Structure. They&#8217;re variables that hold some data. To make an analogy: A jug is a structure that holds water. A variable is a structure that holds data. </p>
<p>The numbers that are stored inside <code>y</code> and <code>z</code> are the <em>Input</em>. That&#8217;s the data that we&#8217;re doing something with.</p>
<p><code>+</code> is an Action: &#8220;Add these two numbers.&#8221; <code>=</code> is also an Action: &#8220;Store the result in <code>x</code>.&#8221;</p>
<p>And, of course, the Result is the sum of <code>y</code> and <code>z</code> that gets stored in <code>x</code>. If <code>y</code> is 1 and <code>z</code> is 2, then the Result is the number 3, which gets stored in <code>x</code>. (Also note that <code>x</code> is a itself variable and thus also part of the Structure, but that&#8217;s getting pretty technical.)</p>
<h3>Wrapping It Up</h3>
<p>So anyhow, I hope that explains SAR a bit better. It&#8217;s a concept that applies to any kind of programming, whether you&#8217;re building a big application or just writing a single-line script. And it&#8217;s not something that you have to think about in-depth every time you write a piece of code, but it&#8217;s something that can help us analyze and understand a program, particularly when we&#8217;re looking at how we can improve its design.</p>
<p>-Max</p>
<p><a href="http://www.codesimplicity.com/post/isar-clarified/#comments">Comments: 4</a></p><hr style="margin: 0; margin-top: 0.5em; border: none; border-top: 1px solid black; width: 1.5em"><p>Code Simplicity is brought to you by <a href="http://www.codesimplicity.com/about/">Max Kanat-Alexander</a> and <a href="http://www.bugzillasource.com">BugzillaSource</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.codesimplicity.com/post/isar-clarified/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Structure, Action, and Results</title>
		<link>http://www.codesimplicity.com/post/structure-action-and-results/</link>
		<comments>http://www.codesimplicity.com/post/structure-action-and-results/#comments</comments>
		<pubDate>Sat, 01 Nov 2008 22:38:30 +0000</pubDate>
		<dc:creator>Max Kanat-Alexander</dc:creator>
				<category><![CDATA[Laws of Software]]></category>

		<guid isPermaLink="false">http://www.codesimplicity.com/?p=49</guid>
		<description><![CDATA[There&#8217;s a very popular model for designing software that we&#8217;ve all heard of if we&#8217;re web developers, and probably most desktop developers have heard of too: our old friend MVC. This works well because it reflects the basic nature of a computer program: a series of actions taken on a structure of data to produce [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a very popular model for designing software that we&#8217;ve all heard of if we&#8217;re web developers, and probably most desktop developers have heard of too: our old friend <abbr title="Model, View, Controller">MVC</abbr>. This works well because it reflects the basic nature of a computer program: a series of <strong>actions</strong> taken on a <strong>structure</strong> of data to produce a <strong>result</strong>. Programs also take input, and so you could possibly argue that input was a fourth part of a program, but usually I just think of a computer program as the first three parts: Structure, Action, and Results.</p>
<p>In the MVC sense, the Model is the Structure, the Controller is what does the Actions, and the View is the Result. I think the analogy (and the words) Structure, Action, and Results are more widely and accurately applicable to the operation of every program in existence, though, moreso than MVC, though MVC is a perfectly good way of looking at it for GUI applications.</p>
<p>Really, Structure, Action, and Results probably describes almost any machine in existence. A machine has some parts that don&#8217;t move, a framework&#8211;that&#8217;s the structure. Some parts move and do something&#8211;that motion is the action. And of course the machine produces something (otherwise we wouldn&#8217;t care much about it) so that&#8217;s the result.</p>
<p>Computer programs are unusual machines in that they can modify their own structure. However, it&#8217;s important that some part of the program be stable, that they &#8220;not move&#8221; in a logical sense. The way that object classes relate to each other, the names of methods and variables&#8211;these are all parts of the structure that usually don&#8217;t change while you&#8217;re running. (Sometimes you make new classes, methods, or variables while you&#8217;re running, but they usually follow some pre-set plan, so there&#8217;s still a lot of &#8220;not moving&#8221; involved.)</p>
<p>When I&#8217;m writing software, I usually build the Structure first, then I work on the Actions, and then I work on the displaying of the Result. Some people work backwards from the Results, that&#8217;s fine too. Probably the only inadvisable thing to do is to start with the Actions, since it&#8217;s kind of confusing to be performing Actions without a Structure and with no defined Result.</p>
<p>There&#8217;s so much to this concept that I could probably write a whole book just on this one topic, but I think this is a decent introduction, and I&#8217;m sure that given this, you can think of lots of other useful applications of it.</p>
<p>-Max</p>
<p><a href="http://www.codesimplicity.com/post/structure-action-and-results/#comments">Comments: 0</a></p><hr style="margin: 0; margin-top: 0.5em; border: none; border-top: 1px solid black; width: 1.5em"><p>Code Simplicity is brought to you by <a href="http://www.codesimplicity.com/about/">Max Kanat-Alexander</a> and <a href="http://www.bugzillasource.com">BugzillaSource</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.codesimplicity.com/post/structure-action-and-results/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simplicity and Security</title>
		<link>http://www.codesimplicity.com/post/simplicity-and-security/</link>
		<comments>http://www.codesimplicity.com/post/simplicity-and-security/#comments</comments>
		<pubDate>Fri, 17 Oct 2008 20:00:52 +0000</pubDate>
		<dc:creator>Max Kanat-Alexander</dc:creator>
				<category><![CDATA[Laws of Software]]></category>

		<guid isPermaLink="false">http://www.codesimplicity.com/?p=48</guid>
		<description><![CDATA[A big part of writing secure software (probably the biggest part) is simplicity.
When we think about software security, the first question that we ask is, &#8220;How many different ways could this program possibly be attacked?&#8221; That is, how many &#8220;ways in&#8221; are there? It&#8217;s a bit like asking &#8220;How many doors and windows are there [...]]]></description>
			<content:encoded><![CDATA[<p>A big part of writing secure software (probably the biggest part) is simplicity.</p>
<p>When we think about software security, the first question that we ask is, &#8220;How many different ways could this program possibly be attacked?&#8221; That is, how many &#8220;ways in&#8221; are there? It&#8217;s a bit like asking &#8220;How many doors and windows are there on this building?&#8221; If your building has 1 exterior door, it&#8217;s very easy to protect that door. If it has 1000, it will be impossible to keep the building secure, no matter how good the doors are or how many security guards you have.</p>
<p>So we need to limit the &#8220;ways in&#8221; to our software to some reasonable number, or it won&#8217;t ever be secure. That&#8217;s accomplished by making the <em>overall system</em> relatively simple, or breaking it down into very simple and totally separate component parts. </p>
<p>Then, once we&#8217;ve limited the ways in, we need to start thinking about &#8220;How many different possible attacks are there against each way in?&#8221; We limit that by making the ways in <em>themselves</em> very simple. Like a door with only one unique key, instead of a door that can take five different keys, all of which individually will open the door.</p>
<p>Once that&#8217;s done, we limit how much damage any attack could do if it got through. For example, in a building, we&#8217;d make any given door only allow access to one room.</p>
<p>All of this explains, for example, why Windows is fundamentally flawed and will <em>never</em> be secure, and why UNIX-based systems have a better reputation for security. <span id="more-48"></span></p>
<p>Standard UNIX has a very small number of system calls that are used to implement the vast majority of all UNIX programs out there. (Even the extended list is only about 140 system calls, though most of those are never used by the average program.) Each system call is extremely specific and does one very limited thing.</p>
<p>Windows, on the other hand, has a <a href="http://www.metasploit.com/users/opcode/syscalls.html">ridiculous set of system calls</a> that are confusing, take too many arguments, and do too much.</p>
<p>Going up to a higher level in the system, the <a href="http://msdn.microsoft.com/en-us/library/aa383686(VS.85).aspx">Windows API</a> is massive and complex. It&#8217;s a strange beast that controls both the OS and the GUI. There&#8217;s really no equivalent thing in UNIX (because the OS and the GUI are separate), but we can at least compare parts of it. Here&#8217;s <a href="http://msdn.microsoft.com/en-us/library/bb540361(VS.85).aspx">The Windows Logging API</a>. Here&#8217;s <a href="http://www.gnu.org/software/libc/manual/html_node/Submitting-Syslog-Messages.html#Submitting-Syslog-Messages">the Linux Logging API</a>. There&#8217;s just no comparison. It&#8217;s like a joke. There&#8217;s so many &#8220;ways in&#8221; to any part of Windows that it will <em>never</em> be fundamentally secure.</p>
<p>You might say, &#8220;Well, I haven&#8217;t had a virus on my Windows machine in a long time.&#8221; That&#8217;s not what I&#8217;m talking about&#8211;I&#8217;m talking about <em>fundamental</em> security. In order to have a secure Windows machine, you have to have a firewall that asks you every time a program wants to make an outbound connection. You have to have a spyware scanner. You have to have <a href="http://www.thepcspy.com/read/what_really_slows_windows_down/5">antivirus software that slows down your computer by as much as 2000%</a>. If Windows was <em>secure</em>, you wouldn&#8217;t need those things.</p>
<p>When we design our own systems, keeping them simple is the only real guarantee of security. We keep each &#8220;way in&#8221; to the system as simple as possible, and we never add more &#8220;ways in&#8221; than we absolutely need. These are compatible things, too, because the simpler each &#8220;way in&#8221; is, the <em>fewer</em> we&#8217;ll actually need. That may not make sense until you think about it this way: If all actions on the system can be reduced to, say, 13 fundamental function calls, then the user can do <em>everything</em> with those 13 calls, even if they&#8217;re not very powerful individually. If instead we only let them do 100 different specific tasks, and <em>don&#8217;t</em> allow them to use the 13 fundamental calls, we have to add a new function for <em>every specific task</em>.</p>
<p>There are lots of other &#8220;ways in&#8221; to a program than just its public API, too. How the user interface interacts with the backend&#8211;that involves various &#8220;ways in&#8221;. Can we access this program&#8217;s internal structure from another program? That would be another &#8220;way in.&#8221; There&#8217;s <em>lots</em> of ways to apply this principle. </p>
<p>Any way you slice it, though, the best way to get real security in things is <em>simplicity</em>. We shouldn&#8217;t have to put a small army in front of our software just to keep it secure. It should just fundamentally have so few &#8220;ways in&#8221; that it doesn&#8217;t need the protection, and those &#8220;ways in&#8221; should be so streamlined and simple that they&#8217;re impossible to exploit.</p>
<p>-Max</p>
<p><a href="http://www.codesimplicity.com/post/simplicity-and-security/#comments">Comments: 14</a></p><hr style="margin: 0; margin-top: 0.5em; border: none; border-top: 1px solid black; width: 1.5em"><p>Code Simplicity is brought to you by <a href="http://www.codesimplicity.com/about/">Max Kanat-Alexander</a> and <a href="http://www.bugzillasource.com">BugzillaSource</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.codesimplicity.com/post/simplicity-and-security/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>What Is A Computer?</title>
		<link>http://www.codesimplicity.com/post/what-is-a-computer/</link>
		<comments>http://www.codesimplicity.com/post/what-is-a-computer/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 18:00:49 +0000</pubDate>
		<dc:creator>Max Kanat-Alexander</dc:creator>
				<category><![CDATA[Laws of Software]]></category>

		<guid isPermaLink="false">http://www.codesimplicity.com/?p=47</guid>
		<description><![CDATA[What is a computer? You&#8217;d think that would be a fairly simple question. After all, I&#8217;m using one to type this up, I ought to know what it is, right? I mean obviously, it&#8217;s a&#8230;computer! I mean, it&#8217;s got a keyboard, and a monitor, and there&#8217;s that box down there&#8230;
But what is it that makes [...]]]></description>
			<content:encoded><![CDATA[<p>What is a computer? You&#8217;d think that would be a fairly simple question. After all, I&#8217;m using one to type this up, I ought to know what it is, right? I mean obviously, it&#8217;s a&#8230;computer! I mean, it&#8217;s got a keyboard, and a monitor, and there&#8217;s that box down there&#8230;</p>
<p>But what is it that makes all that stuff a <em>computer</em>? Why do we look at it and go, &#8220;Oh yeah, that&#8217;s a computer,&#8221; as opposed to, say, &#8220;Oh, that&#8217;s just a TV,&#8221; or &#8220;That&#8217;s where I keep the leprechauns at night.&#8221;?</p>
<p>Some people try to define the word &#8220;computer&#8221; just by saying &#8220;it&#8217;s got such and such parts and they all work this way,&#8221; but that&#8217;s like saying &#8220;airplanes have two wings and jet engines.&#8221; It&#8217;s true, but I could build an airplane that <em>didn&#8217;t</em> have two wings or jet engines. The way something <em>works</em> is not a <em>definition</em> for that thing.</p>
<p>Others try to define it mathematically, but that can also be somewhat limiting, because then only the devices that fit into your mathematical scheme are computers, and there are multiple mathematical models that would all be considered &#8220;computers.&#8221;</p>
<p>So I turned to the dictionary. That was fun for me&#8211;I&#8217;m a dictionary fanatic. I&#8217;ve got lots of great dictionaries, and there are even more online. The Compact Oxford English Dictionary had <a href="http://www.askoxford.com/concise_oed/computer?view=uk">the best definition</a>, as it turned out.. I was very happy with it at first, but when I started to think about it, it didn&#8217;t quite work. For example, it calls computers &#8220;an electronic device,&#8221; and we know that <a href="http://www.maxmon.com/1830ad.htm">computers can be built without electronics</a>.</p>
<p>So I worked to come up with a definition of my own. Strangely enough, the key question that it boiled down to was &#8220;Why is a player piano <em>not</em> a computer?&#8221; It &#8220;processes information&#8221; by playing notes from its roll. If you gave it an etching machine, it could &#8220;store information&#8221; back on to the roll. But despite all that, it&#8217;s clearly not a computer. What is a computer doing that is fundamentally different from a player piano, that a player piano could <em>never</em> do? <span id="more-47"></span></p>
<p>After about two years, I finally came up with an answer that was both simple and all-encompassing. A computer is:</p>
<blockquote><p>
Any piece of matter which can carry out symbolic instructions and compare data in assistance of a human goal.
</p></blockquote>
<p>And that, my friends, is really it. My only thought left is whether I should say &#8220;<em>a series</em> of symbolic instructions&#8221; to more clearly differentiate it from a calculator. What do you think?</p>
<p>-Max</p>
<p><a href="http://www.codesimplicity.com/post/what-is-a-computer/#comments">Comments: 35</a></p><hr style="margin: 0; margin-top: 0.5em; border: none; border-top: 1px solid black; width: 1.5em"><p>Code Simplicity is brought to you by <a href="http://www.codesimplicity.com/about/">Max Kanat-Alexander</a> and <a href="http://www.bugzillasource.com">BugzillaSource</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.codesimplicity.com/post/what-is-a-computer/feed/</wfw:commentRss>
		<slash:comments>35</slash:comments>
		</item>
		<item>
		<title>Sane Software Design</title>
		<link>http://www.codesimplicity.com/post/sane-software-design/</link>
		<comments>http://www.codesimplicity.com/post/sane-software-design/#comments</comments>
		<pubDate>Mon, 11 Aug 2008 19:30:31 +0000</pubDate>
		<dc:creator>Max Kanat-Alexander</dc:creator>
				<category><![CDATA[Laws of Software]]></category>

		<guid isPermaLink="false">http://www.codesimplicity.com/?p=41</guid>
		<description><![CDATA[I have come up with an analogy that should make the basic principles of software design understandable to everybody. The great thing about this analogy is that it covers basically everything there is to know about software design. 
Imagine that you are building a structure out of lead bars. The final structure will look like [...]]]></description>
			<content:encoded><![CDATA[<p>I have come up with an analogy that should make the basic principles of software design understandable to everybody. The great thing about this analogy is that it covers basically everything there is to know about software design. <span id="more-41"></span></p>
<p>Imagine that you are building a structure out of lead bars. The final structure will look like this:</p>
<pre>
   |
_|_|_|_
   |
   |
   |</pre>
<p>You have to build the structure and put it up at a certain location, so that people can use it (for this example, we don&#8217;t care what they need it for, but assume that they need it for some specific reason).</p>
<p>The lead bars represent the individual pieces of your software. Putting it up at the location is like putting your software into production (or sending it out to your users). Everything else should be fairly clear as to how it translates to software, if you think about it. You don&#8217;t have to translate everything to software in your mind as you read, though. Everything should be quite clear if you just imagine that you really are just building a structure out of lead bars.</p>
<h3>The Wrong Way</h3>
<p>Imagine that you were building this all by yourself, and that you had to make the bars out of raw metal. Here&#8217;s the wrong way to build it:</p>
<ol>
<li>Make one tall lead bar, and lay it flat on the ground in your workshop:
<pre>
|
|
|
|
|</pre>
</li>
<li>Cut a hole through the tall bar, and measure that hole.</li>
<li>Make a new bar that will fit through that hole:
<pre>_____</pre>
</li>
<li>Put that new bar through the hole and weld them together permanently:
<pre>
  |
__|__
  |
  |
  |</pre>
</li>
<li>Cut two holes in the horizontal bar, measure them, and make two new lead bars that will fit in those individual holes:
<pre>|   |</pre>
</li>
<li>Insert the two bars into the horizontal bar, and weld them together permanently:
<pre>
   |
_|_|_|_
   |
   |
   |</pre>
</li>
<li>With a forklift, put this into a truck to move it to the location where it&#8217;s supposed to be (It&#8217;s too heavy to move by yourself.)</li>
<li>With a pulley, make the construction stand upright and put it into the ground.</li>
<li>Discover that it won&#8217;t stay up by itself, but if you put some blocks next to it as an emergency solution, it doesn&#8217;t fall over:
<pre>
   |
_|_|_|_
   |
  _|_
 | | |</pre>
</li>
<li>Three days later, watch the structure fall over and break because the blocks aren&#8217;t actually a permanent solution.</li>
<li>Unfortunately, part of the horizontal bar has snapped, and you have to fix it. This is difficult because the bars are all welded together, so you can&#8217;t easily take out the bar and replace it with another one. You either have to build a whole new structure or weld together the broken bar. Welding the broken halves together creates a weak bond, but it&#8217;s cheaper than building a whole new structure, so you just weld them.</li>
<li>Put stronger blocks next to the structure to keep it up.</li>
<li>Next week, the weather breaks the welded bars. Weld them back together again.</li>
<li>In six days, watch the structure fall over because blocks are not a permanent solution.</li>
<li>Repeat the last few steps until you run out of money or time.</li>
</ol>
<h3>Analysis of The Wrong Way</h3>
<p>So, what was <em>good</em> about the above process? Well, it did allow one person to successfully complete a structure. In software terms, that one person &#8220;made something that works.&#8221; It also created a lot of work for one person, which is good if that one person wanted a lot of work.</p>
<p>What was bad about it?</p>
<ul>
<li>The bars all had to be made in sequence, individually.</li>
<li>Problems with the final structure (that it wouldn&#8217;t stay up) were only discovered after it was entirely built and in place.</li>
<li>When problems were discovered, they were just &#8220;quick fixed&#8221; without planning for the future.</li>
<li>It took enormous effort to move the completed structure into place.</li>
<li>If we ever had to change the configuration of the bars, we couldn&#8217;t, because they&#8217;re welded together. We&#8217;d have to build a whole new structure.</li>
<li>The completed structure requires frequent attention.</li>
</ul>
<p>And I&#8217;m sure we could come up with other faults. This whole analogy (including the parts below) could be analyzed all day.</p>
<h3>Bringing It To a Group</h3>
<p>The biggest problem with the Wrong Way process is that it wouldn&#8217;t work <em>at all</em> if there were multiple people working on the project (as there usually are in real-world software projects). The main problem is that you had to measure all the holes before you built a bar, so everything had to be done by one person, in order.</p>
<p>There are, generally, two ways to solve this problem:</p>
<ol>
<li>Write a specification for the sizes of all the individual holes beforehand, and then spread out the work of making all the different bars for each hole.
<p>This is problematic because one person has to write this specification, and if this were a large project (imagine thousands of holes instead of just three or four), it would take a lot of time. Nobody else on the team can be working until the specification is completed. The spec could be full of mistakes&#8211;there are as many chances for mistakes as there are holes specified, so if there are thousands of holes, that&#8217;s a lot of chances for errors to be made.</p>
</li>
<li>Just say, &#8220;All bar holes will always be the same size and in the same places on the bars. Bars can be screwed together.&#8221; Then set everybody to making bars with standardized holes (or go buy them from the store).
<p>That is simple, and it gets everybody working at once. Because you&#8217;ve standardized your bars, you&#8217;ve lost a little flexibility in dealing with any special cases that come up (maybe a half-width hole would be more useful in some part of the structure). However, you should be able to build a decent structure entirely with standard holes, so that&#8217;s not too much of a problem. And when you have a standard, you can make specific exceptions in some places more easily than if things are not standardized.</p>
<p>Of course, with this method it is very important that you do a little research to pick a good hole size and good bars.</p>
</li>
</ol>
<h3>The Right Way</h3>
<p>So, what would our process look like for many people all using standardized bars that screw together? (This is the right way to build something.)</p>
<ol>
<li>Have your team all go build (or buy) their individual bars. You can have as many people working simultaneously as there are bars in the structure.</li>
<li>Have them test their individual bars to make sure that they won&#8217;t break.</li>
<li>Have them carry their individual bars to the place where the structure needs to be.</li>
<li>Put the first bar into the ground, standing upright:
<pre>|</pre>
</li>
<li>Push on the first bar from all angles to see if it is going to fall over.</li>
<li>Screw in a second bar to the first one:
<pre>|
|</pre>
</li>
<li>Test the complete structure now, only to find that it&#8217;s not strong enough to stand by itself.</li>
<li>Attach unbreakable steel ropes to the sides of the structure, like so:
<pre>
  /|\
 / | \</pre>
<p>These ropes should be able to withstand anything within reason, or even well beyond reason.</p>
</li>
<li>Test it again and find out that it now can stay up no matter how hard you push on it.</li>
<li>Add a third bar, and put new ropes on so that it looks like this:
<pre>
   /|\
  //|\\
 // | \\</pre>
</li>
<li>Remove the lower ropes:
<pre>
   /|\
  / | \
 /  |  \</pre>
<p>(Anybody who&#8217;s been involved in refactoring Bugzilla can remember doing a lot of things that sound <em>just like</em> these last two steps. <img src='http://www.codesimplicity.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  )</p>
</li>
<li>Test it again.</li>
<li>Continue these steps until you have a completed structure:
<pre>
      |
   _|_|_|_
  /   |   \
 /    |    \
/     |     \</pre>
</li>
<li>When a pipe breaks in three months, figure out what was wrong with that pipe, fix the problem, and replace it with a new pipe that fits into the same holes. The structure is just as strong as it was before.</li>
<li>Continue the above process until you no longer have to pay attention to the structure and it just stays up all by itself.</li>
<li>Adjust the structure as necessary for the changing requirements of the users of the structure, which is easy because the holes are all standardized.</li>
</ol>
<p>So, did you notice that we followed all the Laws Of Software Design?</p>
<ul>
<li>We <a href="/archives/17">thought about the future</a>. We did that for the entire process, but we particularly did it when we put on unbreakable steel ropes that would last no matter what happened in the future.
<p>Also note that we <a href="/archives/32">didn&#8217;t try to predict the future</a>, we just followed our principles so that no matter what happened, our structure was going to stay together and be easy to build.</li>
<li>We <a href="/archives/18">allowed for change</a> by screwing the bars together instead of welding them. We also put standardized holes in all the bars, even if we didn&#8217;t need them, in case we needed to add more bars in the future.</li>
<li>In every step of creating the structure, we <a href="/archives/19">kept our changes small</a> and tested everything as we went. Creating each individual bar was a small task, and we put them together in small steps.</li>
<li>And of course, the most important decision we made was to <a href="/archives/23">keep it simple</a> by making all the holes consistent and standard, and keeping each piece small and simple.</li>
</ul>
<p>Whether you are one person or a thousand, whether your project is 10 lines of code or 10 million, this process will work.</p>
<p>-Max</p>
<p><a href="http://www.codesimplicity.com/post/sane-software-design/#comments">Comments: 2</a></p><hr style="margin: 0; margin-top: 0.5em; border: none; border-top: 1px solid black; width: 1.5em"><p>Code Simplicity is brought to you by <a href="http://www.codesimplicity.com/about/">Max Kanat-Alexander</a> and <a href="http://www.bugzillasource.com">BugzillaSource</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.codesimplicity.com/post/sane-software-design/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Source of Bugs</title>
		<link>http://www.codesimplicity.com/post/the-source-of-bugs/</link>
		<comments>http://www.codesimplicity.com/post/the-source-of-bugs/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 19:00:44 +0000</pubDate>
		<dc:creator>Max Kanat-Alexander</dc:creator>
				<category><![CDATA[Laws of Software]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[complexity]]></category>
		<category><![CDATA[simplicity]]></category>

		<guid isPermaLink="false">http://www.codesimplicity.com/?p=35</guid>
		<description><![CDATA[
Bugs most commonly come from somebody&#8217;s failure to reduce complexity. Less commonly, they come from the programmer&#8217;s misunderstanding of something that was actually simple.

Other than typos, I&#8217;m pretty sure that those two things are the source of all bugs, though I haven&#8217;t yet done extensive research to prove it.
When something is complex, it&#8217;s far too [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>
<strong>Bugs most commonly come from somebody&#8217;s failure to reduce complexity. Less commonly, they come from the programmer&#8217;s misunderstanding of something that was actually simple.</strong>
</p></blockquote>
<p>Other than typos, I&#8217;m pretty sure that those two things are the source of all bugs, though I haven&#8217;t yet done extensive research to prove it.</p>
<p>When something is complex, it&#8217;s far too easy to misuse it. If there&#8217;s a black box with millions of unlabeled buttons on it, and 16 of them blow up the world, somebody&#8217;s going to blow up the world. Similarly, in programming, if you can&#8217;t easily understand the documentation of a language, or the actual language itself, you&#8217;re going to mis-use it somehow.</p>
<p>There&#8217;s no <em>right</em> way to use a box with millions of unlabeled buttons, really. You could never figure it out, and even if you wanted to read the 1000-page manual, you probably couldn&#8217;t remember the whole thing well enough to use the box correctly. Similarly, if you make anything complex enough, people are more likely to use it wrongly than to use it correctly. If you have 50, 100, or 1000 of these complex parts all put together, they&#8217;ll never work right, no matter how brilliant an engineer puts them together.</p>
<p>So do you start to see here where bugs come from? Every time you added some complexity, somebody (and “somebody” could even be you, yourself) was more likely to mis-use your complex code. Every time it wasn&#8217;t <em>crystal clear</em> <strong>exactly</strong> what should be done and how your code should be used, somebody could have made a mistake. Then you put your code together with some other code, and there was another chance for mistakes or mis-use. Then we put more pieces together, etc.</p>
<p>Often, this sort of situation happens: the hardware designer made the hardware really complicated. So it had to have a complicated assembly language. This made the programming language and the compiler really complicated. By the time you got on the scene, you had no hope of writing bug-free code without ingenious testing and design. And if your design was <em>less than perfect</em>, well&#8230;suddenly you have lots of bugs.</p>
<p>This is also a matter of understanding the viewpoint of other programmers. After all, something might be simple to <em>you</em>, but it might be complex to somebody who isn&#8217;t you. </p>
<p>If you want to understand the viewpoint of somebody who doesn&#8217;t know anything about your code, find the documentation of a library that you&#8217;ve never used, and read it.</p>
<p>Also, find some code you&#8217;ve never read, and read it. Try to understand not just the individual lines, but what the whole program is doing and how you would modify it if you had to. That&#8217;s the same experience people are having reading your code. You might notice that the complexity doesn&#8217;t have to get very high before it becomes frustrating to read other people&#8217;s code.</p>
<p>Now, once in a while, something is really simple, and the programmer just misunderstood it. That&#8217;s another thing to watch for. If you catch a programmer explaining something to you in a way that makes no sense, perhaps that programmer misunderstood something somewhere along the line. Of course, if the thing he was studying was extremely complex, he had basically no hope of fully understanding it without a PhD in <em>that thing</em>.</p>
<p>So these two things are very closely related. When you write code, it&#8217;s partially your responsibility that the programmer who reads your code in the future understands it, and understands it easily. Now, he could have some critical misunderstanding—maybe he never understood what “if” meant. That&#8217;s not your responsibility. Your responsibility is writing clear code, with the expectation that the future programmer reading your code understands the basics of programming and the language you&#8217;re using.</p>
<p>So, there are a few interesting rules that you can get out of this one:</p>
<blockquote><p>
The simpler your code is, the fewer bugs you will have.
</p></blockquote>
<blockquote><p>
Always work to simplify everything about your program.
</p></blockquote>
<p>-Max</p>
<p><a href="http://www.codesimplicity.com/post/the-source-of-bugs/#comments">Comments: 9</a></p><hr style="margin: 0; margin-top: 0.5em; border: none; border-top: 1px solid black; width: 1.5em"><p>Code Simplicity is brought to you by <a href="http://www.codesimplicity.com/about/">Max Kanat-Alexander</a> and <a href="http://www.bugzillasource.com">BugzillaSource</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.codesimplicity.com/post/the-source-of-bugs/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>What Is A Bug?</title>
		<link>http://www.codesimplicity.com/post/what-is-a-bug/</link>
		<comments>http://www.codesimplicity.com/post/what-is-a-bug/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 19:00:21 +0000</pubDate>
		<dc:creator>Max Kanat-Alexander</dc:creator>
				<category><![CDATA[Laws of Software]]></category>

		<guid isPermaLink="false">http://www.codesimplicity.com/?p=36</guid>
		<description><![CDATA[  Okay, most programmers know the story—way back when, somebody found an actual insect inside a computer that was causing a problem. (Actually, apparently engineers have been calling problems “bugs” since earlier than that, but that story is fun.)
  But really, when we say “bug” what exactly do we mean?
  Here&#8217;s the [...]]]></description>
			<content:encoded><![CDATA[<p>  Okay, most programmers know the story—way back when, somebody found an actual insect inside a computer that was causing a problem. (Actually, apparently engineers have been calling problems “bugs” since earlier than that, but that story is fun.)</p>
<p>  But really, when we say “bug” what <em>exactly</em> do we mean?</p>
<p>  Here&#8217;s the precise definition of what constitutes a bug. Either:</p>
<ol>
<li>The program did not behave according to the <strong>programmer&#8217;s intentions</strong>.<br/>or<br/></li>
<li>The programmer&#8217;s intentions did not fulfill common and reasonable <strong>user expectations</strong>.</li>
</ol>
<p><span id="more-36"></span>So usually, as long as the program is doing what the programmer intended it to do, it&#8217;s working correctly. Sometimes what the programmer intended it to do is totally surprising to a user and causes him some problem, so that&#8217;s a bug.</p>
<p>  Anything else is a <em>new feature</em>. That is, if the program does exactly what was intended in exactly the expected fashion, but it doesn&#8217;t do <em>enough</em>, that means it needs a new “feature.” That&#8217;s the difference between the definition of “feature” and “bug.”</p>
<p>  Note that hardware can have bugs too. The programmer&#8217;s intention is rarely “the computer now explodes.” So if the programmer writes a program and the computer explodes, that&#8217;s probably a bug in the hardware. There can be other, less dramatic bugs in the hardware, too.</p>
<p>  Essentially, anything that causes the programmer&#8217;s intentions to not be fully carried out can be considered a bug, unless the programmer is trying to make the computer do something it wasn&#8217;t designed to do. For example, if the programmer tells the computer “take over the world” and it wasn&#8217;t designed to be able to take over the world, then the computer would need a new “take over the world” feature. That wouldn&#8217;t be a bug. </p>
<p>  With hardware, you also have to think about the <em>hardware designer&#8217;s</em> intentions, and common and reasonable <em>programmer</em> expectations. At that level, software programmers are actually the main “users”, and hardware designers are the people whose intentions we care about. (Of course, we  also care about the normal user&#8217;s expectations, especially for hardware that users interact with directly like printers, monitors, keyboards, etc.)</p>
<p>  -Max</p>
<p><a href="http://www.codesimplicity.com/post/what-is-a-bug/#comments">Comments: 4</a></p><hr style="margin: 0; margin-top: 0.5em; border: none; border-top: 1px solid black; width: 1.5em"><p>Code Simplicity is brought to you by <a href="http://www.codesimplicity.com/about/">Max Kanat-Alexander</a> and <a href="http://www.bugzillasource.com">BugzillaSource</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.codesimplicity.com/post/what-is-a-bug/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Unforseeable Consequences: Why We Have Principles</title>
		<link>http://www.codesimplicity.com/post/unforseeable-consequences-why-we-have-principles/</link>
		<comments>http://www.codesimplicity.com/post/unforseeable-consequences-why-we-have-principles/#comments</comments>
		<pubDate>Mon, 14 Jul 2008 19:00:51 +0000</pubDate>
		<dc:creator>Max Kanat-Alexander</dc:creator>
				<category><![CDATA[Laws of Software]]></category>

		<guid isPermaLink="false">http://www.codesimplicity.com/?p=32</guid>
		<description><![CDATA[One of the most important things to know about any kind of engineering is:

  There are some things about the future that you do not know.

Obviously it&#8217;d be ideal if we were all-knowing and could perfectly predict every consequence of every decision we&#8217;ll ever make. But that&#8217;s impossible. In fact, it&#8217;s so far from [...]]]></description>
			<content:encoded><![CDATA[<p>One of the most important things to know about <em>any</em> kind of engineering is:</p>
<blockquote><p>
  There are some things about the future that you <strong>do not know</strong>.
</p></blockquote>
<p>Obviously it&#8217;d be ideal if we were all-knowing and could perfectly predict every consequence of every decision we&#8217;ll ever make. But that&#8217;s impossible. In fact, it&#8217;s so far from possible that if you predict more than half of the consequences of your engineering decisions, you&#8217;re godlike or just <em>really</em> lucky.</p>
<p>Let&#8217;s take an example outside of the realm of programming: <span id="more-32"></span> CDs, which were designed in 1979 to replace cassette tapes as the primary method of listening to music. Who could have predicted that 20 years later, DVDs would be made the same size and shape so that manufacturers could make CD/DVD drives for computers? Did anybody imagine the problems of spinning a CD <em>fifty times</em> faster than it was supposed to be spun, for reading in a CD-ROM drive?</p>
<p>This is why, in engineering, we have &#8220;guiding principles.&#8221; There are certain rules that, when we follow them, keep things working well no matter <em>what</em> happens in the future. </p>
<p>In the case of software, I&#8217;ve summed up the most basic guiding principles as the <a href="/archives/category/laws-of-software">Laws Of Software</a>. The very first (and most important) law is that <a href="/archives/17">the future is more important than the present</a> (because it&#8217;s very big and the present is very small). But here&#8217;s the thing to know about that: <strong>that doesn&#8217;t mean you have to predict everything about the future</strong>. Instead, it explains why you should be making decisions according to the laws of software&#8211;because those laws make for good <em>future</em> software, no matter <em>what</em> that future is.</p>
<p>Sometimes it can be hard to understand why you should be <a href="/archives/8">stupid, dumb simple</a>, if you&#8217;re only thinking about the present. And it can be impossible to predict exactly <em>why</em> or <em>how</em> simplicity will help you in the future. I can tell you that it <em>will</em> help, and you&#8217;ll be glad you did it, and if you don&#8217;t believe me (which you are welcome to do&#8211;your mind is yours!) you&#8217;re going to end up in mess of trouble somewhere down the line, in a future you <em>can&#8217;t predict</em>.</p>
<p>I&#8217;m not singling you out, here. You&#8217;re not dumb. It&#8217;s just that <em>nobody</em> can predict the total future of a piece of software, except to know that certain decisions <em>now</em> will make that future better, and that other decisions will make that future worse. We know this from decades of experience in the software development industry&#8211;certain basic principles invariably lead us in the right direction, and certain &#8220;<a href="http://c2.com/cgi/wiki?AntiPattern">anti-patterns</a>&#8220;, if followed consistently, <em>invariably</em> lead us into trouble.</p>
<p>To be a successful software developer, you have to be willing to <em>not know</em> some things about the future, and trust that following your principles is the right thing to do. Sometimes it can take years to see that you were right, but it&#8217;s a glorious day when you finally realize that your product still exists because you made the right decision <em>three years ago</em>, when you couldn&#8217;t even prove to anybody that it <em>was</em> the right decision, but forged ahead anyway with your &#8220;excessive simplicity&#8221; because you knew it was the right thing to do.</p>
<p>-Max</p>
<p><a href="http://www.codesimplicity.com/post/unforseeable-consequences-why-we-have-principles/#comments">Comments: 5</a></p><hr style="margin: 0; margin-top: 0.5em; border: none; border-top: 1px solid black; width: 1.5em"><p>Code Simplicity is brought to you by <a href="http://www.codesimplicity.com/about/">Max Kanat-Alexander</a> and <a href="http://www.bugzillasource.com">BugzillaSource</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.codesimplicity.com/post/unforseeable-consequences-why-we-have-principles/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Complexity and the Wrong Solution</title>
		<link>http://www.codesimplicity.com/post/complexity-and-the-wrong-solution/</link>
		<comments>http://www.codesimplicity.com/post/complexity-and-the-wrong-solution/#comments</comments>
		<pubDate>Mon, 14 Apr 2008 20:00:20 +0000</pubDate>
		<dc:creator>Max Kanat-Alexander</dc:creator>
				<category><![CDATA[Laws of Software]]></category>
		<category><![CDATA[complexity]]></category>
		<category><![CDATA[refactoring]]></category>

		<guid isPermaLink="false">http://www.codesimplicity.com/archives/27</guid>
		<description><![CDATA[  Often, if something is getting very complex, that means that there is an error somewhere far below the level that things are getting complex on.
  For example, it&#8217;s very difficult to make a car move if it has square wheels. You&#8217;re going to be spending lots and lots of time figuring out [...]]]></description>
			<content:encoded><![CDATA[<p>  Often, if something is getting very complex, that means that there is an error somewhere far below the level that things are getting complex on.</p>
<p>  For example, it&#8217;s very difficult to make a car move if it has square wheels. You&#8217;re going to be spending lots and lots of time figuring out how to make the car work, when really it should just have round wheels.</p>
<p>  Any time there&#8217;s an “unsolvable complexity” in your program, it&#8217;s because there&#8217;s something fundamentally wrong with it. If the problem is “unsolvable” at one level, maybe you should back up and look at what&#8217;s underlying the problem. Maybe you put square wheels on the car, and now you&#8217;re trying to figure out how to make it go fast.</p>
<p>  Programmers actually do this quite often. For example, “I have this terribly messy code, now it&#8217;s really complex to add a new feature!” Well, your fundamental problem there is the that code is messy. Clean it up, make the already-existing code simple, and suddenly adding the new feature will be simple.</p>
<p><strong>What Problem Are You Trying To Solve?</strong></p>
<p>  If somebody comes up to you and says something like, “How do I make this pony fly to the moon?”, the question you need to ask is, “What problem are you trying to solve?” You&#8217;ll find out that they really need to collect gray rocks. Why they thought they had to fly to the moon, and use a <em>pony</em> to do it, only they know. People <em>do</em> get confused like this.</p>
<p>  So when things get complex, back up and you look at the problem that you&#8217;re trying to solve. Take a <em>really big</em> step back. You are allowed to question <em>everything</em>. Maybe you thought that adding 2 and 2 was the only way to get 4, and you didn&#8217;t think about adding 1 and 3 instead, or just skipping the addition entirely and just <em>putting</em> “4” there.  The “problem” is “How do I get 4?” <em>Any</em> method of solving that problem is acceptable, so figure out what the <em>best</em> method would be, for the situation that you&#8217;re in.</p>
<p>  Discard your assumptions. Really <em>look</em> at the <em>problem</em> that you&#8217;re trying to solve, and think about the simplest way to solve that problem. Not “How do I solve this problem using my current code?” Not “How did Professor Bob solve this problem in his program?” No, just how, <em>in general</em>, in a perfect world, should that problem be solved? From there, you might see how your code needs to be re-worked. Then you can re-work your code. <em>Then</em> you can solve the problem.</p>
<p>-Max</p>
<p><a href="http://www.codesimplicity.com/post/complexity-and-the-wrong-solution/#comments">Comments: 18</a></p><hr style="margin: 0; margin-top: 0.5em; border: none; border-top: 1px solid black; width: 1.5em"><p>Code Simplicity is brought to you by <a href="http://www.codesimplicity.com/about/">Max Kanat-Alexander</a> and <a href="http://www.bugzillasource.com">BugzillaSource</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.codesimplicity.com/post/complexity-and-the-wrong-solution/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>If It Ain&#8217;t Broken&#8230;</title>
		<link>http://www.codesimplicity.com/post/if-it-aint-broken/</link>
		<comments>http://www.codesimplicity.com/post/if-it-aint-broken/#comments</comments>
		<pubDate>Fri, 04 Apr 2008 19:00:06 +0000</pubDate>
		<dc:creator>Max Kanat-Alexander</dc:creator>
				<category><![CDATA[Laws of Software]]></category>
		<category><![CDATA[third law]]></category>

		<guid isPermaLink="false">http://www.codesimplicity.com/archives/24</guid>
		<description><![CDATA[Okay, so remember our third law? (You can&#8217;t break things if you don&#8217;t change them.) Well, that has a very important related rule, that every engineer on Earth knows, but sometimes forgets:

Never “fix” anything unless it&#8217;s a problem, and you have evidence showing that the problem really exists.

Of course, most of us know this as [...]]]></description>
			<content:encoded><![CDATA[<p>Okay, so remember our <a href="/archives/19">third law</a>? (You can&#8217;t break things if you don&#8217;t change them.) Well, that has a very important related rule, that every engineer on Earth knows, but sometimes forgets:</p>
<blockquote><p>
<strong>Never “fix” anything unless it&#8217;s a problem, and you have evidence showing that the problem really exists.</strong>
</p></blockquote>
<p>Of course, most of us know this as &#8220;If it ain&#8217;t broken, don&#8217;t fix it.&#8221; However, these wise words are frequently ignored, because many developers don&#8217;t have a good understanding of what &#8220;broken&#8221; means. Often, developers just <em>imagine</em> that users have a problem with something, and start fixing it. Or they go off and develop features that don&#8217;t solve anybody&#8217;s problem. This is <em>far, far</em> more common than you might think.</p>
<p>So that&#8217;s why I say you should have <em>evidence</em> that there&#8217;s a problem. Without that evidence, you could just be fixing things that aren&#8217;t actually problems, and if you go around fixing things that aren&#8217;t broken, you&#8217;re going to <em>break things</em>. And not only could you be generating bugs, but you&#8217;re wasting your time and adding complexity to your program for no reason. You need <em>evidence</em> that there&#8217;s a problem, before you start coming up with a solution.</p>
<p>What do I mean by “evidence”? <span id="more-24"></span> Well, five users report that when they push the red button, your program explodes. Okay, that&#8217;s good enough for me! Or <em>you</em> push the red button, and you notice that the program explodes.</p>
<p>However, just because a user reports something doesn&#8217;t mean it&#8217;s a problem. Sometimes a user just didn&#8217;t realize that your program had some feature already, and so asked you to implement something else silly. For example, you write a program that sorts a list of words alphabetically, and a user asks you to add a feature that sorts a list of <em>letters</em> alphabetically. Your program <em>already does that</em>. (Actually, it already does more than that. This is often the case, with this sort of confused request.) So in this case, the user thought there was a problem, but there wasn&#8217;t even really a problem, even though he could maybe present “evidence” that he couldn&#8217;t sort a list of letters. (He just didn&#8217;t realize that he should use the <em>word</em>-sorting feature.)</p>
<p>Note that if you get a lot of requests like the above, it probably means that users can&#8217;t easily figure out how to find what they need. There&#8217;s some complexity that needs to be reduced on your end.</p>
<p>Finally, sometimes a user will report that there&#8217;s a bug, but actually that&#8217;s the program behaving exactly as you intended it to. In this case, it&#8217;s a matter of “majority rules.” If a significant number of users think that the behavior is a bug, it&#8217;s a bug. If only a tiny minority (like one or two) think it&#8217;s a bug, it&#8217;s not a bug.</p>
<p>The most famous error in this area is what we call “premature optimization”. That is, some developers seem to like to “make things go fast”.  But they do it before they know that it&#8217;s slow! This is like a charity sending food to rich people. “We just wanted to help people!” Right—illogical, isn&#8217;t it? They&#8217;re solving a problem that doesn&#8217;t exist.</p>
<p>The only parts of your program where you should be concerned about speed are the exact parts that you can show cause a real performance problem for the users. The rest of the code, the primary concern is simplicity, not “make things go fast”.</p>
<p>There are infinite ways of violating this rule, but the way to follow it is <em>so simple</em>: just get real evidence that the problem is <em>valid</em> before you fix it.</p>
<p>-Max</p>
<p><a href="http://www.codesimplicity.com/post/if-it-aint-broken/#comments">Comments: 0</a></p><hr style="margin: 0; margin-top: 0.5em; border: none; border-top: 1px solid black; width: 1.5em"><p>Code Simplicity is brought to you by <a href="http://www.codesimplicity.com/about/">Max Kanat-Alexander</a> and <a href="http://www.bugzillasource.com">BugzillaSource</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.codesimplicity.com/post/if-it-aint-broken/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Fourth Law of Software Design: Complexity vs. Ease of Maintenance</title>
		<link>http://www.codesimplicity.com/post/the-fourth-law-of-software-design-complexity-vs-ease-of-maintenance/</link>
		<comments>http://www.codesimplicity.com/post/the-fourth-law-of-software-design-complexity-vs-ease-of-maintenance/#comments</comments>
		<pubDate>Mon, 10 Mar 2008 19:00:39 +0000</pubDate>
		<dc:creator>Max Kanat-Alexander</dc:creator>
				<category><![CDATA[Laws of Software]]></category>
		<category><![CDATA[complexity]]></category>
		<category><![CDATA[fourth law]]></category>
		<category><![CDATA[girders]]></category>
		<category><![CDATA[overengineering]]></category>

		<guid isPermaLink="false">http://www.codesimplicity.com/archives/23</guid>
		<description><![CDATA[Okay, so if we never change our software, we can entirely avoid defects. But change is inevitable! Particularly if we&#8217;re going to add new features. And after all, one of our goals was to make software easy to maintain, and to maintain software, it has to be changed here and there. In other words, we [...]]]></description>
			<content:encoded><![CDATA[<p>Okay, so if we never change our software, we can entirely avoid defects. But change is inevitable! Particularly if we&#8217;re going to add new features. And after all, one of <a href="/archives/22">our goals</a> was to make software easy to maintain, and to maintain software, it has to be changed here and there. In other words, we <em>will</em> be making changes. So &#8220;don&#8217;t change anything&#8221; can&#8217;t be the ultimate defect-reduction technique.</p>
<p>Well, like I said in the <a href="/archives/19">my design philosophy</a> it helps to keep your changes small. But if you want to avoid even more defects, and eliminate them even from your small changes, there&#8217;s another law that can help you. And it doesn&#8217;t just reduce defects&#8211;it  keeps things maintainable, makes it easy to add new features, improves the overall understandability of your code, and knowing it helps you make better software, all around. This Fourth Law of Software Design is: <span id="more-23"></span></p>
<blockquote><p>
<strong>The maintainability of a system is inversely proportional to the complexity of its individual pieces.</strong>
</p></blockquote>
<p>Where &#8220;maintainability&#8221; means &#8220;ease of maintenance.&#8221; Extreme <em>unmaintainability</em> would be the total inability to maintain some part or the whole of a piece of software. <em>Perfect</em> maintainability is impossible, but it&#8217;s the goal you strive for&#8211;total change or infinite new code with no difficulty.</p>
<p>This law is largely empirical, meaning that I figured it out by observation, not by logic. However, it does have a logical basis:</p>
<ol>
<li>The simpler something is, the easier it is to understand. For example, a beach ball is very simple&#8211;a single large round object that you throw around&#8211;and is something that anybody can understand.</li>
<li>The more complex something is, the harder it is to understand. For example, a jet plane is very complex, and takes extensive training to use and understand. Complexity is not the only factor that makes things hard to understand, but with enough complexity, <em>anything</em> can become hard to understand.</li>
<li>The less you understand something, the harder it is to fix or modify it.</li>
<li>Thus: The more complex something becomes, the harder it is to modify (maintain) it.</li>
</ol>
<p>However, you&#8217;ll notice that I didn&#8217;t say anything about the complexity of the <em>whole system</em>, in the law. I only mentioned its <em>individual pieces</em>. Why did I do that?</p>
<p>Well, an average-sized computer program is so complex that no human being could comprehend it all at once in their mind. It&#8217;s only possible to comprehend <em>pieces</em> of it. So we actually <em>always</em> have some large, complex structure for our whole program. What then becomes important is that the <em>pieces</em> can be understood when we look at them, and that we understand how the pieces relate to each other. The easier it is to understand the pieces, the more likely it is that any given person will understand them. That&#8217;s particularly important when you&#8217;re handing your code off to other people, or when you go away from your code for a few months and then have to come back and &#8220;re-learn&#8221; what you did, by reading your own code.</p>
<p>Let&#8217;s make an analogy, to demonstrate the principle. Imagine that you&#8217;re building a 30-foot tall steel structure. There are two ways to make it&#8211;you could make it out of a bunch of small girders, or you could try to forge three huge pieces of steel and put them together. With the girders approach, it&#8217;s easy to make or buy the individual pieces. The three huge pieces, on the other hand, have to be carefully custom-made and worked on extensively. With the girders, if one breaks you just replace it with an identical spare part. With the &#8220;huge pieces&#8221; approach, when one breaks you have to evacuate the structure, remove 1/3 of it, create a whole new custom piece, and then add that back in without collapsing the whole structure. The girders are simple, the huge pieces are complex.</p>
<p>So why do people sometimes write software with the &#8220;huge pieces&#8221; approach instead of the girders approach? It&#8217;s because there&#8217;s a <em>perceived</em> savings of time when you&#8217;re first <em>creating</em> the software, with the &#8220;huge pieces&#8221; method. With a bunch of small pieces, there is a lot of time spent <em>putting them together</em>. You don&#8217;t see that with the huge pieces&#8211;there&#8217;s three of them, they snap together, and that&#8217;s it. But the part that&#8217;s missed here is that it took <em>way more time</em> to create the three huge pieces than it did to create the girders. When you&#8217;re making a huge, complex single piece, any tiny error means that the whole thing has to be fixed or re-worked. And per observation in the practical world of programming, you will spend far more time fixing and re-working those huge pieces than you will putting together the small girders. So even though the time spent creating the &#8220;huge pieces&#8221; might seem like &#8220;productive, important time&#8221; and the time spent putting together the girders might seem like &#8220;busywork&#8221; or &#8220;wasted time,&#8221; the &#8220;girders&#8221; approach is actually more efficient.</p>
<p>I could go on and on about this, but you can find out about it for yourself. If you don&#8217;t believe me, spend a few years working on a software project where all the parts are very complex. I don&#8217;t <em>recommend</em> that you do that, but if you need any proof of this law for yourself, that would be a good (if painful) way to get it. Of course, you could also just <em>apply</em> the law and see if your software keeps on being maintainable&#8211;that&#8217;s a much less painful demonstration. <img src='http://www.codesimplicity.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>So how do we use this law, in the practical world of programming? Well, generally I recommend that people make the individual components of their code as simple as possible. Ideally this would start way down at the assembly language level, but you don&#8217;t always get simplicity there. Nor do you always get a simple programming language. But with what you have, strive for simplicity. Make everything as simple as possible. Don&#8217;t be afraid to be <a href="/archives/8">stupid, dumb simple</a>. There is no limit to how simple you can make something, because if you go too far, your &#8220;simplicity&#8221; will start becoming <em>complex</em>. (In other words, you&#8217;ll be <a href="/archives/12">overengineering</a>.) So just be as simple as you can possibly be, and if you overdo it (which almost never happens), it&#8217;ll be pretty obvious.</p>
<p>-Max</p>
<p><a href="http://www.codesimplicity.com/post/the-fourth-law-of-software-design-complexity-vs-ease-of-maintenance/#comments">Comments: 8</a></p><hr style="margin: 0; margin-top: 0.5em; border: none; border-top: 1px solid black; width: 1.5em"><p>Code Simplicity is brought to you by <a href="http://www.codesimplicity.com/about/">Max Kanat-Alexander</a> and <a href="http://www.bugzillasource.com">BugzillaSource</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.codesimplicity.com/post/the-fourth-law-of-software-design-complexity-vs-ease-of-maintenance/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>The Third Law of Software Design</title>
		<link>http://www.codesimplicity.com/post/the-third-law-of-software-design/</link>
		<comments>http://www.codesimplicity.com/post/the-third-law-of-software-design/#comments</comments>
		<pubDate>Fri, 07 Mar 2008 19:00:18 +0000</pubDate>
		<dc:creator>Max Kanat-Alexander</dc:creator>
				<category><![CDATA[Laws of Software]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[designing too far into the future]]></category>
		<category><![CDATA[overengineering]]></category>
		<category><![CDATA[third law]]></category>

		<guid isPermaLink="false">http://www.codesimplicity.com/archives/19</guid>
		<description><![CDATA[So now we know that there is more future time than present time and that software will change as time goes on.
Our next law is, once again, axiomatic, and needs no derivation:

It is impossible to introduce new defects in your software if you do not change anything about it.

This is important&#8211;and categorized as a law&#8211;because [...]]]></description>
			<content:encoded><![CDATA[<p>So now we know that <a href="/archives/17">there is more future time than present time</a> and that <a href="/archives/18">software will change</a> as time goes on.</p>
<p>Our next law is, once again, <a href="/archives/17">axiomatic</a>, and needs no derivation:</p>
<blockquote><p>
<strong>It is impossible to introduce new defects in your software if you do not change anything about it.</strong>
</p></blockquote>
<p>This is important&#8211;and categorized as a law&#8211;because defects violate our purpose of <a href="/archives/21">helping people</a>. If something is a defect, by definition it is not helpful to people, and we need to avoid it.</p>
<p>This is also sometimes stated more informally as &#8220;You can&#8217;t introduce new bugs if you don&#8217;t add or modify code.&#8221; I&#8217;m not sure that &#8220;code&#8221; entirely covers &#8220;anything about it,&#8221; so I didn&#8217;t state it that way.</p>
<p>Of course, the reverse would be:</p>
<blockquote><p>
It is possible to introduce defects into your software if you change something about it.
</p></blockquote>
<p>Which leads to:</p>
<blockquote><p>
The more changes you make, the more likely you are to introduce a defect.
</p></blockquote>
<p>The funny thing is that this seems to be in conflict with the <a href="/archives/18">second law</a>, and in fact it is. <span id="more-19"></span> It&#8217;s the balancing act between the second and third law that requires your intelligence as a software designer.</p>
<p>Combining all three laws, we get:</p>
<blockquote><p>
The best design is the one that allows for the most change in the environment with the least change in the software.
</p></blockquote>
<p>And that, pretty simply, sums up my design philosophy.</p>
<p>However, it&#8217;s important to limit that somewhat. Although that may be the best <em>code</em> design, that rule doesn&#8217;t necessarily lead to the best <em>user-facing</em> design. An equivalent law for users would be something like, &#8220;If you never use the program it won&#8217;t break,&#8221; but I&#8217;m not sure that&#8217;s so useful. This third law is about preventing bugs, not about making things work <em>nicely</em>. You still want things to work nicely and do what people want&#8211;I&#8217;m just telling you here how to avoid <em>bugs</em>.</p>
<p>Another thing to know here is that, given our first two laws, it&#8217;s an error to write a system that &#8220;does everything we could ever possibly need,&#8221; but not make it flexible enough to cope with future change. That might seem like a good way to &#8220;avoid future changes in the software&#8221;, but really you&#8217;re just bringing all that change into the <em>present</em>, introducing the same number of bugs, and then not allowing any room to grow. And no program will do everything you could <em>ever</em> possibly need&#8211;there will always be future requirements that you cannot predict. This is covered more in <a href="/archives/6">Designing Too Far Into The Future</a>.</p>
<p>On the other hand, you can <a href="/archives/12">overengineer</a> to the point where your design is <em>so</em> flexible that creating and maintaining it is extremely difficult. That would be the point where you reach a level of flexibility that is not necessary to the real future (thinking about this in relation to the First Law).</p>
<p>However, overengineering is a much less common error than designing too far into the future. When in doubt, expect change, and plan your code in ways that will make change as simple and small as possible.</p>
<p>-Max</p>
<p><a href="http://www.codesimplicity.com/post/the-third-law-of-software-design/#comments">Comments: 7</a></p><hr style="margin: 0; margin-top: 0.5em; border: none; border-top: 1px solid black; width: 1.5em"><p>Code Simplicity is brought to you by <a href="http://www.codesimplicity.com/about/">Max Kanat-Alexander</a> and <a href="http://www.bugzillasource.com">BugzillaSource</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.codesimplicity.com/post/the-third-law-of-software-design/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>The Second Law of Software Design</title>
		<link>http://www.codesimplicity.com/post/the-second-law-of-software-design/</link>
		<comments>http://www.codesimplicity.com/post/the-second-law-of-software-design/#comments</comments>
		<pubDate>Mon, 03 Mar 2008 19:00:52 +0000</pubDate>
		<dc:creator>Max Kanat-Alexander</dc:creator>
				<category><![CDATA[Laws of Software]]></category>
		<category><![CDATA[change]]></category>
		<category><![CDATA[first law]]></category>
		<category><![CDATA[second law]]></category>

		<guid isPermaLink="false">http://www.codesimplicity.com/archives/18</guid>
		<description><![CDATA[Now that we know that the future is important, our second law answers the question, &#8220;What&#8217;s going to happen in the future?&#8221; To any programmer who&#8217;s worked for any amount of time, this law will be obviously true once you see it, but it&#8217;s still good to derive and prove it.
This law is derived from [...]]]></description>
			<content:encoded><![CDATA[<p>Now that we know that <a href="/archives/17">the future is important</a>, our second law answers the question, &#8220;What&#8217;s going to happen in the future?&#8221; To any programmer who&#8217;s worked for any amount of time, this law will be obviously true once you see it, but it&#8217;s still good to derive and prove it.</p>
<p>This law is derived from things that we know about the physical universe. From physics we know:</p>
<blockquote><p>
Nothing stays still.
</p></blockquote>
<p>That is, there is no matter or energy anywhere that isn&#8217;t <em>moving</em>. Even the atoms in your desk are vibrating furiously, back and forth. It is actually impossible to make them stand still.</p>
<p>So, from that we can then assume:</p>
<blockquote><p>
Anything that exists in the physical universe will change.
</p></blockquote>
<p>Now, that might not be so obvious in some respects. <span id="more-18"></span> After all, couldn&#8217;t you just have something vibrate back and forth forever in one space? Well, let&#8217;s ignore that that vibration is &#8220;change&#8221;, because it&#8217;s not really the kind of change I&#8217;m talking about. You have to look at it this way: as soon as a vibrating object strikes another vibrating object, one of the vibrations will change. With enough objects in the universe, change then becomes unavoidable. There are enough objects in this universe (particularly the world we live in every day) that change is thus extremely common and likely. Also, <em>people</em> change things, above and beyond these physical laws.</p>
<p>So, you can guarantee this:</p>
<blockquote><p>
The world around your program is going to change.
</p></blockquote>
<p>It could be that you wrote a program for four-wheeled cars and now everybody drives 18-wheel trucks. It could be that you wrote a program for 10 year olds and then 10-year-old education got so bad that they couldn&#8217;t use it anymore. Really, it could be anything&#8211;the only thing you can guarantee is that <em>something</em> is going to change.</p>
<p>This leads us to our second law of software design:</p>
<blockquote><p>
<strong>Your software is going to change.</strong>
</p></blockquote>
<p>It&#8217;s not going to change by <em>itself</em>, but unless you just give up and decide you don&#8217;t want people to use your software anymore, you as a programmer are going to have to accommodate the demands of a changing environment. And that changing environment includes you and your users, too. One day you could wake up and decide that you don&#8217;t like how &#8220;feature A&#8221; works and re-write that piece of the program. Or you might suddenly get new users who don&#8217;t like how &#8220;feature B&#8221; works and have to change that. Really, the possible causes of change are limitless&#8211;the only thing you can guarantee is that <em>something</em> will change.</p>
<p>That leads us nicely into the next statement we can derive here, looking at our second law in the context of our <a href="/archives/17">first law</a>:</p>
<blockquote><p>
The longer your program exists, the more probable it is that any piece of it will have to change.
</p></blockquote>
<p>That is, as you go into the infinite future, you start tending toward a 100% possibility of every single piece of your program changing. In the next five minutes, no part of your program will probably change. In the next 10 days, a small piece of it might. In the next 20 years, I&#8217;m betting that a majority of it (if not all of it) will change.</p>
<p><em>This</em> is our primary concern in designing for the future&#8211;that we allow for and expect <em>change</em>, not that we design ourselves rigid structures that will &#8220;stand forever&#8221; but suddenly become useless when the environment around them changes.</p>
<p>When you design for the future, you are designing for change.</p>
<p>-Max</p>
<p><a href="http://www.codesimplicity.com/post/the-second-law-of-software-design/#comments">Comments: 10</a></p><hr style="margin: 0; margin-top: 0.5em; border: none; border-top: 1px solid black; width: 1.5em"><p>Code Simplicity is brought to you by <a href="http://www.codesimplicity.com/about/">Max Kanat-Alexander</a> and <a href="http://www.bugzillasource.com">BugzillaSource</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.codesimplicity.com/post/the-second-law-of-software-design/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>The Goals of Software Design</title>
		<link>http://www.codesimplicity.com/post/the-goals-of-software-design/</link>
		<comments>http://www.codesimplicity.com/post/the-goals-of-software-design/#comments</comments>
		<pubDate>Fri, 29 Feb 2008 18:30:09 +0000</pubDate>
		<dc:creator>Max Kanat-Alexander</dc:creator>
				<category><![CDATA[Laws of Software]]></category>
		<category><![CDATA[complexity]]></category>
		<category><![CDATA[first goal]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[primary law]]></category>
		<category><![CDATA[purpose of software]]></category>
		<category><![CDATA[second goal]]></category>
		<category><![CDATA[third goal]]></category>

		<guid isPermaLink="false">http://www.codesimplicity.com/archives/22</guid>
		<description><![CDATA[Now that we know what software design is and the purpose of software, the next step is to define the goals of this science of software design.  
From the purpose of software, we know that when we write software, we&#8217;re trying to help people. So, one of the goals of a science of software [...]]]></description>
			<content:encoded><![CDATA[<p>Now that we know <a href="/archives/20">what software design is</a> and <a href="/archives/21">the purpose of software</a>, the next step is to define the goals of this science of software design.  </p>
<p>From the purpose of software, we know that when we write software, we&#8217;re trying to help people. So, one of the goals of a science of software design should be:</p>
<blockquote><p>
To allow us to write software that is as helpful as possible.
</p></blockquote>
<p>Secondly, we usually want people to <em>keep on</em> being helped by our software. So our second goal is:</p>
<blockquote><p>
To allow our software to <em>continue</em> to be as helpful as possible.
</p></blockquote>
<p>Now, that&#8217;s a great goal, but any software system of any size is <a href="/archives/4">extremely complex</a>, so allowing it to continue being helpful is quite a task. Maintaining it over time can be quite a bit of work. Even just creating the system in the first place can be nightmarish if you don&#8217;t have some guidelines to follow, or haven&#8217;t already had experience doing it. So that leads us to our third goal: <span id="more-22"></span></p>
<blockquote><p>
To design systems that can be created and maintained as easily as possible by their programmers, so that they can be&#8211;and continue to be&#8211;as helpful as possible.
</p></blockquote>
<p>When software is easy to create, a programmer can spend more time focusing on being helpful to the user, and less time focusing on the details of programming. Similarly, the easier it is to maintain a piece of software, the easier it is for a programmer to have that software <em>continue</em> to be helpful.</p>
<p>This third goal is probably the one traditionally thought of as the goal of software design, even if it&#8217;s never stated explicitly. However, it&#8217;s very important to also have the first and second goal to guide us.</p>
<p>The phrase &#8220;<em>as easily as possible</em>&#8221; in the third goal is very important. The idea is to make things <em>easy</em> to create and maintain, not to make them <em>difficult</em> or <em>complex</em>. That doesn&#8217;t mean that everything will be <em>immediately</em> easy&#8211;sometimes it takes time to learn a new technology or design something well. But <em>in the long run</em>, your choices should lead to easier maintenance and creation for your software.</p>
<p>Sometimes the first goal (being helpful) and the third goal (easy maintenance) are a little bit in conflict&#8211;sometimes making your software helpful can make it harder to maintain. However, I believe that these two goals have been <em>much</em> more in conflict, historically, than they need to be. It is absolutely possible to create a totally maintainable system that is yet extremely helpful to its users. And in fact, if you don&#8217;t make it maintainable, it&#8217;s going to be quite difficult to meet our second goal of <em>continuing</em> to be helpful.</p>
<p>All this, of course, leads us quite nicely back into our <a href="/archives/17">Primary Law</a>, which is where we&#8217;d be going next if this were a book. The only thing I&#8217;d add to the Primary Law article is that under most circumstances, there&#8217;s a lot more potential help to be done in the future than there is in the present. (If there&#8217;s <em>no</em> potential help to be done in the future for your software, then it doesn&#8217;t have much of a life expectancy anyway, so we don&#8217;t worry too much about that situation.) In other words (and as I&#8217;ll be talking about more, later), by focusing on the second goal (continuing to be helpful), it is often possible to achieve the first (being helpful). That doesn&#8217;t mean first goal is unimportant&#8211;I&#8217;m just giving you something to think about.</p>
<p>-Max</p>
<p><a href="http://www.codesimplicity.com/post/the-goals-of-software-design/#comments">Comments: 0</a></p><hr style="margin: 0; margin-top: 0.5em; border: none; border-top: 1px solid black; width: 1.5em"><p>Code Simplicity is brought to you by <a href="http://www.codesimplicity.com/about/">Max Kanat-Alexander</a> and <a href="http://www.bugzillasource.com">BugzillaSource</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.codesimplicity.com/post/the-goals-of-software-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Purpose of Software</title>
		<link>http://www.codesimplicity.com/post/the-purpose-of-software/</link>
		<comments>http://www.codesimplicity.com/post/the-purpose-of-software/#comments</comments>
		<pubDate>Wed, 27 Feb 2008 19:30:12 +0000</pubDate>
		<dc:creator>Max Kanat-Alexander</dc:creator>
				<category><![CDATA[Laws of Software]]></category>
		<category><![CDATA[bugzilla]]></category>
		<category><![CDATA[Firefox]]></category>

		<guid isPermaLink="false">http://www.codesimplicity.com/archives/21</guid>
		<description><![CDATA[Whenever you engage in some activity, it&#8217;s a good idea to have some idea of what the purpose of that activity is. What is the end goal, and why are you doing it? For example, when I sleep, the goal is to be rested. When I talk, the purpose is to communicate and be understood.
Similarly, [...]]]></description>
			<content:encoded><![CDATA[<p>Whenever you engage in some activity, it&#8217;s a good idea to have some idea of what the <em>purpose</em> of that activity is. What is the end goal, and why are you doing it? For example, when I sleep, the goal is to be rested. When I talk, the purpose is to communicate and be understood.</p>
<p>Similarly, when we write software, we should have some idea of why we&#8217;re doing it, and what the end goal is.</p>
<p>Now, is there some way that you could sum up what the purpose of <em>all software</em> is? If there was such a statement possible, it would give orientation to our whole science of software design, because we&#8217;d know <em>what</em> we were going for.</p>
<p>Well, I think I&#8217;ve managed to derive a single purpose that would fit all software:<span id="more-21"></span></p>
<blockquote><p>
  <strong>To help people.</strong>
</p></blockquote>
<p>For example, <a href="http://www.bugzilla.org/">Bugzilla</a> exists &#8220;to help people <em>track bugs</em>.&#8221; <a href="http://www.mozilla.com/">Firefox</a> exists &#8220;to help people <em>browse the web</em>.&#8221; Remember, you could browse the web entirely by reading HTML yourself&#8211;but Firefox (or your web browser of choice) sure does help.</p>
<p>Even if you wrote a piece of software to help animals or plants, it would still be &#8220;to help <em>people</em> help animals or plants.&#8221;</p>
<p>Software is never there &#8220;to help inanimate matter.&#8221; Software does not exist &#8220;to help the computer.&#8221; It always exists to help <em>people</em>. Even when you&#8217;re writing libraries, you&#8217;re writing &#8220;to help programmers&#8221;, who are people. You are <em>never</em> writing &#8220;to help the computer.&#8221;</p>
<p>Now, what does &#8220;help&#8221; mean? Well, that is somewhat a subjective thing, and somewhat not. Look it up <a href="http://www.merriam-webster.com/cgi-bin/dictionary?book=Dictionary&#038;va=help">in the dictionary</a>. There are many things you could help with&#8211;organizing a schedule, writing a book, planning a diet, anything. <em>What</em> you help with is up to you, but the purpose is always <em>to help</em>.</p>
<p>People who cannot conceive of helping another person will write bad software&#8211;their software won&#8217;t help people. In fact, I might theorize (as a guess based on some personal observations) that your <em>potential</em> ability to write good software is limited only by your ability to conceive of helping another.</p>
<p>The purpose of software is not &#8220;to make money&#8221; or &#8220;to show off how intelligent I am.&#8221; Anybody writing with those as their only purposes is violating the purpose of software and is quite likely to get into trouble. Granted, both of those are a way of &#8220;helping&#8221; <em>yourself</em>, but that&#8217;s a pretty limited scope of help and, I would argue, is likely to lead to lower-quality software than software genuinely designed to help individuals do what they need or want to do.</p>
<p>So anyhow, there you have it. When we are making decisions about software, our guiding principle can be how we can <em>help</em>. It&#8217;s possible to help more or less, to help fewer or more people or things. With that as a yardstick, it&#8217;s possible to understand our Laws Of Software Design and how we should be making decisions about software.</p>
<p>-Max</p>
<p><a href="http://www.codesimplicity.com/post/the-purpose-of-software/#comments">Comments: 12</a></p><hr style="margin: 0; margin-top: 0.5em; border: none; border-top: 1px solid black; width: 1.5em"><p>Code Simplicity is brought to you by <a href="http://www.codesimplicity.com/about/">Max Kanat-Alexander</a> and <a href="http://www.bugzillasource.com">BugzillaSource</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.codesimplicity.com/post/the-purpose-of-software/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>What Is Software Design?</title>
		<link>http://www.codesimplicity.com/post/what-is-software-design/</link>
		<comments>http://www.codesimplicity.com/post/what-is-software-design/#comments</comments>
		<pubDate>Mon, 25 Feb 2008 19:00:07 +0000</pubDate>
		<dc:creator>Max Kanat-Alexander</dc:creator>
				<category><![CDATA[Laws of Software]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[software design]]></category>

		<guid isPermaLink="false">http://www.codesimplicity.com/archives/20</guid>
		<description><![CDATA[On my last blog, one of the commenters very correctly pointed out that I hadn&#8217;t actually told you what I meant by &#8220;software design.&#8221; And, in fact, looking around the web a bit, I&#8217;m finding that what I mean by &#8220;software design&#8221; isn&#8217;t fully covered by most current definitions.
For the sake of this definition, let&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>On my <a href="/archives/17">last blog</a>, one of the commenters very correctly pointed out that I hadn&#8217;t actually told you what I meant by &#8220;software design.&#8221; And, in fact, looking around the web a bit, I&#8217;m finding that what <em>I</em> mean by &#8220;software design&#8221; isn&#8217;t fully covered by most current definitions.</p>
<p>For the sake of this definition, let&#8217;s say that the process of making software is composed of three parts: administrative decision-making, technical decision-making, and actual coding. Of course, there&#8217;s also testing, releasing&#8211;there&#8217;s lots of parts to software in the real world. I&#8217;m just making an artificial division here to help define one part of the three I mentioned. <span id="more-20"></span></p>
<p>By &#8220;administrative decision-making&#8221; I mean the sorts of decisions that would be made primarily by managers in a software organization. These are scheduling, cost estimates, what programmer to assign to what task, etc. There are a lot of theories and study in this area&#8211;I think that it&#8217;s actually fairly well-covered (even if not completely made scientific yet) by lots of people. That is not the area I&#8217;m talking about when I say &#8220;software design.&#8221;</p>
<p>The other side of those three parts is &#8220;coding&#8221;. That&#8217;s where you sit down and actually write the program, typing strange words onto a screen in the hope that the computer will do something. This process is partially covered by the study of computer science, which gives us mathematical ways of modeling code and information. It&#8217;s also covered by the manual of whatever language we&#8217;re writing in. Coding is what you do after you&#8217;ve already made decisions&#8211;it&#8217;s just the actual process of telling the computer what to do, or figuring out how to make the computer perform the actions you want.</p>
<p>The last piece, in the middle, is what I&#8217;m loosely calling &#8220;technical decision-making.&#8221; Often, the process of technical decision-making and coding happen so fast that they are mentally indistinguishable, particularly if you are an experienced programmer. You just &#8220;know&#8221; what to do and type it in. However, the decision-making and the coding are actually separate processes. Technical decisions would be things like: &#8220;Do we go with a functional programming language or a procedural programming language?&#8221;, &#8220;Should we have unit tests?&#8221;, &#8220;How should we style our code?&#8221;, &#8220;Should we optimize for speed?&#8221;, and even-less-high-level decisions, until you get down to the actual coding. Basically, anything that happens in your mind, on a piece of paper, on the whiteboard, etc. before you start programming, that&#8217;s <em>software design</em> as I mean it. Anything that involves the <em>overall design of the system</em> or the <em>technical decisions you make while creating the system</em> would fall under this category.</p>
<p>It could just as easily be called &#8220;software creation&#8221;, but I think that would get too confused with coding and computer science. Similarly, I started out calling it the subject of &#8220;software&#8221;, but that has the same problems. &#8220;Software architecture&#8221; is too limiting, as it&#8217;s often thought of in terms of classes and objects, and might not include things like unit tests, code style, or other technical decisions you have to make in the process of creating software.</p>
<p>I suspect that in time I will come up with an even-more-precise definition, but this should at least give you some idea of what I mean, for now.</p>
<p>What I think we primarily lack in the field of software design is a series of fundamental truths on which we can base our technical decisions. Experienced software developers &#8220;know&#8221; what &#8220;the right thing to do&#8221; is, but <em>why</em> is that the right thing? What makes that &#8220;right?&#8221; Many Perl developers, for example, would claim that Perl is &#8220;the right way&#8221;, in direct conflict with the way other languages work. There are definite warring camps in this field&#8211;how can we figure out which way we should go?</p>
<p>Well, that&#8217;s one of my goals with this science (or subject) of software design&#8211;to help us be able to figure out where we should go in any given situation.</p>
<p>So, in my view, any science of software design would have to consist of:</p>
<ol>
<li>An explanation of the purpose of software.</li>
<li>An explanation of the goals of the science.</li>
<li>A series of fundamental truths on which to base decisions.</li>
</ol>
<p>And this would allow us to achieve:</p>
<ol>
<li>The ability to make decisions that achieve the stated purpose of software.</li>
<li>Some way of understanding what causes errors (decisions that do not achieve the purpose) in software design.</li>
<li>A method (or methods) of preventing future errors.</li>
<li>A method (or methods) of fixing errors that already exist.</li>
</ol>
<p>In my view, a science is only as useful as it can be applied. Physics is very useful because we can use it to build things, fix things, design new things, etc. I would like the science of software design to be directly applicable to the practical process of writing software, and the kinds of decisions that real programmers have to make every day. I can&#8217;t promise that the study will be <em>perfect</em>, but I can promise you that it will be <em>useful</em>.</p>
<p>-Max</p>
<p><a href="http://www.codesimplicity.com/post/what-is-software-design/#comments">Comments: 4</a></p><hr style="margin: 0; margin-top: 0.5em; border: none; border-top: 1px solid black; width: 1.5em"><p>Code Simplicity is brought to you by <a href="http://www.codesimplicity.com/about/">Max Kanat-Alexander</a> and <a href="http://www.bugzillasource.com">BugzillaSource</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.codesimplicity.com/post/what-is-software-design/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>The Primary Law of Software Design</title>
		<link>http://www.codesimplicity.com/post/the-primary-law-of-software-design/</link>
		<comments>http://www.codesimplicity.com/post/the-primary-law-of-software-design/#comments</comments>
		<pubDate>Thu, 21 Feb 2008 20:51:31 +0000</pubDate>
		<dc:creator>Max Kanat-Alexander</dc:creator>
				<category><![CDATA[Laws of Software]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[law]]></category>
		<category><![CDATA[primary law]]></category>
		<category><![CDATA[word]]></category>

		<guid isPermaLink="false">http://www.codesimplicity.com/archives/17</guid>
		<description><![CDATA[Ideally, any science should have, as its base, a series of unbreakable laws from which others are derived. What is a law? Well, in the field of science, it&#8217;s something that:

Is universally true, without exception.
Predicts phenomena that, when looked for, will be found to exist in the real world.

Some of the best laws are axiomatic, [...]]]></description>
			<content:encoded><![CDATA[<p>Ideally, any science should have, as its base, a series of unbreakable <strong>laws</strong> from which others are derived. What is a law? Well, in the field of science, it&#8217;s something that:</p>
<ul>
<li>Is universally true, without exception.</li>
<li>Predicts phenomena that, when looked for, will be found to exist in the real world.</li>
</ul>
<p>Some of the best laws are <strong>axiomatic</strong>, a big word meaning &#8220;obviously true.&#8221; For example, &#8220;Yesterday happened before today&#8221; is an <em>axiomatic</em> statement&#8211;the definition of the word &#8220;yesterday&#8221; makes that obviously true.</p>
<p>For the science of software design, we are lucky to have an axiomatic basic law which is senior to all others: <span id="more-17"></span></p>
<blockquote><p>
<strong>There is more future time than there is present time.</strong>
</p></blockquote>
<p>This is obviously true. &#8220;Now&#8221; is an infinitely small moment that quickly becomes another &#8220;now.&#8221; The future is infinite.</p>
<p>So, since the future is infinitely large and the present is infinitely small, we can derive another obvious statement:</p>
<blockquote><p>
The future is more important than the present.
</p></blockquote>
<p>Now, when we&#8217;re talking about an infinitely small present and an infinite future, what I&#8217;ve said there is pretty obvious. In the real world, though, we have to ask the question: <em>how</em> much future are we talking about? What&#8217;s more important, the next five minutes or the next ten years?</p>
<p>Well, in order to answer that question, we have to make one <em>assumption</em>: that you want your program to continue to exist and be used in the future. If you only want it to exist for the next five minutes, then those are the most important. If you want it to continue to be around for 10 years, then those 10 years are the most important.</p>
<p>So all together, this tells us <em>how good</em> our software design needs to be&#8211;it needs to be exactly as good as there is future time in which our software must exist.</p>
<p>If you&#8217;re writing a program that&#8217;s only going to be used once, you don&#8217;t have to worry about its design. If you&#8217;re writing a program that&#8217;s going to be used <em>and modified</em> by astronauts on a 100-year voyage to Alpha Centauri, you have to be <em>really good</em>.</p>
<p>So, this science of software design is a thing where you have choices&#8211;if you follow and understand all of its laws, you will have a program that survives very well into the future. If you follow none of them, your program won&#8217;t continue to exist very long, or at the very least, it will become more and more difficult to ensure its continued existence.</p>
<p>Now, keep in mind that sometimes in life, there are situations where what you do for the next five minutes determines whether or not you live or die. Similarly, in the real world of software, there can be situations where what your organization does <em>right now</em> determines whether you go bankrupt or not. These are totally valid decisions according to this law, because if your software falls entirely out of existence <em>right now</em>, then the next ten years don&#8217;t matter. There is <em>no</em> future existence for something that no longer exists. (Another axiomatic statement!)</p>
<p>However, such situations are generally the exception, not the rule. If you found yourself constantly in a situation where the next five minutes determined your life or death, wouldn&#8217;t you want to get out of that? Similarly, if you find yourself in an organization that always insists that the next five minutes are more important than the next ten years, perhaps you should consider leaving.</p>
<p>Now, don&#8217;t pass any of this off as unimportant just because it&#8217;s &#8220;obvious.&#8221; What matters isn&#8217;t the statement itself, but the <em>importance</em> placed upon the statement. This is the <em>senior law</em> of software design, from which all other aspects of good design flow <em>without exception</em>. If you know of any exceptions, I&#8217;d be happy to hear them so that I could refine the science using a higher primary law. But I&#8217;m not aware of any exceptions.</p>
<p>When thinking about this law, I usually apply it from the viewpoint of a <em>programmer</em>, not as a user. Sure, a program that is written now and can still be used in 20 years would be fantastically designed <em>from a user&#8217;s perspective</em>. But what I&#8217;m concerned about mostly is whether or not a software developer will be able to fix or modify this program 20 years from now. That&#8217;s an entirely realistic concern&#8211;there are <a href="http://office.microsoft.com/word/">programs</a> that have been around for 20 years or more.</p>
<p>There are also other important things to think about in relation to this law&#8211;what you <em>can</em> and <em>can&#8217;t</em> know about the future. But that&#8217;s a subject for another blog.</p>
<p>-Max</p>
<p><a href="http://www.codesimplicity.com/post/the-primary-law-of-software-design/#comments">Comments: 21</a></p><hr style="margin: 0; margin-top: 0.5em; border: none; border-top: 1px solid black; width: 1.5em"><p>Code Simplicity is brought to you by <a href="http://www.codesimplicity.com/about/">Max Kanat-Alexander</a> and <a href="http://www.bugzillasource.com">BugzillaSource</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.codesimplicity.com/post/the-primary-law-of-software-design/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>There Is No Science Of Software</title>
		<link>http://www.codesimplicity.com/post/there-is-no-science-of-software/</link>
		<comments>http://www.codesimplicity.com/post/there-is-no-science-of-software/#comments</comments>
		<pubDate>Tue, 19 Feb 2008 23:15:57 +0000</pubDate>
		<dc:creator>Max Kanat-Alexander</dc:creator>
				<category><![CDATA[Essays]]></category>
		<category><![CDATA[Laws of Software]]></category>
		<category><![CDATA[agile software development]]></category>
		<category><![CDATA[bill]]></category>
		<category><![CDATA[cmmi]]></category>
		<category><![CDATA[computer science]]></category>
		<category><![CDATA[mythical man month]]></category>
		<category><![CDATA[rup]]></category>
		<category><![CDATA[turing machine]]></category>
		<category><![CDATA[univac]]></category>

		<guid isPermaLink="false">http://www.codesimplicity.com/archives/16</guid>
		<description><![CDATA[What we think of today as being &#8220;computers&#8221; started out in the minds of mathematicians as purely abstract devices&#8211;thoughts about how to solve math problems using machines instead of the mind.
These mathematicians are the people we would consider the modern founders of &#8220;computer science.&#8221; Computer Science is actually the mathematical study of information processing. It [...]]]></description>
			<content:encoded><![CDATA[<p>What we think of today as being &#8220;computers&#8221; started out in the minds of mathematicians as <a href="http://web.bvu.edu/faculty/schweller/Turing/Turing.html">purely abstract devices</a>&#8211;thoughts about how to solve math problems using machines instead of the mind.</p>
<p>These mathematicians are the people we would consider the modern founders of &#8220;computer science.&#8221; Computer Science is actually the mathematical study of information processing. It is not, as some people believe it to be, the study of computer programming. In fact, <em>there is no <strong>science</strong> of computer programming</em>. To understand how that could possibly be true, and what I mean, you have to know the history of programming.</p>
<p>The earliest computers were built under the supervision of computer scientists by highly skilled electronic engineers. <span id="more-16"></span> They were run by highly-trained operators in tightly-controlled environments. They were all custom-built by the organizations that needed them (mostly governments, to aim missiles and crack codes), and there were only one or two copies of any given model.</p>
<p>Then, along comes <a href="http://www.thocp.net/hardware/univac.htm">UNIVAC</a> and the whole notion of &#8220;commercial&#8221; computers. Now, there&#8217;s only so many advanced theoretical mathematicians in the world. If you start shipping out computers to <em>everybody</em>, you can&#8217;t ship a mathematician along with each one. So although some organizations, such as the United States Census Bureau, almost certainly had some highly-trained operators for their machinery, other organizations undoubtedly got their machine and said, &#8220;Okay, Bill from Accounting, this is yours! Read the manual and have at it!&#8221; And there went Bill, diving into this complex machine and doing his best to make it work.</p>
<p>Bill there is our first &#8220;working programmer.&#8221; He might have studied math in school, but he almost certainly didn&#8217;t study the sort of advanced theory needed to <em>conceive and design</em> the machine itself. But he can read the manual and understand it, and by trial and error, make the machine do what he wants.</p>
<p>Of course, the more commercial computers you ship, the more Bills you have and the fewer highly-trained operators you have. And if there&#8217;s one thing that Bill has, it&#8217;s job pressure. He has demands from management to &#8220;Get that task done now!&#8221; and &#8220;We don&#8217;t care how it&#8217;s done, just do it!&#8221; He figures out how to make the thing work according to its manual, and it works, even if it crashes every two hours.</p>
<p>Eventually Bill gets a whole team of programmers to work with him. He has to figure out how to design a system and split up the tasks between different people. Instead of being studied and mapped out like a standard science, the whole art of practical programming grows organically, more like college students teaching themselves to cook than like NASA engineers building a space shuttle.</p>
<p>So there&#8217;s this hodge-podge system for software development, and it&#8217;s all very complex and hard to manage, but everybody gets along somehow. Then along comes <em><a href="http://www.robelle.com/smugbook/manmonth.html">The Mythical Man Month</a></em>, a book by a guy who actually <em>looked</em> at the process of software development and pointed out some things about it&#8211;most famously that adding more programmers to a project doesn&#8217;t necessarily make it faster. He didn&#8217;t come up with a whole science, but he did make some good observations about programming and managing software development.</p>
<p>Of course, then came a flurry of software development methods: the <a href="http://www-306.ibm.com/software/awdtools/rup/">Rational Unified Process</a>, the <a href="http://www.sei.cmu.edu/cmmi/">Capability Maturity Model</a>, <a href="http://agilemanifesto.org/">Agile Software Development</a>, and others. None of these claim to be a science, just a way of <em>managing</em> the complexity of software development.</p>
<p>And that, basically, brings us up to where we are today: lots of &#8220;methods,&#8221; but no real <em>science</em>.</p>
<p>A science is composed of observations, experiments, and <em>laws</em>. Although we have hundreds of books of observations about practical programming, and &#8220;the world is our laboratory&#8221;, all of that has resulted in very few <em>laws</em>, which are the most important part of a science. That is, instead of coming up with methods to work around complexity, there ought to be some fundamental rules to follow that would lead to simplicity&#8211;ways to avoid complexity entirely and explain <em>why</em> what &#8220;works&#8221; in software development <em>does</em> work.</p>
<p>In reality, there are two missing sciences here. The first one is being worked on actively, and includes the various methods I mentioned above. That&#8217;s the science of managing software development. The fact that conflicting, equally-valid &#8220;opinions&#8221; seem to exist within the field indicates that the fundamental laws of software management have not been worked out. However, there is at least attention being given to the problem.</p>
<p>The other science, though, gets very little attention in the practical world of programming: the science of writing software. Very few people are taught that there is a <em>science</em> to writing software, in school. Instead, they are just shown &#8220;This is how it works in this programming language, now go write some software!&#8221;</p>
<p>The science I&#8217;m talking about is <em>not Computer Science</em>. That&#8217;s a mathematical study. I&#8217;m talking about a science for the &#8220;working programmer&#8221;&#8211;something that gives fundamental laws and rules to follow when writing a program in <em>any</em> language. One that&#8217;s as reliable as physics or chemistry in telling you how to create an application.</p>
<p>Some people might say that such a science is not possible, that software development is too variable to ever be described by simple, fundamental laws. Some people also once said that understanding the physical universe was impossible because &#8220;it is the creation of God and God is unknowable.&#8221; So unless you&#8217;re telling me computers are unknowable, I think that making such a science would be entirely possible.</p>
<p>Actually, I&#8217;ve started to collect some basic hypotheses for such a science, and I&#8217;m writing a book about it. I might post some of them here, but actually, all of what I&#8217;ve written in the blog so far actually comes from those hypotheses. That is, I haven&#8217;t really posted any of my hypothetical &#8220;laws&#8221; yet, but I have been posting data that I&#8217;ve derived <em>from</em> them.</p>
<p>Anyhow, I think that the primary source of complexity in software is actually the fact that this science is lacking. If programmers actually had a science for simplicity in software, there wouldn&#8217;t be nearly so much complexity, and we wouldn&#8217;t need crazy processes to manage that complexity.</p>
<p>Whenever there&#8217;s a problem with something, my instinct is to go philosophically <em>above</em> the level of the problem and look at it from there. If there&#8217;s some &#8220;unsolvable&#8221; effect happening to something, there must be some unknown <em>cause</em> on a higher level. So there you go&#8211;if the problem is complexity, then maybe it&#8217;s because there was no science of simplicity in the first place.</p>
<p>-Max</p>
<p><a href="http://www.codesimplicity.com/post/there-is-no-science-of-software/#comments">Comments: 11</a></p><hr style="margin: 0; margin-top: 0.5em; border: none; border-top: 1px solid black; width: 1.5em"><p>Code Simplicity is brought to you by <a href="http://www.codesimplicity.com/about/">Max Kanat-Alexander</a> and <a href="http://www.bugzillasource.com">BugzillaSource</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.codesimplicity.com/post/there-is-no-science-of-software/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

