<?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>Tim Martin&#039;s blog &#187; Software Development</title>
	<atom:link href="http://blog.asymptotic.co.uk/category/softwaredev/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.asymptotic.co.uk</link>
	<description>On the human side of software</description>
	<lastBuildDate>Sat, 04 Sep 2010 10:36:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A nice take on the apples-and-oranges puzzle</title>
		<link>http://blog.asymptotic.co.uk/2010/07/a-nice-take-on-the-apples-and-oranges-puzzle/</link>
		<comments>http://blog.asymptotic.co.uk/2010/07/a-nice-take-on-the-apples-and-oranges-puzzle/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 12:10:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[hiring]]></category>

		<guid isPermaLink="false">http://blog.asymptotic.co.uk/?p=505</guid>
		<description><![CDATA[Richard Wiseman has a nice retelling of the apples-and-oranges puzzle (which incidentally was a regular interview question at a company I used to work for):
Yesterday I saw a drinks machine that had three selections – Tea, Coffee  or Random (Tea or Coffee).  However, the machine was wired up wrongly  so that each button [...]]]></description>
			<content:encoded><![CDATA[<p>Richard Wiseman has <a href="http://richardwiseman.wordpress.com/2010/07/30/its-the-friday-puzzle-70/">a nice retelling of the apples-and-oranges puzzle</a> (which incidentally was a regular interview question at a company I used to work for):</p>
<blockquote><p>Yesterday I saw a drinks machine that had three selections – Tea, Coffee  or Random (Tea or Coffee).  However, the machine was wired up wrongly  so that each button does not give what it claims. If each drink costs  50p, what is the minimum that you have to put into the machine to work  out which button gives which selection?</p></blockquote>
<p>What I like about this is that it makes more natural several of the constraints of the original puzzle (a crate of apples, a crate of oranges, and a mixed crate):</p>
<ul>
<li>Why can&#8217;t I just peer into the crate and look at the contents?</li>
<li>Why only draw one fruit at a time?</li>
<li>Why do I care how many fruits I have to sample?</li>
</ul>
<p>It also makes more sense of the effectively-unlimited supply of fruit that is implied by the question: if it&#8217;s the <em>wiring</em> that&#8217;s at fault and not the hopper of tea / coffee, you could refill it as many times as you want without affecting the wiring.</p>
<p>The puzzle, of course, hinges on the listener not paying attention to the crucial fact: the wiring for each button (or the labelling on each crate) is <em>known</em> to be wrong, not just <em>unknown</em>. It&#8217;s one of the neat things about this puzzle that an intelligent solver may well mishear it, but can easily prove it&#8217;s impossible if the wiring is entirely unknown. In point of fact, it&#8217;s a fairly simple to show that if it is possible, then the answer must be one: we can&#8217;t necessarily distinguish a random stream from a constant stream with any number of samples. Constructing a proof that one sample will suffice is fairly easy, given that there are only three possibilities of which to sample, and by symmetricity only two possibilities that differ.</p>
<p>Does this make a good interview question for a software developer? I&#8217;m not at all convinced it does. It feels like a meta-puzzle: you reason through it by knowing the implicit rules of the game of puzzle-writing (one obvious one being that the answer can&#8217;t be impossible, and it can&#8217;t rely on luck or &#8220;good enough&#8221; solutions like 1000 random samples). Good software engineering often involves judgment calls where such rules don&#8217;t exist, and great software engineering often involves rethinking the rules of the game entirely.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.asymptotic.co.uk/2010/07/a-nice-take-on-the-apples-and-oranges-puzzle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging in the real world</title>
		<link>http://blog.asymptotic.co.uk/2010/07/debugging-in-the-real-world/</link>
		<comments>http://blog.asymptotic.co.uk/2010/07/debugging-in-the-real-world/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 00:07:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[Zambia]]></category>

		<guid isPermaLink="false">http://blog.asymptotic.co.uk/?p=501</guid>
		<description><![CDATA[As part of my preparations for living in Zambia, I&#8217;ve had to have some vaccinations. One of the recommended vaccinations was Hepatitis B. Luckily, the UK National Health Service provides Hep B vaccinations for free. Unluckily, they also provide Hepatitis A vaccinations for free, and the two are delivered as a combined vaccine. I&#8217;ve already [...]]]></description>
			<content:encoded><![CDATA[<p>As part of my preparations for living in Zambia, I&#8217;ve had to have some vaccinations. One of the recommended vaccinations was Hepatitis B. Luckily, the UK National Health Service provides Hep B vaccinations for free. <em>Unluckily</em>, they also provide Hepatitis A vaccinations for free, and the two are delivered as a combined vaccine. I&#8217;ve already been vaccinated for Hep A, so I can&#8217;t have the combined shot. This means I have to have the single Hep B vaccine, which <em>isn&#8217;t</em> free.</p>
<p>It seems odd that having immunity to a disease should drive up my costs for getting vaccinated for another disease. It seems downright bizarre that my making it easier (or at least, no harder) for the government to deliver the free service should mean I have to pay. It would be fashionable at this point to rail against the fundamental inefficiency of government-provided healthcare.</p>
<p>But I don&#8217;t think that&#8217;s what&#8217;s happening here. The mistake the NHS seem to be making here looks like the same sort of mistake that is made every day by thousands of software developers. The set of rules for Hepatitis has a bug in it (no pun intended).</p>
<p>It seems to me that in this case the bug is a leaky abstraction. The obvious goal is to provide immunity to both diseases, and a policy of providing a combined vaccine looks from a high level as if it fulfils that goal. When the details of the policy are implemented, an obvious refinement is not to provide a combined vaccine to someone who&#8217;s already had one shot (whether this is a matter of health or cost-saving I don&#8217;t know, but it doesn&#8217;t affect the argument).</p>
<p>Obviously this is an over-simplification; looking at the world through the eyes of a programmer, things naturally form into shapes and idioms that are common currency to the techie. But I think this there&#8217;s something to be gained from seeing the world this way. When people try and build rule sets, they get things wrong. Not because they are stupid, or unwilling, or corrupted, or bureaucratic, but simply because creating perfect rule sets isn&#8217;t something that humans are naturally capable of.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.asymptotic.co.uk/2010/07/debugging-in-the-real-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why is it so hard to report a bug?</title>
		<link>http://blog.asymptotic.co.uk/2010/07/why-is-it-so-hard-to-report-a-bug/</link>
		<comments>http://blog.asymptotic.co.uk/2010/07/why-is-it-so-hard-to-report-a-bug/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 22:48:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[psychology]]></category>

		<guid isPermaLink="false">http://blog.asymptotic.co.uk/?p=484</guid>
		<description><![CDATA[Not so long ago I had a misunderstanding with a colleague, who I&#8217;ll call Bob. I received a routine request for technical support from Bob, to which I replied immediately with a clear but brief explanation of how to solve the problem. An hour later, I got a slightly testy email from Bob to say [...]]]></description>
			<content:encoded><![CDATA[<p>Not so long ago I had a misunderstanding with a colleague, who I&#8217;ll call Bob. I received a routine request for technical support from Bob, to which I replied immediately with a clear but brief explanation of how to solve the problem. An hour later, I got a slightly testy email from Bob to say that his problem still wasn&#8217;t fixed, and it was really holding him up. I double-checked that the proposed solution worked, silently cursed Bob for being too simple to follow my instructions and pinged back an email with a longer and slightly more patronising set of instructions. Two hours later, a furious email from Bob, copied to the CEO. Didn&#8217;t I understand how important this issue was? A critical project was in the balance, and I hadn&#8217;t fixed his problem.</p>
<p>The punch line? Bob&#8217;s email hadn&#8217;t been working all morning, and nothing I sent had got through to him. Bob&#8217;s emails read to me as if he&#8217;d got my instructions and somehow failed to follow them correctly, so it looked to me like he was being inept. From Bob&#8217;s point of view, I was giving him stony silence that could only be explained by a lack of motivation.</p>
<p>I&#8217;m sure this kind of problem has been plaguing the interactions between technical and non-technical people for as long as there has been technology to bicker over. Users complain about bugs that don&#8217;t get fixed, while techies whinge that the users misdescribe their problems, foul things up further with misguided attempts to fix them and then fail to follow instructions when they get them. Why isn&#8217;t it going away as people get more tech-savvy?</p>
<p>Behaving correctly when you encounter a fault and reporting it in a productive way is a reasonably subtle task; Simon Tatham&#8217;s piece on <a href="http://www.chiark.greenend.org.uk/~sgtatham/bugs.html">how to report bugs effectively</a> is a very approachable and effective guide, but it&#8217;ll probably only ever be read by the motivated. Even so, you might think that sheer trial and error would teach people that certain ways of reporting a bug get the solution they&#8217;re after more quickly than others.</p>
<p>Some people suggest that we techies are lacking in communication skills, and that we need to work harder at making ourselves understood in order to engage with the modern workplace. This isn&#8217;t entirely without merit, but I think it&#8217;s facile. I&#8217;ve been lucky enough to work with some very articulate developers, and none have been immune to this kind of misunderstanding.</p>
<p>I think there&#8217;s something deeper going on here, and I think it lies in psychology. The <a href="http://en.wikipedia.org/wiki/Fundamental_attribution_error">fundamental attribution error</a> is the observed effect that people tend to attribute other people&#8217;s behaviour disproportionately to their character, neglecting the possibility of simple situational explanations. For example, I attributed Bob&#8217;s inability to solve his problem to his not taking the time to read my instructions properly, or being too poorly-skilled to put them into operation. All the time I was building up in my head a picture of Bob as an incompetent, over-confident bumbling oaf who shouldn&#8217;t be trusted to go near a keyboard—and all <em>because his email wasn&#8217;t working</em>.</p>
<p>But it goes the other way too. I&#8217;ve no doubt Bob had painted a picture to himself of me as an uncommunicative nerd who didn&#8217;t appreciate the importance of Bob&#8217;s project to the business. Neither of us even considered that there might be an alternative explanation.</p>
<p>The thinking that leads to the fundamental attribution error makes some sense, when you think about it. When you&#8217;re dealing with someone on a casual basis you can come to great harm by not making an assessment of their character, and assuming that any flaws you observe are likely to hurt you again in the future is a sound defensive position. This might lead to missed opportunities in casual acquaintances, but that could be a price worth paying.</p>
<p>This thinking is catastrophic, though, when it becomes an entrenched pattern that prevents the very nature of the problem from being properly understood. Blaming developers for being aloof, or users for being incompetent, only reinforces the stereotypes. Working on our communication skills only helps if the thoughts we communicate are based on the right model.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.asymptotic.co.uk/2010/07/why-is-it-so-hard-to-report-a-bug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Forwarding events in C#</title>
		<link>http://blog.asymptotic.co.uk/2010/03/forwarding-events-in-csharp/</link>
		<comments>http://blog.asymptotic.co.uk/2010/03/forwarding-events-in-csharp/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 10:19:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[events]]></category>

		<guid isPermaLink="false">http://blog.asymptotic.co.uk/?p=482</guid>
		<description><![CDATA[For a long time I&#8217;ve had a problem with events in C#: I want to wrap one class in another, which offers a higher level of abstraction, but this means that all the events have to be copied and lots of boilerplate code has to be written to do the forwarding. The obvious thing to [...]]]></description>
			<content:encoded><![CDATA[<p>For a long time I&#8217;ve had a problem with events in C#: I want to wrap one class in another, which offers a higher level of abstraction, but this means that all the events have to be copied and lots of boilerplate code has to be written to do the forwarding. The obvious thing to do would be to have an event exposed as a property, which would give clients of the abstract interface read-only access to the event:</p>
<pre>public class HigherLevelClass
{
   public event SomeDelegate MyEvent
   {
      get { return impl.MyEvent; }
   };

   private LowerLevelClass impl;

   /* ... */
}
</pre>
<p>Unfortunately this isn&#8217;t valid syntax, and at first glance that seems to be the end of it. However, I discovered today that the designers of C# have actually thought of this, and provided a way round it:</p>
<pre>public class HigherLevelClass
{
   public event SomeDelegate MyEvent
   {
      add { impl.MyEvent += value; }
      remove { impl.MyEvent -= value; }
   };
}
</pre>
<p>Simple, once you know how. But this illustrates an interesting problem with keyword search when applied to programming techniques: I&#8217;ve searched for just this information on several occasions, but wasn&#8217;t able to find it until I hit on the magic phrase &#8220;event forwarding&#8221;. In my experience it&#8217;s pretty common to know how to describe what you&#8217;d <em>like</em> something to do, but not be able to find the same words as the person who knows how to do it.</p>
<p>I&#8217;m sure this is far from the only reason, but perhaps it goes some way to explaining why there are eight separate implementations of every single open source library type, each of which is partially complete.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.asymptotic.co.uk/2010/03/forwarding-events-in-csharp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>You were never meant to do that with SQL</title>
		<link>http://blog.asymptotic.co.uk/2009/12/you-were-never-meant-to-do-that-with-sql/</link>
		<comments>http://blog.asymptotic.co.uk/2009/12/you-were-never-meant-to-do-that-with-sql/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 17:10:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Optimisation]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://blog.asymptotic.co.uk/?p=422</guid>
		<description><![CDATA[There seems to be a lot of hatred for SQL in the world at the moment: I can&#8217;t think of any other reason why the term NoSQL would catch on in the way that it has, when the key technological distinction is actually the lack of ACID guarantees (which are entirely orthogonal to whether or [...]]]></description>
			<content:encoded><![CDATA[<p>There seems to be a lot of hatred for SQL in the world at the moment: I can&#8217;t think of any other reason why the term <a href="http://en.wikipedia.org/wiki/Nosql">NoSQL</a> would catch on in the way that it has, when the key technological distinction is actually the lack of <a href="http://en.wikipedia.org/wiki/ACID">ACID guarantees</a> (which are entirely orthogonal to whether or not SQL is used, as evidenced by non-ACID MySQL and <a href="http://wiki.apache.org/hadoop/Hive/LanguageManual">HiveQL</a>, which offers a pretty familiar SQL-like interface on an entirely non-traditional backend).</p>
<p>I wonder whether one of the unspoken reasons for this hatred is that at one point or another almost everyone has ended up doing this sort of thing:</p>
<pre>   builder.Add("SELECT foo FROM bar WHERE id = ");
   builder.Add(id.ToString());

   if (additionalConstraint)
   {
      builder.Add(" AND frobbable = 1 ");
   }

   /* ... ad nauseam ... */</pre>
<p>SQL is a hard language to like: it&#8217;s never been properly standardised (or rather, it has, but the standard has never been implemented) meaning that you spend too much time worrying about compatibility. Its theoretical underpinning is poor, leading to constructions that are hard for the engine to optimise (meaning more manual work).</p>
<p>However, SQL is a language in its own right, and was never intended to be generated programmatically by another programming language. This shouldn&#8217;t come as a surprise, as I struggle to think of any programming language that has been designed to work in this way.</p>
<p>Using SQL from a decent command-line environment is a  powerful tool and often a pleasure to use. By comparison, generating SQL programmatically is an abomination that would be worth of <a href="http://thedailywtf.com/">The Daily WTF</a> were it not for the fact that nobody&#8217;s ever invented an API that offers the same flexibility.</p>
<p>Personally, I blame the vendors. Until RDBMSs can offer the same quality of optimisation that modern compilers can (that is, write in a high-level language and never even think about micro-optimisation) high-performance relational database access will remain a sea of vendor-specific optimiser hacks. Maybe there&#8217;s a theoretical reason why optimisers will never be this good, in which case perhaps we do need to abandon the relational model in practice. But let&#8217;s not pretend it has anything to do with SQL.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.asymptotic.co.uk/2009/12/you-were-never-meant-to-do-that-with-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Project Euler in F#: Problem 8</title>
		<link>http://blog.asymptotic.co.uk/2009/12/project-euler-in-f-problem-8/</link>
		<comments>http://blog.asymptotic.co.uk/2009/12/project-euler-in-f-problem-8/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 21:13:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[F#]]></category>

		<guid isPermaLink="false">http://blog.asymptotic.co.uk/?p=373</guid>
		<description><![CDATA[I&#8217;ve been trying to teach myself F# using the Project Euler problems, and I&#8217;m starting to feel I&#8217;m getting somewhere with the language. The few Euler problems I&#8217;ve solved so far have had very straightforward and natural solutions.
Problem 8 is as follows: Find the subsequence of 5 consecutive digits that yield the greatest product when [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been trying to teach myself F# using the <a href="http://www.projecteuler.net/">Project Euler</a> problems, and I&#8217;m starting to feel I&#8217;m getting somewhere with the language. The few Euler problems I&#8217;ve solved so far have had very straightforward and natural solutions.</p>
<p>Problem 8 is as follows: Find the subsequence of 5 consecutive digits that yield the greatest product when multiplied together, in the 1000-digit number:</p>
<blockquote><p>73167176531330624919225119674426574742355349194934<br />
96983520312774506326239578318016984801869478851843<br />
85861560789112949495459501737958331952853208805511<br />
12540698747158523863050715693290963295227443043557<br />
66896648950445244523161731856403098711121722383113<br />
62229893423380308135336276614282806444486645238749<br />
30358907296290491560440772390713810515859307960866<br />
70172427121883998797908792274921901699720888093776<br />
65727333001053367881220235421809751254540594752243<br />
52584907711670556013604839586446706324415722155397<br />
53697817977846174064955149290862569321978468622482<br />
83972241375657056057490261407972968652414535100474<br />
82166370484403199890008895243450658541227588666881<br />
16427171479924442928230863465674813919123162824586<br />
17866458359124566529476545682848912883142607690042<br />
24219022671055626321111109370544217506941658960408<br />
07198403850962455444362981230987879927244284909188<br />
84580156166097919133875499200524063689912560717606<br />
05886116467109405077541002256983155200055935729725<br />
71636269561882670428252483600823257530420752963450</p></blockquote>
<p>I was able to come up with an F# solution that is one line, plus a helper line to convert the string into a sequence of digits:</p>
<pre>let str = "731&lt;...&gt;"

let digits = Seq.map (fun x -&gt; int (Char.GetNumericValue x)) str

let maxproduct num list =
 Seq.max (Seq.map (fun x -&gt; Seq.reduce (*) x) (Seq.windowed num list))</pre>
<p>The value <tt>digits</tt> is just a list of the digits in the string, converted into integers. The function <tt>maxproduct</tt> works the obvious way: take every subsequence of five digits (<tt>Seq.windowed</tt>), multiply them together (<tt>Seq.reduce</tt>, applied to each element of the sequence with <tt>Seq.map</tt>) and then find the maximum (<tt>Seq.max</tt>).</p>
<p>The only reason this needs quite so little work is the existence of <a href="http://msdn.microsoft.com/en-us/library/ee340420%28VS.100%29.aspx"><tt>Seq.windowed</tt></a> in the standard library, which does exactly the right thing in turning a 1000-element list into 996 arrays of subsequences of consecutive digits.</p>
<p>I&#8217;m not sure I like ramming all the functions into one line, and I&#8217;m sure there must be a way to combine map and reduce without the lambda, which adds a lot of clutter. If this was real code, it would need quite a lot of work to make it readable. However, the standard library is a big win, because the process of &#8216;windowing&#8217; a sequence is nicely separated from the code. It&#8217;s also nice (for toy problems like this, at any rate) that the program is pretty much a definition of the problem, with little thought being necessary as to how to do the processing.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.asymptotic.co.uk/2009/12/project-euler-in-f-problem-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Relational Database Basics: What is a relation?</title>
		<link>http://blog.asymptotic.co.uk/2009/12/relational-database-basics-what-is-a-relation/</link>
		<comments>http://blog.asymptotic.co.uk/2009/12/relational-database-basics-what-is-a-relation/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 10:19:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[relational theory]]></category>

		<guid isPermaLink="false">http://blog.asymptotic.co.uk/?p=321</guid>
		<description><![CDATA[The biggest misunderstanding people tend to have with the relational model must be the understanding of the term &#8220;relation&#8221; itself. Since people tend to learn relational theory as an add-on to learning about SQL, they naturally learn that the things you put the data in are called &#8220;tables&#8221; and that tables are related to each [...]]]></description>
			<content:encoded><![CDATA[<p>The biggest misunderstanding people tend to have with the relational model must be the understanding of the term &#8220;relation&#8221; itself. Since people tend to learn relational theory as an add-on to learning about SQL, they naturally learn that the things you put the data in are called &#8220;tables&#8221; and that tables are related to each other. The natural (but incorrect) assumption then, is that &#8220;relational&#8221; refers to the relationships that exist <em>between</em> tables, and this couldn&#8217;t be more wrong.</p>
<h3>The simplest explanation</h3>
<p>Put simply, a &#8220;relation&#8221; is what SQL calls a table. If you learn nothing else about relational theory, at least understand this. This is an oversimplification of course, but it&#8217;s close enough to being true that if you don&#8217;t want to learn any theory, it will at least make the discussions of theorists more comprehensible.</p>
<h3>The mathematical explanation</h3>
<p>This isn&#8217;t the best way to <em>understand</em> what a relation is, but if you intend to have meaningful discussions with other practitioners, you will need to have a common understanding based on a definition that is unambiguous. I&#8217;ll therefore get the mathematical explanation out of the way here; if it doesn&#8217;t make much sense, return to it after the more intuitive description below. Though this is a relatively formal description, it doesn&#8217;t come close to being totally precise, and anyone who wants to know more is encouraged to investigate a book on the subject.</p>
<p>An <em>attribute</em> is a combination of a <em>name</em> and a  <em>type</em> identifier, where we can for the moment treat a type as being a (possibly infinite) set of values with some operators defined on it. Think of an attribute as being like a column definition.</p>
<p>A <em>tuple</em> is a set of distinct attributes, where each attribute is associated with one value that is an instance of the type for that attribute. The members of a tuple do not posess an inherent order, and tuples ordered in different ways for display purposes nevertheless represent the same tuple.</p>
<p>A <em>relation</em> consists of a <em>heading</em> and a <em>body</em>. The heading is a (possibly empty) set of attributes with distinct names. The body is a (possibly empty) set of tuples, each of which has the same set of attributes as the heading of the relation.</p>
<p>To put this in terms familiar to an SQL user: an attribute is analogous to a column definition, a tuple is analogous to a row and a relation is analogous to a table. Note that this is an over-simplification, mostly because we think of the rows and columns of a table as posessing an inherent order, and mathematical relations have no such order.</p>
<p>One other thing that bears stating at this point is that a relation is technically an <em>immutable</em> value, and is held in a mutable variable called a <em>relvar</em>. This is analogous to common programming practice where an integer like 5 is immutable, but held in a mutable integer variable. If you &#8220;insert a row into a table&#8221;, then actually you change the contents of that relvar from one relation to another. This distinction is rarely of relevance in discussing theoretical issues.</p>
<h3>The intuitive explanation</h3>
<p>Unless you&#8217;re already familiar with relational theory, that was probably all rather unclear, in which case the only vital things to take away are: columns are unordered, and rows are unordered. If you are familiar with relational theory, you&#8217;re probably angry at me for making so many mistakes, in which case please point them out in the comments.</p>
<p>So what does this mean in intuitive terms? A common intuitive feeling about tables is that they represent a list of entities, and indeed this understanding works nicely for simple cases. Take a table of salaried employees in FictoCorp:</p>
<div class="mceTemp">
<dl id="attachment_324" class="wp-caption alignnone" style="width: 543px;">
<dt class="wp-caption-dt"><img class="size-full wp-image-324" title="employees_table" src="http://blog.asymptotic.co.uk/wp-content/uploads/2009/11/employees_table.png" alt="Table showing list of employees in a fictional company" width="533" height="184" /></dt>
</dl>
</div>
<p>The head of HR for this company might look at the table and say, &#8220;yep, those are my employees—I&#8217;d recognise &#8216;em anywhere.&#8221; As far as they&#8217;re concerned, each row in this table represents one of the employees they have to deal with. Furthermore, no row represents more than one employee, and there&#8217;s no employee of the company who doesn&#8217;t have a row.</p>
<p>It just so happens that FictoCorp (who have a lot of important customers in the netball industry) has a policy that all employees must play for one of the company&#8217;s netball teams. In order to keep track of this, the team captain keeps the following table in the company database:</p>
<div class="mceTemp">
<dl id="attachment_325" class="wp-caption alignnone" style="width: 543px;">
<dt class="wp-caption-dt"><img class="size-full wp-image-325" title="players_table" src="http://blog.asymptotic.co.uk/wp-content/uploads/2009/11/players_table.png" alt="A table showing the netball teams and positions of fictional players" width="533" height="184" /></dt>
</dl>
</div>
<p>We&#8217;ll simplify things by only displaying four employees, though obviously there would be more.</p>
<p>As an aside, netball has the nice property that the positions are named and unique; no player can be on the same team playing in the same position as another player. Therefore the combination of Netball Team and Position uniquely identifies a single employee. Obviously this constraint makes it impossible for FictoCorp to hire or fire people other than in unisex groups of 7 (in order that they can add or remove an entire netball team at once), but hey, it&#8217;s worth it for all the lucrative netball-industry contacts.</p>
<p>As far as the netball club captain is concerned, the entries in this table <em>are</em> the employees. Any employee will be in this table, and anyone in this table is an employee. So who is right, the HR manager or the netball club captain? Which table &#8220;holds&#8221; the employees? And if one table &#8220;is&#8221; the set of employees, what does that mean about the other table?</p>
<h4>A digression</h4>
<p>FictoCorp&#8217;s netball teams are so successful that the major league teams start to send talent scouts to their games. One day, the manager of a professional team rings up to enquire about hiring one of FictoCorp&#8217;s players.</p>
<blockquote><p>&#8220;He was brilliant, we just have to have him &#8230; Any price, any price at all &#8230; His name? I don&#8217;t remember that, but he was definitely playing Wing Attack for your Men&#8217;s First team&#8221;</p></blockquote>
<p>Luckily, with this information is all that is needed to identify that the player in question is Charles. The table of netball players worked equally well as a way of finding a player from their netball team and position as vice versa.</p>
<p>From the point of view of an outsider to FictoCorp, the table <em>is</em> a list of teams and playing positions, with the useful effect that the player&#8217;s name can be looked up. The talent scout&#8217;s view and the club manager&#8217;s view of the meaning of the table are different, but both are using the same table.</p>
<h4>Resolving the ambiguity</h4>
<p>The netball players table is neither a container of people, nor a container of playing positions. Both of these are <em>extrinsic</em> to the table: they will continue to exist if the table is deleted, though FictoCorp may no longer have the information it needs to get the necessary work done.</p>
<p>One way to think of the relation is in terms of the corresponding <em>predicate</em>: a function that takes a group of objects and produces a true or false value. An informal definition of the predicate for the netball players table might be:</p>
<p style="padding-left: 30px;">There exists a player called X, who plays on team Y in position Z</p>
<p>If we substitute into this values from the table, we get true values from the function:</p>
<p style="padding-left: 30px;">There exists a player called <strong>Alice</strong>, who plays on team <strong>W1</strong> in position <strong>GA</strong> (<em>true</em>)</p>
<p style="padding-left: 30px;">There exists a player called <strong>Charles</strong>, who plays on team <strong>M1</strong> in position <strong>WA</strong> (<em>true</em>)</p>
<p>If we substitute in other values, we get false values from the function</p>
<p style="padding-left: 30px;">There exists a player called <strong>Charles</strong>, who plays on team <strong>W1</strong> in position <strong>WA</strong> (<em>false</em>)</p>
<p>You can think of this as a function on a 3-dimensional space, where one dimension is the list of every person in the world, one dimension is every netball team FictoCorp has and the final dimension is every possible position in a netball team:</p>
<div class="mceTemp">
<dl id="attachment_332" class="wp-caption alignnone" style="width: 356px;">
<dt class="wp-caption-dt"><img class="size-full wp-image-332" title="relation_visualisation" src="http://blog.asymptotic.co.uk/wp-content/uploads/2009/11/relation_visualisation.png" alt="Diagram of a relation on a 3-dimensional space" width="346" height="351" /></dt>
</dl>
</div>
<p>The predicate is a function over this entire 3-dimensional space. The tuples (rows) in the relation represent points in this space for which the function evaluates to true. Tuples that could be in the table, but aren&#8217;t, represent points in this space for which the predicate evaluates to false.</p>
<p>Things to note:</p>
<ul>
<li>The predicate evaluates to true or false on every point in this space; nowhere in the space is the predicate undefined</li>
<li>The predicate can&#8217;t be evaluated anywhere <em>but</em> points in this space; it would be meaningless to do so</li>
</ul>
<p>In a sense, the predicate give the <em>meaning</em> of the table, and this meaning won&#8217;t change as we add and remove players from various teams. The tuples in the relation (the rows in the table) show us what is currently true <em>in the real world</em>. It is a goal of a well-maintained database that the facts implied by the table always remain a true representation of what is true in the real world, for drawing conclusions about the real world is the reason databases exist.</p>
<h4>Objections to this model</h4>
<p>One obvious objection to this model is that if people, salaries, netball team positions etc. are all extrinsic to the tables, how do we keep track of an entity that happens not to appear in any of the tables? If FictoCorp has a contractor called Edgar working for the company who isn&#8217;t in the employees table, and is excused from being in any of the netball teams, how do we keep track of this person?</p>
<p>The answer is that the database contains all the information we want to store, <em>and nothing else</em>. If the database system needs to be able to be used to answer questions about contractors, it will have a contractors table in which Edgar will appear. If for some reason FictoCorp doesn&#8217;t care to know what contractors it has relationships with, then Edgar will be a non-entity as far as the database is concerned.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.asymptotic.co.uk/2009/12/relational-database-basics-what-is-a-relation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Book Review: SQL and Relational Theory</title>
		<link>http://blog.asymptotic.co.uk/2009/12/book-review-sql-and-relational-theory/</link>
		<comments>http://blog.asymptotic.co.uk/2009/12/book-review-sql-and-relational-theory/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 14:43:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[relational theory]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://blog.asymptotic.co.uk/?p=341</guid>
		<description><![CDATA[

 


The first thing to know about SQL and Relational Theory is that it&#8217;s largely a retread of Chris Date&#8217;s previous excellent book Database in Depth. The latter is a favourite of mine: extremely readable, yet with enough theoretical clout to change the way I looked at databases forever. The new volume carries over large [...]]]></description>
			<content:encoded><![CDATA[<div class="mceTemp">
<dl id="attachment_340" class="wp-caption alignleft" style="width: 132px;">
<dt class="wp-caption-dt"> <a href="http://www.amazon.co.uk/gp/product/0596523068?ie=UTF8&amp;tag=reviewtfm-21&amp;linkCode=as2&amp;camp=1634&amp;creative=19450&amp;creativeASIN=0596523068"><img class="size-full wp-image-340" title="51cUKPgnCyL._SL160_" src="http://blog.asymptotic.co.uk/wp-content/uploads/2009/11/51cUKPgnCyL._SL160_.jpg" alt="Front cover of the book &quot;SQL and Relational Theory&quot;" width="122" height="160" /></a></dt>
</dl>
</div>
<p>The first thing to know about <a href="http://www.amazon.co.uk/gp/product/0596523068?ie=UTF8&amp;tag=reviewtfm-21&amp;linkCode=as2&amp;camp=1634&amp;creative=19450&amp;creativeASIN=0596523068">SQL and Relational Theory</a> is that it&#8217;s largely a retread of Chris Date&#8217;s previous excellent book <a href="http://www.amazon.co.uk/gp/product/0596100124?ie=UTF8&amp;tag=reviewtfm-21&amp;linkCode=as2&amp;camp=1634&amp;creative=19450&amp;creativeASIN=0596100124">Database in Depth</a>. The latter is a favourite of mine: extremely readable, yet with enough theoretical clout to change the way I looked at databases forever. The new volume carries over large chunks of the text from the older one, with some minor tweaks. As the name suggests, it brings in substantial additional material to link relational theory in with SQL, the only practical implementation of the model in current use.</p>
<div class="mceTemp">
<dl id="attachment_344" class="wp-caption alignright" style="width: 132px;">
<dt class="wp-caption-dt"><a href="http://www.amazon.co.uk/gp/product/0596100124?ie=UTF8&amp;tag=reviewtfm-21&amp;linkCode=as2&amp;camp=1634&amp;creative=19450&amp;creativeASIN=0596100124"><img class="size-full wp-image-344" title="41MQ41V09GL._SL160_" src="http://blog.asymptotic.co.uk/wp-content/uploads/2009/11/41MQ41V09GL._SL160_.jpg" alt="The front cover of &quot;Database in Depth&quot;" width="122" height="160" /></a></dt>
</dl>
</div>
<p>In the preface, Date explains that the motivation for the new book was the realisation that practitioners weren&#8217;t able to figure out for themselves how to apply his theoretical ideas within SQL. Clearing up this difficulty is an admirable goal, and illustrates well that Date&#8217;s approach is practical and not meant as ivory-tower theory, but I can&#8217;t help but wonder if one of the reasons he didn&#8217;t state was that books sell better with &#8216;SQL&#8217; in the title.</p>
<p>The additional material has resulted in a book that is roughly twice as long. This isn&#8217;t a problem in itself, though it does spoil one of the things I loved about &#8220;In Depth&#8221;: that it could be read in a couple of evening&#8217;s work by a sufficiently motivated person. The importance of making a book light enough that you can sit and read it on the sofa without looking like a database nerd should not be understated.</p>
<p>The prose remains clear and readable, and strikes a nice balance that makes it approachable to relative beginners while avoiding ever sounding patronising. Date&#8217;s style is precise to a fault, and some people will find it needlessly pedantic; nevertheless, there isn&#8217;t any pointless pedantry here, and if you stick with it you&#8217;ll learn why subtle distinctions need to be made.</p>
<p>So how useful are the new insertions on SQL? I find it difficult to tell. On the one hand, it makes it much easier to relate the ideas in this book to discussions of theory that actually occur in the real world, since SQL is the <em>lingua franca</em>. In the old book, it was certainly annoying to have all the examples written in Tutorial D, without a real specification of how the language works. On the other hand, Date&#8217;s examples in this book are still in a mythical beast called &#8220;Standard SQL&#8221;, of which no practical implementation exists. What is good practice in standard SQL might be impossible in your chosen implementation, or there might be a better way to achieve the same thing.</p>
<p>It&#8217;s certainly worth buying one of the two books here, but the choice of which is not as obvious. If you already own &#8220;In Depth&#8221;, the updated version probably isn&#8217;t worth buying. If you don&#8217;t, then &#8220;SQL and Relational Theory&#8221; is the thing to buy, unless you&#8217;re after a lighter and more portable read.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.asymptotic.co.uk/2009/12/book-review-sql-and-relational-theory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What do you get if you cross Richard Stallman with Ayn Rand?</title>
		<link>http://blog.asymptotic.co.uk/2009/11/what-do-you-get-if-you-cross-richard-stallman-with-ayn-rand/</link>
		<comments>http://blog.asymptotic.co.uk/2009/11/what-do-you-get-if-you-cross-richard-stallman-with-ayn-rand/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 13:24:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Politics]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://blog.asymptotic.co.uk/?p=299</guid>
		<description><![CDATA[&#8220;Quite simply, not enough schools perform like the best. In fact, results tend to hover around the national average.&#8221; — A UK government minister explains education
On of Richard Stallman&#8217;s points was that software producers need to stop competing with each other in order to ensure our output is the best that it can possibly be. [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>&#8220;Quite simply, not enough schools perform like the best. In fact, results tend to hover around the national average.&#8221; — <em>A UK government minister explains education</em></p></blockquote>
<p>On of Richard Stallman&#8217;s points was that software producers need to stop competing with each other in order to ensure our output is the best that it can possibly be. Ayn Rand argued that we need to compete with each other constantly in order to ensure our output is the best that it can possibly be.</p>
<p>The wish to make more things brilliant and less of them mediocre drives a lot of people, from the greatest entrepreneurs and inventors to whichever hapless minister produced the quotation with which I began this article (I was unable to find any source on the web, and I&#8217;m forced to admit it may have been apocryphal.)</p>
<p>But the method by which we make the world a better place is a fiercely contentious question, and many of the people on the extremes will, when push comes to shove, put ideology ahead of results. Nothing wrong with that, but it leaves those of us in the middle lacking clear role models when it comes to pursuing a more consequentialist approach. This is particularly difficult to do when we identify strongly with their goals, if not their ideologies.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.asymptotic.co.uk/2009/11/what-do-you-get-if-you-cross-richard-stallman-with-ayn-rand/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
