<?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>while coding</title>
	<atom:link href="http://www.youell.com/matt/writing/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.youell.com/matt/writing</link>
	<description>simplify</description>
	<lastBuildDate>Mon, 16 Aug 2010 03:50:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A Fork in the Road</title>
		<link>http://www.youell.com/matt/writing/?p=763</link>
		<comments>http://www.youell.com/matt/writing/?p=763#comments</comments>
		<pubDate>Mon, 16 Aug 2010 03:50:44 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[problem solving]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software industry]]></category>

		<guid isPermaLink="false">http://www.youell.com/matt/writing/?p=763</guid>
		<description><![CDATA[I got into an interesting conversation the other day with my pairing partner about the approach he and I wanted to take while trying to fix a bug. What followed was something of an existential conversation about software, complexity, and the role of the programmer in managing complexity.
We work with a small but quite tangled [...]]]></description>
			<content:encoded><![CDATA[<p>I got into an interesting conversation the other day with my pairing partner about the approach he and I wanted to take while trying to fix a bug. What followed was something of an existential conversation about software, complexity, and the role of the programmer in managing complexity.</p>
<p>We work with a small but quite tangled system. The system itself is only a few years old but contains many technologies and bears the scars of several smart but inexperienced people learning how to design as they went. I won&#8217;t articulate the details of the bug we were experiencing but I will say that it is something that recently appeared and was troublesome but non-critical.</p>
<p>The difference in our two points of view became apparently very quickly. My desired approach was to try to pin down the bug, deconstruct it to the point of understanding, and then apply a fix. My coworker&#8217;s approach was to make a well-educated guess about the cause of the bug and apply a refactoring to our codebase that would address the anticipated problem.</p>
<p>His reasoning was that our codebase was too complex to spend time trying to understand it in detail, and in the worst-case scenario we would still have completed a useful refactoring that improved the quality of our codebase. I found this a bit hopeless. Is software really so complex that we as programmers now have to act like doctors &#8211; diagnosticians &#8211; making reasoned guesses about the world around us? Is there no more engineering?</p>
<p>10 or 15 years ago I would have considered his approach ridiculous. Now I&#8217;m honestly not sure. Modern software systems contain so much abstraction and layering that it is really hard to judge the level of effort that will be involved in addressing any one problem.</p>
<p>So what option did we choose? We guessed and did the refactoring. I don&#8217;t think I would have agreed to that with just any pair partner, but this particular coworker is a very productive programmer. He had a clear path forward and a clear rationale.  And one thing you don&#8217;t do with a productive programmer is get in their way.</p>
<p>Did it work? No. I almost want to say &#8220;OF COURSE NOT!&#8221; but that would be unfair. It could very easily have worked. What did eventually work? A pair sitting down and tracing through the application stack with <a href="http://www.gnu.org/software/gdb/">gdb</a>. And even that has only located the approximate location of the error. We still haven&#8217;t solved the problem yet. But we&#8217;re much closer.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.youell.com/matt/writing/?feed=rss2&amp;p=763</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction To Wheeler, Part 3: Transitions and Mutual Dispatch</title>
		<link>http://www.youell.com/matt/writing/?p=665</link>
		<comments>http://www.youell.com/matt/writing/?p=665#comments</comments>
		<pubDate>Thu, 22 Jul 2010 00:59:10 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Road To Wheeler]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming languages]]></category>

		<guid isPermaLink="false">http://www.youell.com/matt/writing/?p=665</guid>
		<description><![CDATA[Hey, quick, watch this video before you read any further. It&#8217;s under 2 minutes long and it is *fascinating*.

That video is about how cell membranes work. Did you notice how proteins, enzymes, etc. can only pass through the cell membrane if they are the right shape (and flavor)? That&#8217;s how values trigger transitions in Wheeler.
Transitions
If [...]]]></description>
			<content:encoded><![CDATA[<p>Hey, quick, watch this video before you read any further. It&#8217;s under 2 minutes long and it is *fascinating*.</p>
<p><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/owEgqrq51zY&amp;hl=en_US&amp;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/owEgqrq51zY&amp;hl=en_US&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></p>
<p>That video is about how cell membranes work. Did you notice how proteins, enzymes, etc. can only pass through the cell membrane if they are the right shape (and flavor)? That&#8217;s how values trigger transitions in Wheeler.</p>
<h3>Transitions</h3>
<p>If categories are the most minimal representation of state, then transitions are the most minimal representation of action. Transitions are how computation happens in Wheeler. After all, organizing data is only half the battle with programming. Once you have the data in the form you want, you have to actually <em>do something</em>.</p>
<p>You can think of transitions as being very much like an event handler. You define a transition to trigger when an interaction between one or more categories happens.</p>
<p>Since Wheeler is still a work in progress, transitions are not yet native. Instead, transitions are created in Python, the language Wheeler is built on.</p>
<p>Remember our Hello example?</p>
<p><img src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/hello_world_363x174.png" alt=""  style="float: none"/></p>
<p>Here&#8217;s the transition defined for it in Python:</p>
<pre class="syntax-highlight:php">
def printer(category):
	for item in category:
		print item.name[1:-1],
	print
	return []

ROOT.create(&#039;print&#039;).add_handler( STRING, printer )
</pre>
<p>(I&#8217;ve omitted some unimportant details for clarity.)</p>
<p>What you might be able to suss out here is that there is a ROOT category that all categories live within, and I&#8217;ve created a &#8220;print&#8221; category within that. In addition, I&#8217;ve added a transition (with add_handler) which knows to watch for interactions with items in the string category. If the transition finds an interaction that matches, it executes the printer() function, which simply calls Python&#8217;s &#8216;print&#8217; function.</p>
<h3>Mutual Dispatch</h3>
<p>When more than one transition is triggered by an expression, the transitions all execute AND &#8211; at least in concept &#8211; they all execute *at the same time*.</p>
<p>This is very much like the real world. If two objects collide you don&#8217;t say that one or the other of them collided first. The collision is mutual and simultaneous. In that same way, when categories interact, the interaction is mutual and simultaneous.</p>
<p>Here&#8217;s the final snippet of Wheeler for this introduction:</p>
<p><img src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/mutual_dispatch.png" alt=""  style="float: none"/></p>
<p>In case it&#8217;s not clear what is going on here, we have some numbers, which are in the category &#8216;number&#8217;, some text in the category &#8217;string&#8217;, and some other categories (&#8217;print&#8217;, &#8216;+&#8217;) which give it all meaning with transitions. One transition knows to add all of the numbers in the expression when the plus sign is present. Another transition knows to print all of the strings in the expression to stdout when the &#8216;print&#8217; category is present.</p>
<p>When presented with this jumble of categories, Wheeler figures out what to do based on the criteria of the transitions. This effectively creates a typed-dispatch mechanism. I call this simultaneous, polymorphic behavior &#8220;Mutual Dispatch&#8221;.</p>
<p>That sums up Wheeler as currently implemented. </p>
<p>There&#8217;s still a lot of work to be done. I&#8217;ve covered what Wheeler is currently capable of. There are other planned features that I didn&#8217;t cover and hope to implement soon. I will provide more info here as new features are added.</p>
<p>I hope you find it as oddly fascinating as I do! Feedback is not just requested, it is begged for. I also strongly encourage you to <a href="http://github.com/built/wheeler">grab the code</a>, play, and contribute.</p>
<p>(Thanks to Westside Programmers and #pdxfunc for letting me present on Wheeler a few times over the past year. Having the chance to present and receive feedback has firmed up the concepts in my mind and made them easier to distill into this introduction.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.youell.com/matt/writing/?feed=rss2&amp;p=665</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction To Wheeler, Part 2: Values &amp; Types</title>
		<link>http://www.youell.com/matt/writing/?p=663</link>
		<comments>http://www.youell.com/matt/writing/?p=663#comments</comments>
		<pubDate>Wed, 21 Jul 2010 23:57:31 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Road To Wheeler]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming languages]]></category>

		<guid isPermaLink="false">http://www.youell.com/matt/writing/?p=663</guid>
		<description><![CDATA[(Note: It may be helpful to read the posts I did on types several months ago.)
Someone recently asked me if Wheeler had types. My answer was &#8220;No. Uhhh&#8230; and yes.&#8221; What a terrible answer! I&#8217;ll try to do better in this post.
Wheeler has no explicit type system. You will never declare a value to be [...]]]></description>
			<content:encoded><![CDATA[<p>(Note: It may be helpful to read the <a href="http://www.youell.com/matt/writing/?p=601">posts I did on types</a> several months ago.)</p>
<p>Someone recently asked me if Wheeler had types. My answer was &#8220;No. Uhhh&#8230; and yes.&#8221; What a terrible answer! I&#8217;ll try to do better in this post.</p>
<p>Wheeler has no explicit type system. You will never declare a value to be of a certain type. You might, however, associate a value with a particular category through an interaction. In that way you&#8217;re establishing a relationship that will allow typing *behavior*.</p>
<h3>What is a value?</h3>
<p>Values are the imaginary, interstitial things floating between categories. When you establish a relationship between categories in Wheeler, you&#8217;re creating values.</p>
<h3>What is a type?</h3>
<p>I won&#8217;t attempt to answer this in general. I am not a type theorist. From the perspective of Wheeler we might say that a type is determined by a graph&#8217;s &#8220;shape&#8221; and &#8220;flavor&#8221;. Shape is the actual form of the graph we create in memory (tree, ring, object, etc.). Flavor is what specific categories are being connected by that graph.</p>
<h3>What the hell is the difference?</h3>
<p>Context. It&#8217;s all context. A value will trigger typing behavior when something matching that shape and flavor is being watched for. At that point it could be considered a type. The rest of the time, a value.</p>
<h3>Layering values into types</h3>
<p>Have you ever seen an artist paint a landscape? First they&#8217;ll paint the background&#8230; the sky, the horizon, the land. Then they start to layer on more and more detail. At what point does their work become a painting? Existential arguments aside, you might say that the work is a painting when it meets the criteria of the artist. Criteria will vary from artist to artist. Everyone has their own objectives, aesthetics, etc. In other words, everyone brings their own point of view or <em>context</em> to a situation. This idea is so fundamental in Wheeler that it is a core value of the language:</p>
<p><strong>Context Drives Behavior</strong></p>
<p>To help understand this, let&#8217;s look at a Venn diagram. (Venn diagrams are quite handy for discussing concepts in Wheeler.)</p>
<p><img src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/value_cars.png" alt=""  style="float: none"/></p>
<p>Here you see we&#8217;ve got just a category, Cars. You could think of that as a type. Let&#8217;s pile on some more specifics:</p>
<p><img src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/value_cars_honda.png" alt=""  style="float: none"/></p>
<p><img src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/value_cars_honda_element.png" alt=""  style="float: none"/></p>
<p>Now we&#8217;ve got all cars that are Honda Elements. That&#8217;s more specific, but it&#8217;s still more like a type than anything.</p>
<p><img src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/value_cars_honda_element_vin.png" alt=""  style="float: none"/></p>
<p>Ah, but now that we have a VIN, the unique Vehicle Identification Number. That&#8217;s so unique as to specify a particular vehicle. That seems more like a concrete value now. Yay.</p>
<p><img src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/value_cars_honda_element_vin_actual.png" alt=""  style="float: none"/></p>
<p>Next time we&#8217;ll look at <em>Transitions</em> which allow computation in Wheeler. Then we&#8217;ll exercise our type and value scheme.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.youell.com/matt/writing/?feed=rss2&amp;p=663</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction To Wheeler, Part 1: Categories &amp; Interactions</title>
		<link>http://www.youell.com/matt/writing/?p=659</link>
		<comments>http://www.youell.com/matt/writing/?p=659#comments</comments>
		<pubDate>Thu, 08 Jul 2010 16:07:39 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Road To Wheeler]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming languages]]></category>

		<guid isPermaLink="false">http://www.youell.com/matt/writing/?p=659</guid>
		<description><![CDATA[I started my &#8220;Road to Wheeler&#8221; series last year to introduce some of the ideas behind Wheeler, a new programming language I&#8217;ve been developing. Instead of continuing that discussion I&#8217;m going to explain through demonstration. This is the first in a series of posts that will introduce the basic ideas behind Wheeler.
(You can play along [...]]]></description>
			<content:encoded><![CDATA[<p>I started my &#8220;Road to Wheeler&#8221; series last year to introduce some of the ideas behind Wheeler, a new programming language I&#8217;ve been developing. Instead of continuing that discussion I&#8217;m going to explain through demonstration. This is the first in a series of posts that will introduce the basic ideas behind Wheeler.</p>
<p>(You can play along at home by grabbing <a href="http://github.com/built/wheeler">the latest code</a> and running the examples. You&#8217;ll need Python 2.5 and patience.)</p>
<p>First, let&#8217;s fire up &#8220;bigwheel&#8221;, the Wheeler interpreter:</p>
<p><img src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/bigwheel_349x150.png" alt="" style="float: none"/></p>
<p>Here is &#8220;Hello, world&#8221; in Wheeler:</p>
<p><img src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/hello_world_363x174.png" alt=""  style="float: none"/></p>
<p>Wheeler is flexible though, so you could also say:</p>
<p><img src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/hello_world2_355x150.png" alt=""  style="float: none"/></p>
<p>More on that later.</p>
<h3>Categories</h3>
<p>Wheeler is different from many languages you may be familiar with. All languages have abstractions. Some common examples are functions, lists, collections, stacks, pointers, and objects. In Wheeler, <strong>state</strong> is the fundamental abstraction.</p>
<p>State is represented by an abstraction called a Category. Categories are lightweight, atomic things. In Wheeler, <em>everything</em> is a category. Here are some sample categories:</p>
<ul>
<li>Fred</li>
<li>blue</li>
<li>5.3</li>
<li>&#8220;Hello, world!&#8221;</li>
<li>number</li>
<li>3/15/10</li>
<li>send</li>
<li>05:10:59</li>
<li>AM</li>
<li>PM</li>
<li>true</li>
<li>print</li>
</ul>
<p>Categories express boolean state. You&#8217;re either in a category or you&#8217;re not. Here&#8217;s an example:</p>
<p><img src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/apple_red.png" alt=""  style="float: none"/></p>
<p>Do you see that? No? Good. What you do not see is &#8216;apple&#8217; being put into the &#8216;red&#8217; category. That is happening behind the scenes through an <em>interaction</em> between apple and red.</p>
<p>Categories aren&#8217;t containers, but from a practical standpoint they act like containers. This allows you to make statements about the world. We can pile some more attributes on &#8220;apple&#8221;:</p>
<p><img src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/apple_red2.png" alt=""  style="float: none"/></p>
<h3>Interactions</h3>
<p>Interactions are expressions that combine categories to create new states. Our &#8220;Hello, world!&#8221; was an example of an interaction. Making our apple red was another interaction. Interaction is a mutual, simultaneous event where a connection (graph edge) is created between each item in the expression.</p>
<p>Wheeler has a &#8220;dump&#8221; command that will let you see (in GraphViz) the relationships you&#8217;ve created. Let&#8217;s dump &#8220;apple&#8221; and see the relationships:</p>
<p><img src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/apple_dump.png" alt=""  style="float: none"/></p>
<p>And the relationships as diagrammed in GraphViz:</p>
<p><img src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/apple_graph.png" alt=""  style="float: none"/></p>
<p>Here you can see that &#8220;apple&#8221; is related to &#8220;red&#8221;, &#8220;tasty&#8221;, and &#8220;sweet&#8221;. (You might notice that it is also related to &#8220;dump&#8221;, the category it interacted with to generate our diagram, and &#8220;metadata&#8221;, a built-in category.) </p>
<p>You can see that not only is &#8216;apple&#8217; connected to &#8216;red&#8217;, but &#8216;red&#8217; is also connected to &#8216;apple&#8217;. In Wheeler all relationships are bidirectional. This may seem odd if you&#8217;re used to typical hierarchical relationships in programming. Wheeler doesn&#8217;t think about the world that way. Wheeler has a few strongly-held beliefs, and one of these is:</p>
<p><strong>Hierarchy Is Bullshit</strong></p>
<p>Next time we&#8217;ll talk about composing categories into types.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.youell.com/matt/writing/?feed=rss2&amp;p=659</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Typical Types of Typing and the Types They Typify, Part 2</title>
		<link>http://www.youell.com/matt/writing/?p=627</link>
		<comments>http://www.youell.com/matt/writing/?p=627#comments</comments>
		<pubDate>Tue, 17 Nov 2009 11:31:59 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Road To Wheeler]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.youell.com/matt/writing/?p=627</guid>
		<description><![CDATA[Note: This is the conclusion of a two-part entry in my ongoing “Road to Wheeler” series.
In my last post I covered some of the popular type schemes used in programming today. I continued a little past where most discussions of type go when I pulled in pattern matching.
Deconstructing Types
Imagine that you are using a language [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Note: This is the conclusion of a two-part entry in my ongoing “Road to Wheeler” series.</p></blockquote>
<p>In <a href="/matt/writing/?p=601">my last post</a> I covered some of the popular type schemes used in programming today. I continued a little past where most discussions of type go when I pulled in pattern matching.</p>
<h4>Deconstructing Types</h4>
<p>Imagine that you are using a language with no data types and you want to implement some of the typing behavior that I showed in my last post. One way you might do it is with a <a href="http://en.wikipedia.org/wiki/Record_%28computer_science%29">record</a> used to associate type information with a value.</p>
<p>A C-style int might look something like this:</p>
<pre class="syntax-highlight:c">
x = (int, 5)
</pre>
<p>That&#8217;s pretty simple. We&#8217;re storing our value along with it&#8217;s type. Using that same scheme we can also represent a typical object instance:</p>
<pre class="syntax-highlight:c">
vendor = (Vendor, FirstName, LastName)
</pre>
<p>&#8220;Vendor&#8221; here is the classname, but it could also be an interface name. Or the record could contain a list of interfaces supported. Or, a list of methods implemented.</p>
<p>The pattern matching example from last time is already in record format. We&#8217;ll just change the Erlang braces to parentheses for continuity with the other examples:</p>
<pre class="syntax-highlight:c">
(customer, FirstName, LastName)
</pre>
<p>Let&#8217;s list all of these records together to compare them:</p>
<pre class="syntax-highlight:c">
(int, 5)
(Vendor, FirstName, LastName)
(customer, FirstName, LastName)
</pre>
<p>See the similarity? The types are from different methodologies, but they boil down to equivalent concepts.</p>
<h4>Our Own Imaginary Type Implementation</h4>
<p>I could easily define a function in my imaginary typeless language to properly handle any of these records:</p>
<pre class="syntax-highlight:python">
def display(record):

	type = record[0] # Key off first item in the record.

	if type == int:
		print_int(record)

	elif type == Vendor:
		print_vendor(record)

	elif type == customer:
		print_customer(record)
</pre>
<p>Is pattern matching a typing scheme? Do typing schemes devolve to pattern matching? </p>
<p>One thing I left out of my pattern matching example from last time: Patterns can match concrete values, such as specific numbers. In this example I&#8217;m expecting to find out just how overdue a customer&#8217;s account is:</p>
<pre class="syntax-highlight:c">
bill_with_msg({customer, 0}) -&gt; send_bill(&quot;Here&#039;s your new bill.&quot;);
bill_with_msg({customer, DaysOverdue}) -&gt; send_bill(&quot;Your bill is ~p days overdue.&quot;, DaysOverdue).
</pre>
<p>The first pattern matches on the atom &#8220;customer&#8221; and the specific value of 0 for the number of days overdue.</p>
<p>If we rewrote this in our typeless language with records it might look something like this:</p>
<pre class="syntax-highlight:python">
def bill_with_msg(record):

	type = record[0]
	days_overdue = record[1]

	if days_overdue == 0:
		send_bill(&quot;Here&#039;s your new bill&quot;)
	else:
		send_bill(&quot;You&#039;re bill is $days_overdue days overdue.&quot;)
</pre>
<h4>Guards Point The Way</h4>
<p>Have you seen guards? They&#8217;re pretty handy. Here&#8217;s an example of guards in Erlang:</p>
<pre class="syntax-highlight:c">
bill_with_msg({customer, 0}) -&gt; send_bill(&quot;New bill.&quot;);
bill_with_msg({customer, DaysOverdue}) when DaysOverdue &lt;= 30 -&gt; send_bill(&quot;Your bill is overdue.&quot;);
bill_with_msg({customer, DaysOverdue}) when DaysOverdue &gt; 30 -&gt; send_bill(&quot;YOUR BILL IS SERIOUSLY OVERDUE. PLEASE PAY NOW.&quot;).
</pre>
<p>Those &#8220;when&#8221; clauses are guards. And they&#8217;re pretty nice. In a fairly concise and clear way we&#8217;ve expressed our desire to do several things with relatively little code. In the process we&#8217;ve managed to unlock a new dimension to typing. If you accept that typing is essentially pattern matching you can see that the guards are actually adding extra dimension to our types by letting us do very specific pattern matching.</p>
<p>The trouble with guards is that they are bound to a function. What if you want to capture a certain type of customer (one who has spent more than $10k this year) so you can target them directly? You might find yourself with functions like this:</p>
<pre class="syntax-highlight:c">
bill_customer(customer, spent) when spent &gt; 10000 -&gt; preferred_billing().

find_shipping_options(customer, spent) when spent &gt; 10000 -&gt; preferred_shipping().

lookup_special_offers(customer, spent) when spent &gt; 10000 -&gt; offer_preferred_promos().
</pre>
<p>That&#8217;s a lot of repetition; a code smell. If you&#8217;re an OO type of person you might break that kind of customer out into it&#8217;s own class, generated by a factory. Or perhaps you might decorate your customer objects with particular account classes. And of course there might be many other strategies.</p>
<p>This might also be a good place for a macro if you&#8217;re a Lisper.</p>
<p>Another way might be to declare a type with the guard built-in. Here&#8217;s one way this might work with some made-up syntax:</p>
<pre class="syntax-highlight:c">
typedef Customer = Customer when spent &lt; 10000
typedef GoldCustomer = Customer when spent &gt;= 10000 and spend &lt; 10000
typedef PlatinumCustomer = Customer when spent &gt;= 100000
</pre>
<p>Here we&#8217;re creating some concise types on top of an existing type. Instead of subtyping or aggregating classes, we&#8217;re taking a class or data structure (Customer) and describing some situations where we&#8217;d like it to be treated specially. Now we can have polymorphic behavior on anything &#8211; types, values, or ranges of values.</p>
<p>This scheme will stretch a little farther:</p>
<pre class="syntax-highlight:c">

typedef Spam = String when contains &quot;viagra&quot;

def proc_mail(Spam msg):
	mark_and_toss()

def proc_mail(String msg):
	deliver(msg)
</pre>
<p>Of course you can only do this with lazy type evaluation, so there&#8217;s some runtime cost. I&#8217;m ok with that. Laziness has its virtues.</p>
<p>What I&#8217;ve presented so far is interesting but still rather flat. We can go farther. What if we can look at the shape of things too? After all, an interface represents a sort of shape. What if you just want to support objects that have a &#8220;Text&#8221; property? What if you only want to deal with Customers who have blue items in their RecentPurchases collection? Or more abstractly, what if we only want to deal with objects that expose a hashtable containing other hashtables?</p>
<p>Sound weird? It shouldn&#8217;t. It happens all the time, it just depends on the environment you work and code in. See also: jQuery, LINQ, RSpec, Hamcrest, etc., etc..</p>
<h4>This Way To The Egress</h4>
<p>I haven&#8217;t seen a type system that does exactly what I describe. Maybe you have. If so I hope you&#8217;ll tell me about it. Haskell&#8217;s type system is pretty nice (and I&#8217;m still learning), but seems to stop short of the dynamic behavior I&#8217;m looking for. Wheeler, the language I&#8217;m working on, aims (at least in part) for something very much like this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.youell.com/matt/writing/?feed=rss2&amp;p=627</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Typical Types of Typing and the Types They Typify, Part 1</title>
		<link>http://www.youell.com/matt/writing/?p=601</link>
		<comments>http://www.youell.com/matt/writing/?p=601#comments</comments>
		<pubDate>Mon, 02 Nov 2009 09:21:32 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Road To Wheeler]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.youell.com/matt/writing/?p=601</guid>
		<description><![CDATA[Note: This is the first of a two-part entry in my  ongoing &#8220;Road to Wheeler&#8221; series.
In the C language, where I was first introduced to the concept of &#8220;type&#8221;, types are metadata associated with some bytes. Here&#8217;s some C code:

int x = 5;

int z = x + 3;

Here x, z, 5, and 3 are [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Note: This is the first of a two-part entry in my  ongoing &#8220;<a href="http://www.youell.com/matt/writing/?p=583">Road to Wheeler</a>&#8221; series.</p></blockquote>
<p>In the C language, where I was first introduced to the concept of &#8220;type&#8221;, types are metadata associated with some bytes. Here&#8217;s some C code:</p>
<pre class="syntax-highlight:c">
int x = 5;

int z = x + 3;
</pre>
<p>Here x, z, 5, and 3 are all understood to be &#8216;int&#8217;s. What&#8217;s an int? The computer doesn&#8217;t really care. It just knows that an int is going to be a certain number of bytes in memory.</p>
<h4>If She&#8217;s Lucky, I&#8217;ll Show Her My OO Face</h4>
<p>In a common OO language like C++ or Java, we start to think of types in more abstract terms. We&#8217;re no longer thinking solely in terms of memory footprint. Now we&#8217;re thinking in terms of interface. Also, the concept of &#8220;type&#8221; becomes very closely bound with the notion of polymorphism: We expect that a function with two different implementations will &#8220;automagically&#8221; catch the proper value that gets thrown at it:</p>
<pre class="syntax-highlight:java">
// Imagine a few classes, which I won&#039;t bother to fill out:
class Person;
class Customer : Person;
class Vendor : Person;

public void Display(Customer thingy)
{
	// Do something customer-specific here.
}

public void Display(Vendor thingy)
{
	// Do something vendor-specific here.
}
</pre>
<p>That&#8217;s about as far as a lot of programmers in the Java, C# and C++ worlds seem to go in terms of thinking about types. That&#8217;s too bad, because there&#8217;s more going on.</p>
<h4>Quack Quack</h4>
<p><a href="http://en.wikipedia.org/wiki/Duck_typing">Duck typing</a> is the big thing outside of most of the static typing world. Essentially duck typing depends purely on behavior &#8211; if an implicit interface is available, things work. By &#8220;implicit interface&#8221;, I mean if the functions and properties on a class which are expected actually exist. &#8220;If it walks like a duck and quacks like a duck, it must be a duck.&#8221;</p>
<p>Duck typing doesn&#8217;t require a lot of formality, but it&#8217;s still a type strategy. You&#8217;ll find duck typing in languages like Python, Ruby, and Perl. </p>
<p>Btw, not to be outdone, C# 4.0 offers &#8220;<a href="http://msdn.microsoft.com/en-us/library/dd264736%28VS.100%29.aspx">dynamic types</a>&#8221; &#8211; essentially some syntax and internal support to allow duck typing in C# code. It ain&#8217;t pretty, but it is equivalent. (Accordingly, look for it in Java in 5 years and C++ in about 14. /snark)</p>
<p>Hey! Here&#8217;s some code to ponder:</p>
<pre class="syntax-highlight:ruby">
# More hand-waving classes. You get the idea.
class Person
	def show

class Robot
	def show

class Customer &lt; Person
class Vendor &lt; Robot

def display(whatever)
	#do something with a Customer or Vendor. Or Robot or Person. Or whatever has a show method.
	whatever.show
end
</pre>
<p>This works because both classes, though unrelated, have the same method which is expected (show). So duck typing is still interface typing, but without any guarantee. &#8220;Jump and the net will appear&#8221; it one way to look at it. (Most of the time it does!)</p>
<h4>Pattern Matching and Awesomesauce</h4>
<p>Here&#8217;s where I&#8217;m going to take a detour from the norm and talk about pattern matching. Pattern matching is a nifty feature in a number of different languages which lets you capture data and use it polymophically. Most often this is used to isolate a specific piece of data or to differentiate partial functions. It is in that last sense that I&#8217;m most interested in pattern matching as a typing scheme. Here&#8217;s an example in Erlang:</p>
<pre class="syntax-highlight:c">
display({customer, FirstName, LastName}) -&gt;
	show_customer(FirstName, LastName);
display({vendor, FirstName, LastName}) -&gt;
	show_vendor(FirstName, LastName).
</pre>
<p>Just as in the OO example, here we have two overloaded functions and one of them will be selected based on the first argument. What is different here is that we&#8217;re not switching on types, we&#8217;re switching on values. The &#8220;customer&#8221; atom is a value that is being matched. If I had passed in some other atom, like &#8220;vendor&#8221;, that wouldn&#8217;t have matched &#8220;customer&#8221; in the first function signature, so the computer would look at the next function to see if that matches. Luckily in this case I&#8217;ve defined my second function to match &#8220;vendor&#8221;, so it finds a match. Note that I could also have used an underscore (wildcard) in place of &#8220;vendor&#8221;, and matched on anything that had made it that far. Effectively that would have meant &#8220;not a customer&#8221;.</p>
<p>Like with duck typing, we&#8217;re not dealing with an explicit type, but we still have typing behavior. It&#8217;s a different kind of type.</p>
<p>This has turned into a two-parter. I&#8217;ll recap: I&#8217;ve reviewed some common type schemes and bent the concept of &#8220;type&#8221; a little bit. In <a href="http://www.youell.com/matt/writing/?p=627">the next installment</a> I&#8217;m going to bend the idea of &#8220;type&#8221; <em>just a little more</em>. Be sure to come back and see if I break anything.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.youell.com/matt/writing/?feed=rss2&amp;p=601</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Road to Wheeler</title>
		<link>http://www.youell.com/matt/writing/?p=583</link>
		<comments>http://www.youell.com/matt/writing/?p=583#comments</comments>
		<pubDate>Tue, 27 Oct 2009 17:43:35 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Road To Wheeler]]></category>

		<guid isPermaLink="false">http://www.youell.com/matt/writing/?p=583</guid>
		<description><![CDATA[Over the summer I sketched out a new programming language which I&#8217;ve tentatively named Wheeler. I&#8217;m still working on the implementation, though I have a crude prototype which I presented last month to the Westside Programmer&#8217;s group in Beaverton. The limited feedback I&#8217;ve received so far (aside from &#8220;WTF?&#8221;) has included comparisons with Prolog and [...]]]></description>
			<content:encoded><![CDATA[<p>Over the summer I sketched out a new programming language which I&#8217;ve tentatively named Wheeler. I&#8217;m still working on the implementation, though I have a crude prototype which I presented last month to the Westside Programmer&#8217;s group in Beaverton. The limited feedback I&#8217;ve received so far (aside from &#8220;WTF?&#8221;) has included comparisons with Prolog and Haskell. I&#8217;d like to talk more about this new language here, but before I do I want to pave the way with some short posts highlighting some of the thinking and motivation behind the language. This is the first post in that series.</p>
<p>From Vonnegut&#8217;s &#8220;Slaughterhouse Five&#8221;:</p>
<blockquote>
<p>Billy couldn&#8217;t read Tralfamadorian, of course, but he could at least see how the books were laid out &#8211; in brief clumps of symbols separated by stars. Billy commented that the clumps might be telegrams.</p>
<p>&#8220;Exactly,&#8221; said the voice.</p>
<p>&#8220;They <em><strong>are</strong></em> telegrams?&#8221;</p>
<p>&#8220;There are no telegrams on Tralfamadore. But you&#8217;re right: each clump of symbols is a brief, urgent message &#8211; describing a situation, a scene. We Tralfamadorians read them all at once, not one after the other. There isn&#8217;t any particular relationship between all the messages, except that the author has chosen them carefully, so that, when seen all at  once, they produce an image of life that is beautiful and surprising and deep. There is no beginning, no middle, no end, no suspense, no moral, no causes, no effects. What we love in our books are the depths of the many marvelous moments seen all at one time.&#8221;</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.youell.com/matt/writing/?feed=rss2&amp;p=583</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PDX Virtlib</title>
		<link>http://www.youell.com/matt/writing/?p=578</link>
		<comments>http://www.youell.com/matt/writing/?p=578#comments</comments>
		<pubDate>Sat, 10 Oct 2009 01:37:38 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[books]]></category>
		<category><![CDATA[portland]]></category>

		<guid isPermaLink="false">http://www.youell.com/matt/writing/?p=578</guid>
		<description><![CDATA[This summer I created the Portland Virtual Technical Lending Library. I just call it the Virtlib or the Virtual Library.
http://virtlib.builtsoftware.com
Have you ever noticed how your local library doesn&#8217;t stock a great selection of technical books? They would if they could, but they can&#8217;t. It would just be too expensive. Technical books are a niche, and [...]]]></description>
			<content:encoded><![CDATA[<p>This summer I created the Portland Virtual Technical Lending Library. I just call it the Virtlib or the Virtual Library.</p>
<p><a href="http://virtlib.builtsoftware.com">http://virtlib.builtsoftware.com</a></p>
<p>Have you ever noticed how your local library doesn&#8217;t stock a great selection of technical books? They would if they could, but they can&#8217;t. It would just be too expensive. Technical books are a niche, and worse, they are a constantly changing niche. Libraries can&#8217;t get a good return on investment from a book like &#8220;<a href="http://virtlib.builtsoftware.com/book/isbn/0977616630/">Agile Web Development with Rails</a>&#8220;. It&#8217;ll be useless in 3 or 4 years when the technology changes. A copy of &#8220;Jane Eyre&#8221; could still be providing constant value 20 years from now. And far more people will read Jane Eyre than will ever hear of Ruby. The mainstream rules.</p>
<p>Because of this geek-gap at the library, technical folks are forced to go off to the book store or places like Amazon or <a href="http://www.alibris.com/">Alibris</a> to get our books. And it ain&#8217;t cheap! Then, after we buy our book, we read it and set it aside. If it was good, we hang on to it for reference later. We end up with shelves full of books that other people could be using. </p>
<p><em>Why not let them?</em></p>
<p>That&#8217;s what the Virtual Library is all about: Sharing with your local tech community. And it&#8217;s pretty easy. You sign up for an account, and then start adding the books you want to share. You type in Title, Author, and ISBN and that&#8217;s about it. Then others can request your books. And you can request their books too! You decide along with the other person how you&#8217;re going to meet up to get the book. Local user group meetings are a great time for this, but you can meet when and wherever you&#8217;re both willing.</p>
<p>The Virtual Library is still in the early stages of development, and it is only available in the greater Portland Metro area, but if people find it useful I&#8217;ll be expanding it to other tech-minded areas. If you live somewhere outside of Portland and you&#8217;d like to have a Virtual Library, contact me.</p>
<p>If you&#8217;re in the Portland area and you&#8217;ve got any kind of technical books (not just programming&#8230; even medical, legal, musical, architectural, etc.) that you would like to share, go sign up for an account and add them in. You&#8217;ll be doing yourself and your local geek community a great favor.</p>
<p><a href="http://virtlib.builtsoftware.com/about/start/">Go sign up!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.youell.com/matt/writing/?feed=rss2&amp;p=578</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The One Where I Rant About Data</title>
		<link>http://www.youell.com/matt/writing/?p=556</link>
		<comments>http://www.youell.com/matt/writing/?p=556#comments</comments>
		<pubDate>Sun, 27 Sep 2009 19:58:13 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[rants]]></category>

		<guid isPermaLink="false">http://www.youell.com/matt/writing/?p=556</guid>
		<description><![CDATA[I&#8217;ll come right out and say this: Data is imaginary. It doesn&#8217;t exist. So let&#8217;s not pretend that it does.
Well, I guess we have to pretend that it does to some extent. But we certainly don&#8217;t have to pretend that it exists in some absolute, immutable way.
Take files, for example. What are files, really? If [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll come right out and say this: Data is imaginary. It doesn&#8217;t exist. So let&#8217;s not pretend that it does.</p>
<p>Well, I guess we have to pretend that it does to some extent. But we certainly don&#8217;t have to pretend that it exists in some absolute, immutable way.</p>
<p>Take files, for example. What are files, really? If you think about this long and hard enough you realize no, files aren&#8217;t just chains of bytes. Files are flattened data structures. And more than that, they are flattened out <em>ideas</em>. But let&#8217;s stick with the data structure thing. Every document, every file, everything ever has some kind of structure.</p>
<p>Files haven&#8217;t always existed in computers. There was a time with computers and <strong>gasp</strong>, no files. The file metaphor appeared fairly early in computing. So why do we stick with that same metaphor now? </p>
<p>Files are crap. They&#8217;ve forced us to flatten out our data. That business plan that you&#8217;re writing in 15 parts, with three sub parts each? It really wants to be a tree with 15 nodes, each with 3 nodes. Or something. It most certainly does NOT want to be flattened down into a file, where every part of the file is on the same footing with every other part of the file. That just doesn&#8217;t make sense. </p>
<p>So here we are, as programmers, and we have all of this data and structure floating around in our programs, and we have to store things in a file. Blech! How are you going to store a graph (object graph, data tree, what have you) in a flat file and have that make any damned sense at all?</p>
<p>You&#8217;re not. No, do NOT say XML! That is not the answer either. Don&#8217;t get me wrong&#8230; XML heads in the right direction, but it&#8217;s still flattening things out terribly. And it&#8217;s also kind of stupid. To be fair that&#8217;s mostly an implementation detail.</p>
<p>I know, I know, you want me to explain why XML is stupid, because otherwise I&#8217;m just making spurious accusations, and programmers hate that shit. Or at least pretend to, so they can poke at other programmers when they disagree with them. Whatever. I hold these truths to be self-evident, that files are fucking bullshit and that cramming data into flat files is a god damned waste of time. And yes, I mean &#8220;god damned&#8221;. Even if you don&#8217;t believe in a God or a god or an FSM or what have you, it&#8217;s clear that we only have so much time on this spinning ball of mud and how much of it will we spend bruising, battering, and smearing out our data to fit into some ridiculous flat file system?</p>
<p>Thank god for relational databases, right?</p>
<p>Fuck you. Have you listened to a god damned word I&#8217;ve been saying? I&#8217;m talking about taking our data, packing it up into ridiculous shapes and sizes, spackling on meta data to make it all make sense, and then shoving it off to some other place to live. Does that in any way make you think that relational databases are getting off the hook here? Fuck-to-the-N-O. What&#8217;s that? I have to mash my data up into chunks that fit into little square tables? And then if I want my data to connect to other data I have to create more little meta tables to show how everything connects? And it&#8217;s all ok, because there&#8217;s MATH behind it all, right? God damned MATH will save the fucking day.</p>
<p>No.</p>
<p>Maybe you&#8217;re catching on now. Now you&#8217;re thinking about those nifty key/value databases that have come back around lately, aren&#8217;t you? And the document stores? The hierarchical databases? Surely something here will save the day, right? Rubbish. But maybe. I don&#8217;t know.</p>
<p>Here&#8217;s what I know: I have data, and I want to look at my data my way. You have data, and some of it is probably some of the same data that I have. And that&#8217;s cool&#8230; I remember kindergarten. I like to share. But why in the hell do I have to share with you on YOUR terms? Don&#8217;t get me wrong, I don&#8217;t see why you should have to share with me on my terms either. Things should be flexible and bendy and still make sense. Is that too much to ask? </p>
<p>Probably, yes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.youell.com/matt/writing/?feed=rss2&amp;p=556</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Cat In the Hat</title>
		<link>http://www.youell.com/matt/writing/?p=563</link>
		<comments>http://www.youell.com/matt/writing/?p=563#comments</comments>
		<pubDate>Sat, 26 Sep 2009 19:33:10 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[How I Code]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming languages]]></category>

		<guid isPermaLink="false">http://www.youell.com/matt/writing/?p=563</guid>
		<description><![CDATA[I continue to be impressed by the flexibility of list comprehensions, especially in Python. The other day I discovered that I could handle a small but twisty problem quite simply, which I will now share in the style of Dr. Seuss:


[hat[cat] if cat in hat else cat for cat in cats] 

]]></description>
			<content:encoded><![CDATA[<p>I continue to be impressed by the flexibility of list comprehensions, especially in Python. The other day I discovered that I could handle a small but twisty problem quite simply, which I will now share in the style of Dr. Seuss:</p>
<pre class="syntax-highlight:python">

[hat[cat] if cat in hat else cat for cat in cats] 
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.youell.com/matt/writing/?feed=rss2&amp;p=563</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
