<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Critical Development</title>
	<atom:link href="http://dvanderboom.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://dvanderboom.wordpress.com</link>
	<description>Language design, framework development, UI design, robotics and more.</description>
	<lastBuildDate>Thu, 05 Jan 2012 07:56:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='dvanderboom.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Critical Development</title>
		<link>http://dvanderboom.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://dvanderboom.wordpress.com/osd.xml" title="Critical Development" />
	<atom:link rel='hub' href='http://dvanderboom.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Dynamic Clipping of Rounded Corners in Silverlight</title>
		<link>http://dvanderboom.wordpress.com/2010/11/06/dynamic-clipping-of-rounded-corners-in-silverlight/</link>
		<comments>http://dvanderboom.wordpress.com/2010/11/06/dynamic-clipping-of-rounded-corners-in-silverlight/#comments</comments>
		<pubDate>Sat, 06 Nov 2010 15:01:45 +0000</pubDate>
		<dc:creator>Dan Vanderboom</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[User Interface Design]]></category>
		<category><![CDATA[Attached Dependency Properties]]></category>
		<category><![CDATA[Clipping Path]]></category>
		<category><![CDATA[Rounded Corners]]></category>

		<guid isPermaLink="false">https://dvanderboom.wordpress.com/2010/11/06/dynamic-clipping-of-rounded-corners-in-silverlight/</guid>
		<description><![CDATA[I recently came across a nice article by Colin Eberhardt on automatically adjusting clipping bounds whenever the element to be clipped was resized, and I decided to make some small additions to make it work with rounded corners for a project I’m working on. Since Colin was generous enough to share his code, I’m going [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dvanderboom.wordpress.com&amp;blog=2293322&amp;post=1445&amp;subd=dvanderboom&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I recently came across <a href="http://www.codeproject.com/Articles/36495/Silverlight-ClipToBounds-Can-I-Clip-It-Yes-You-Can.aspx">a nice article</a> by Colin Eberhardt on automatically adjusting clipping bounds whenever the element to be clipped was resized, and I decided to make some small additions to make it work with rounded corners for a project I’m working on. Since Colin was generous enough to share his code, I’m going to share my additions as well.</p>
<p>Colin’s solution involves the creation of an attached property called Clip.ToBounds (a bool) applied to the item whose bounds you want to serve as a clipping path.&#160; When this property is attached, it adds a listener to the Resize event and updates the clipping path when this happens.&#160; Simple but effective.</p>
<p>I’ve added two more attached properties: Clip.RadiusX and Clip.RadiusY.</p>
<p>Here’s what the end result looks like:</p>
<p><a href="http://dvanderboom.files.wordpress.com/2010/11/image.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;margin:5px;" title="image" border="0" alt="image" src="http://dvanderboom.files.wordpress.com/2010/11/image_thumb.png?w=640&#038;h=455" width="640" height="455" /></a></p>
<p>The whole bordered area is a UserControl I created called ContentView.&#160; Its root is a Border, which contains a Grid that is broken into three rows.&#160; The top row contains a ContentHeader control, and the bottom row contains a ContentFooter control.&#160; This is defined in the following code:</p>
<pre class="code"><span style="color:blue;"><font size="2">&lt;</font></span><font size="2"><span style="color:olive;">UserControl
    </span><span style="color:navy;">x</span><span style="color:blue;">:</span>Class<span style="color:blue;">=&quot;</span>ClipRoundedCorners<span style="color:blue;">.</span><span style="color:olive;">ContentView</span></font><font size="2"><span style="color:blue;">&quot;
    </span><span style="color:red;">xmlns</span></font><font size="2"><span style="color:blue;">=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
    </span><span style="color:red;">xmlns</span><span style="color:blue;">:</span><span style="color:navy;">x</span></font><font size="2"><span style="color:blue;">=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
    </span><span style="color:red;">xmlns</span><span style="color:blue;">:</span><span style="color:navy;">d</span></font><font size="2"><span style="color:blue;">=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
    </span><span style="color:red;">xmlns</span><span style="color:blue;">:</span><span style="color:navy;">mc</span></font><font size="2"><span style="color:blue;">=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
    </span><span style="color:red;">xmlns</span><span style="color:blue;">:</span><span style="color:navy;">local</span><span style="color:blue;">=&quot;clr-namespace:</span>ClipRoundedCorners</font><font size="2"><span style="color:blue;">&quot;
    </span><span style="color:navy;">mc</span><span style="color:blue;">:</span><span style="color:red;">Ignorable</span><span style="color:blue;">=&quot;</span><span style="color:navy;">d</span></font><font size="2"><span style="color:blue;">&quot;
    </span><span style="color:navy;">d</span><span style="color:blue;">:</span><span style="color:red;">DesignWidth</span><span style="color:blue;">=&quot;640&quot; </span><span style="color:navy;">d</span><span style="color:blue;">:</span><span style="color:red;">DesignHeight</span></font><font size="2"><span style="color:blue;">=&quot;480&quot;&gt;

    &lt;</span><span style="color:olive;">Border </span><span style="color:navy;">x</span><span style="color:blue;">:</span>Name<span style="color:blue;">=&quot;</span><span style="color:navy;">LayoutRoot</span><span style="color:blue;">&quot; </span><span style="color:navy;">BorderThickness</span><span style="color:blue;">=&quot;2&quot; </span><span style="color:navy;">BorderBrush</span><span style="color:blue;">=&quot;White&quot; </span><span style="color:navy;">CornerRadius</span></font><font size="2"><span style="color:blue;">=&quot;10&quot;&gt;
        &lt;</span><span style="color:olive;">Grid </span><span style="color:navy;">local</span><span style="color:blue;">:</span><span style="color:olive;">Clip</span><span style="color:red;">.</span><span style="color:maroon;">ToBounds</span><span style="color:blue;">=&quot;true&quot; </span><font><span style="color:navy;">local</span><span style="color:blue;">:</span><span style="color:olive;">Clip</span><span style="color:red;">.</span><span style="color:maroon;">RadiusX</span><span style="color:blue;">=&quot;10&quot; </span><span style="color:navy;">local</span><span style="color:blue;">:</span><span style="color:olive;">Clip</span><span style="color:red;">.</span><span style="color:maroon;">RadiusY</span></font></font><font size="2"><span style="color:blue;"><font>=&quot;10&quot;&gt;</font>
            &lt;</span><span style="color:olive;">Grid</span><span style="color:#a31515;">.</span><span style="color:navy;">RowDefinitions</span></font><font size="2"><span style="color:blue;">&gt;
                &lt;</span><span style="color:olive;">RowDefinition </span><span style="color:navy;">Height</span></font><font size="2"><span style="color:blue;">=&quot;84&quot;/&gt;
                &lt;</span><span style="color:olive;">RowDefinition</span></font><font size="2"><span style="color:blue;">/&gt;
                &lt;</span><span style="color:olive;">RowDefinition </span><span style="color:navy;">Height</span></font><font size="2"><span style="color:blue;">=&quot;88&quot;/&gt;
            &lt;/</span><span style="color:olive;">Grid</span><span style="color:#a31515;">.</span><span style="color:navy;">RowDefinitions</span></font><font size="2"><span style="color:blue;">&gt;
            &lt;</span><span style="color:navy;">local</span><span style="color:blue;">:</span><span style="color:olive;">ContentHeader </span><span style="color:navy;">Margin</span></font><font size="2"><span style="color:blue;">=&quot;0&quot;/&gt;
            &lt;</span><span style="color:navy;">local</span><span style="color:blue;">:</span><span style="color:olive;">ContentFooter </span><span style="color:navy;">Margin</span><span style="color:blue;">=&quot;0&quot; </span><span style="color:navy;">d</span><span style="color:blue;">:</span><span style="color:red;">LayoutOverrides</span><span style="color:blue;">=&quot;Width&quot; </span><span style="color:olive;">Grid</span><span style="color:red;">.</span><span style="color:maroon;">Row</span></font><font size="2"><span style="color:blue;">=&quot;2&quot;/&gt;
            &lt;</span><span style="color:olive;">ScrollViewer </span><span style="color:navy;">Margin</span><span style="color:blue;">=&quot;0&quot; </span><span style="color:olive;">Grid</span><span style="color:red;">.</span><span style="color:maroon;">Row</span><span style="color:blue;">=&quot;1&quot; </span><span style="color:navy;">Background</span></font><font size="2"><span style="color:blue;">=&quot;#FF545454&quot;/&gt;
        &lt;/</span><span style="color:olive;">Grid</span></font><font size="2"><span style="color:blue;">&gt;
    &lt;/</span><span style="color:olive;">Border</span></font><font size="2"><span style="color:blue;">&gt;
&lt;/</span><span style="color:olive;">UserControl</span></font><span style="color:blue;"><font size="2">&gt;
</font></span></pre>
<p>
  <br />The attached Clip properties are defined on the Grid control. Even though the Border defines its own CornerRadius, it’s the Grid within it that needs to set the clipping path.</p>
<p>Within the Clip class, I’ve updated the ClipToBounds method to set the RadiusX and RadiusY properties of the RectangleGeometry object used to set the clipping path.</p>
<pre class="code"><font size="2"><span style="color:blue;">private static void </span><span style="color:maroon;">ClipToBounds</span>(<span style="color:olive;">FrameworkElement </span>Element)
{
    <span style="color:blue;">if </span>(<span style="color:maroon;">GetToBounds</span>(Element))
    {
        Element.<span style="color:navy;">Clip </span>= <span style="color:blue;">new </span><span style="color:olive;">RectangleGeometry</span>()
        {
            <span style="color:navy;">Rect </span>= <span style="color:blue;">new </span><span style="color:#00008b;">Rect</span>(0, 0, Element.<span style="color:navy;">ActualWidth</span>, Element.<span style="color:navy;">ActualHeight</span>)
        };

        <span style="color:blue;">var </span>rect = Element.<span style="color:navy;">Clip </span><span style="color:blue;">as </span><span style="color:olive;">RectangleGeometry</span>;
        rect.<span style="color:navy;">RadiusX </span>= <span style="color:maroon;">GetRadiusX</span>(Element);
        rect.<span style="color:navy;">RadiusY </span>= <span style="color:maroon;">GetRadiusY</span>(Element);
    }
    </font><font size="2"><span style="color:blue;">else
    </span>{
        Element.<span style="color:navy;">Clip </span>= <span style="color:blue;">null</span>;
    }
}</font></pre>
<p>The complete Visual Studio 2010 (Silverlight 4) demo project can be <a href="http://danvanderboom.com/Examples/ClipRoundedCorners.zip">downloaded here</a>.</p>
<p>Resize your browser to see ContentView resize.&#160; The clipping path updates like you’d expect it to.</p>
<p>Happy Silverlight coding!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dvanderboom.wordpress.com/1445/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dvanderboom.wordpress.com/1445/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dvanderboom.wordpress.com/1445/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dvanderboom.wordpress.com/1445/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dvanderboom.wordpress.com/1445/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dvanderboom.wordpress.com/1445/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dvanderboom.wordpress.com/1445/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dvanderboom.wordpress.com/1445/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dvanderboom.wordpress.com/1445/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dvanderboom.wordpress.com/1445/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dvanderboom.wordpress.com/1445/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dvanderboom.wordpress.com/1445/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dvanderboom.wordpress.com/1445/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dvanderboom.wordpress.com/1445/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dvanderboom.wordpress.com&amp;blog=2293322&amp;post=1445&amp;subd=dvanderboom&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dvanderboom.wordpress.com/2010/11/06/dynamic-clipping-of-rounded-corners-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a59dbf3cc9c673540221e35e2c007ec1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Dan</media:title>
		</media:content>

		<media:content url="http://dvanderboom.files.wordpress.com/2010/11/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>The Archetype Language (Part 9)</title>
		<link>http://dvanderboom.wordpress.com/2010/10/03/the-archetype-language-part-9/</link>
		<comments>http://dvanderboom.wordpress.com/2010/10/03/the-archetype-language-part-9/#comments</comments>
		<pubDate>Sun, 03 Oct 2010 20:13:39 +0000</pubDate>
		<dc:creator>Dan Vanderboom</dc:creator>
				<category><![CDATA[Animation]]></category>
		<category><![CDATA[Archetype Language]]></category>
		<category><![CDATA[Composability]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Fluent API]]></category>
		<category><![CDATA[Language Innovation]]></category>

		<guid isPermaLink="false">https://dvanderboom.wordpress.com/2010/10/03/the-archetype-language-part-9/</guid>
		<description><![CDATA[Overview This is part of a continuing series of articles about a new .NET language under development called Archetype.&#160; Archetype is a C-style (curly brace) functional, object-oriented (class-based), metaprogramming-capable language with features and syntax borrowed from many languages, as well as some new constructs.&#160; A major design goal is to succinctly and elegantly implement common [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dvanderboom.wordpress.com&amp;blog=2293322&amp;post=1387&amp;subd=dvanderboom&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong><font color="#800000">Overview</font></strong></p>
<p><font color="#800000">This is part of a continuing series of articles about a new .NET language under development called <strong>Archetype</strong>.&#160; Archetype is a C-style (curly brace) functional, object-oriented (class-based), metaprogramming-capable language with features and syntax borrowed from many languages, as well as some new constructs.&#160; A major design goal is to succinctly and elegantly implement common patterns that normally require a lot of boilerplate code which can be difficult, error-prone, or just plain onerous to write.</font></p>
<p><font color="#800000">You can follow the news and progress on the Archetype compiler on twitter<font color="#800000"> </font><a href="http://twitter.com/archetypelang"><font color="#800000">@archetypelang</font></a>.</font></p>
<p><font color="#800000">Links to the individual articles:</font></p>
<blockquote><p><a href="http://dvanderboom.wordpress.com/2010/04/26/new-language-code-named-archetype/"><font color="#800000">Part 1</font></a><font color="#800000"> – Properties and fields, function syntax, the me keyword</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/04/27/the-archetype-language-part-2/"><font color="#800000">Part 2</font></a><font color="#800000"> – Start function, named and anonymous delegates, delegate duck typing, bindable properties, composite bindings, binding expressions, namespace imports, string concatenation</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/04/27/the-archetype-language-part-3/"><font color="#800000">Part 3</font></a><font color="#800000"> – Exception handling, local variable definition, namespace imports, aliases, iteration (loop, fork-join, while, unless), calling functions and delegates asynchronously, messages</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/05/08/the-archetype-language-part-4/"><font color="#800000">Part 4</font></a><font color="#800000"> – Conditional selection (<strong>if</strong>), pattern matching, regular expression literals, agents, classes and traits</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/05/24/the-archetype-language-part-5/"><font color="#800000">Part 5</font></a><font color="#800000"> – Type extensions, custom control structures</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/06/14/the-archetype-language-part-6/"><font color="#800000">Part 6</font></a><font color="#800000"> – If expressions, enumerations, nullable types, tuples, streams, list comprehensions, subrange types, type constraint expressions</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/09/27/the-archetype-language-part-7/"><font color="#800000">Part 7</font></a><font color="#800000"><font color="#c0504d"><font color="#c0504d"> –</font> </font><font color="#800000">Semantic</font> density, operator overloading, custom operators</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/10/01/the-archetype-language-part-8/"><font color="#800000">Part 8</font></a><font color="#800000"> – Constructors, declarative Archetype: the initializer body</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/10/03/the-archetype-language-part-9/"><font color="#800000">Part 9</font></a><font color="#800000"> – Params &amp; fluent syntax, safe navigation operator, null coalescing operators</font></p>
</blockquote>
<p><font color="#800000">Conceptual articles about language design and development tools:</font></p>
<blockquote><p><a href="http://dvanderboom.wordpress.com/2010/06/14/language-design-complexity-extensibility-and-intention/"><font color="#800000">Language Design: Complexity, Extensibility, and Intention</font></a></p>
<p><a href="http://dvanderboom.wordpress.com/2010/05/31/reimagining-the-integrated-development-environment/"><font color="#800000">Reimagining the IDE</font></a></p>
<p><a href="http://dvanderboom.wordpress.com/2009/09/07/better-tool-support-for-net/"><font color="#800000">Better Tool Support for .NET</font></a></p>
</blockquote>
<h1>Params &amp; Fluent Syntax</h1>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">C# has a parameter modifier called <strong>params</strong> that allows you to supply additional function arguments to populate a single array parameter.       </p>
<p></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><font face="Consolas"><font size="2"><span style="color:blue;">void </span>Display(<span style="color:blue;">params string</span>[] Names)         <br />{         <br />&#160;&#160;&#160; </font></font><font face="Consolas"><font size="2"><span style="color:green;">// &#8230;          <br /></span>}         </p>
<p></font></font></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><font size="2" face="Consolas"></font></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"><font face="Verdana">Without the <strong>params</strong> modifier, we’d have to call it like this:         </p>
<p></font></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><font size="2" face="Consolas">Display(<span style="color:blue;">new string</span>[] { <span style="color:#a31515;">&quot;Dan&quot;</span>, <span style="color:#a31515;">&quot;Josa&quot;</span>, <span style="color:#a31515;">&quot;Sarah&quot; </span>});       </p>
<p></font></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><font size="2" face="Consolas"></font></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">Because <strong>params</strong> is declared, we can do this instead:       </p>
<p></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><font size="2" face="Consolas">Display(<span style="color:#a31515;">&quot;Dan&quot;</span>, <span style="color:#a31515;">&quot;Josa&quot;</span>, <span style="color:#a31515;">&quot;Sarah&quot;</span>);       </p>
<p></font></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><font size="2" face="Consolas"></font></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">If there’s one thing you can take away from Archetype’s design, it’s that syntactic sugar is everything.&#160; After examining my own procedural animation library (<a href="http://dvanderboom.wordpress.com/2009/12/31/animate-net-fluent-animation-library-for-silverlight-wpf/">Animate.NET</a>) to see how it could be used best in Archetype, I came to the conclusion that these <strong>params </strong>parameters can be substantial.&#160; When they are, they create syntactic unpleasantries, especially when nested structures are involved.       </p>
<p></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">Consider the following C# example.      </p>
<p></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">var</span><span style="font-family:consolas;font-size:10pt;"> anim = </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#2b91af;font-size:10pt;">Animate</span><span style="font-family:consolas;font-size:10pt;">.Wait(0.2.seconds(),</span></p>
<p style="margin:0 0 0 81pt;"><span style="font-family:consolas;font-size:10pt;">RedChip.MoveBy(0.4.seconds(), -40, 0), </span></p>
<p style="margin:0 0 0 81pt;"><span style="font-family:consolas;font-size:10pt;">RedChip.FadeIn(0.2.seconds()), </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="margin:0 0 0 81pt;"><span style="font-family:consolas;font-size:10pt;">BlackChip.MoveBy(0.4.seconds(), 0, 40), </span></p>
<p style="margin:0 0 0 81pt;"><span style="font-family:consolas;font-size:10pt;">BlackChip.FadeOut(0.4.seconds()) </span></p>
<p style="margin:0 0 0 .75in;"><span style="font-family:consolas;font-size:10pt;">) </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;">.WhenComplete(a =&gt; </span></p>
<p style="margin:0 0 0 .75in;"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="margin:0 0 0 81pt;"><span style="font-family:consolas;font-size:10pt;">MainStage.Children.Remove(RedChip); </span></p>
<p style="margin:0 0 0 81pt;"><span style="font-family:consolas;font-size:10pt;">MainStage.Children.Remove(BlackChip); </span></p>
<p style="margin:0 0 0 .75in;"><span style="font-family:consolas;font-size:10pt;">}) </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;">.Begin(); </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">     <br />First, a quick explanation of the code.&#160; Animate is a static class, and the Wait function returns an object called GroupAnimation that inherits from Animation.&#160; After a 0.2 second wait, the following <strong>params</strong> list of Animation objects will execute.&#160; RedChip and BlackChip are FrameworkElements (Silverlight/WPF objects), and animation commands such as MoveBy and FadeOut are extension methods on FrameworkElement.&#160; Each of these animation commands returns an Animation-derived object.&#160; The <strong>seconds()</strong> extension method on int and float types convert to TimeSpan objects.</span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">     <br />The ultimate goal of this first Wait section of code is to define a set of animations—nested sets are possible, which form a tree of animations.&#160; These trees can get more complicated than this, but we’ll keep the example simple for now.</span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">     <br />Now for the criticism.&#160; Look at the matching parentheses of the Wait function.&#160; The normal TimeSpan parameter is listed as an equal along with the Animation parameter list, and what is being used as a complex, nested structure is holding up the closing parenthesis and dragging it down to the end of the entire list.&#160; If only there were a cleaner way of treating this nested structure like constructor initializers (see <a href="http://dvanderboom.wordpress.com/2010/10/01/the-archetype-language-part-8/">Part 8</a>).&#160; These correspond, in terms of visual layout, to the attributes and the child elements of an XML node.</span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">     <br />What else is wrong with this picture?&#160; The .WhenComplete and .Begin functions are being invoked on the result of the previous expression.&#160; It’s characteristic of fluent-style APIs to define functions (or extension methods) that operate on the result of the previous operation so they can be strung together into sentence-like patterns.&#160; The dot before both WhenComplete and Begin look odd when appearing on lines by themselves, and the lambda expression would be better promoted to a proper code block.</span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">     <br />Finally, it’s unfortunate that in declaring a new local variable, we have to indent the whole animation block this way.&#160; </span><span style="font-size:10pt;">Here’s what the same code looks like in Archetype:</span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="margin:0;"><span style="font-family:consolas;color:#72830f;font-size:10pt;"></span></p>
<p style="margin:0;"><span style="font-family:consolas;color:#72830f;font-size:10pt;">     <br />Animate</span><span style="font-family:consolas;font-size:10pt;">.<span style="color:#1f497d;">Wait</span> (0.2 seconds) -&gt; anim </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">RedChip</span><span style="font-family:consolas;font-size:10pt;">.<span style="color:#1f497d;">MoveBy</span>(0.4 seconds, -40, 0), </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">RedChip</span><span style="font-family:consolas;font-size:10pt;">.<span style="color:#1f497d;">FadeIn</span>(0.2 seconds), </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">BlackChip</span><span style="font-family:consolas;font-size:10pt;">.<span style="color:#1f497d;">MoveBy</span>(0.4 seconds, 0, 40), </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">BlackChip</span><span style="font-family:consolas;font-size:10pt;">.<span style="color:#1f497d;">FadeOut</span>(0.4 seconds) </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">} </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">WhenComplete</span><span style="font-family:consolas;font-size:10pt;"> (a) </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">MainStage</span><span style="font-family:consolas;font-size:10pt;">.<span style="color:#1f497d;">Children</span>.<span style="color:#1f497d;">Remove</span>(RedChip),</span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">MainStage</span><span style="font-family:consolas;font-size:10pt;">.<span style="color:#1f497d;">Children</span>.<span style="color:#1f497d;">Remove</span>(BlackChip)</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">} </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">Begin</span><span style="font-family:consolas;font-size:10pt;">(); </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">     <br />This is more like it.&#160; Notice the declarative assignment (declaration + assignment) with <strong>–&gt; anim</strong> on the first line, and the way the parentheses can be closed after the TimeSpan object (see <a href="http://dvanderboom.wordpress.com/2010/09/27/the-archetype-language-part-7/">Part 7 on custom operators</a> for an explanation of the syntax “<strong>0.2 seconds</strong>”).&#160; There’s no more need to indent the whole structure to make it line up nicely in an assignment.&#160; The following initializer code block (in curly braces) supplies Animation object values to the <strong>params</strong> parameter in the Wait function, and the WhenComplete and Begin functions don’t require a leading dot to operate on the previous expression (Intellisense would reflect these options).</span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"><font size="2"></font></span></p>
<p> <span style="font-size:10pt;">
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal">The Archetype code is much cleaner.&#160; It’s easier to see where groups of constructs begin and end, enabling fluent-style APIs with arbitrarily-complicated nested structures to be easily constructed.&#160; Let’s take a look at one more example with a more deeply nested structure:</p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal">&#160;</p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;color:#72830f;font-size:10pt;">Animate</span><span style="font-family:consolas;font-size:10pt;">.<span style="color:#1f497d;">Group</span> –&gt; anim         <br /></span></p>
<p>   <span style="font-family:consolas;font-size:10pt;">{</span></span>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">RedChip</span><span style="font-family:consolas;font-size:10pt;">.<span style="color:#1f497d;">MoveBy</span>(0.4 seconds, -40, 0), </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">RedChip</span><span style="font-family:consolas;font-size:10pt;">.<span style="color:#1f497d;">FadeIn</span>(0.2 seconds), </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">BlackChip</span><span style="font-family:consolas;font-size:10pt;">.<span style="color:#1f497d;">MoveBy</span>(0.4 seconds, 0, 40), </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">BlackChip</span><span style="font-family:consolas;font-size:10pt;">.<span style="color:#1f497d;">FadeOut</span>(0.4 seconds), </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#72830f;font-size:10pt;">Animate</span><span style="font-family:consolas;font-size:10pt;">.<span style="color:#1f497d;">Wait</span> (0.4 seconds) </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="margin:0 0 0 .75in;"><span style="font-family:consolas;color:#72830f;font-size:10pt;">Animate</span><span style="font-family:consolas;font-size:10pt;">.<span style="color:#1f497d;">CrossFade</span>(1.5 seconds, <span style="color:#1f497d;">RedChip</span>, <span style="color:#1f497d;">BlackChip</span>),</span></p>
<p style="margin:0 0 0 .75in;"><span style="font-family:consolas;font-size:10pt;"><span style="color:#1f497d;">BlackChip</span>.<span style="color:#1f497d;">MoveTo</span>(0.2 seconds, 20, 150)</span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;">} </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">}</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span><span style="font-size:10pt;">     <br />Here, a GroupAnimation is defined that contains, as one of its child Animations, another GroupAnimation (created with the Wait function).&#160; The animation isn’t started in this case, so anim.Begin() can be called later, or anim could be composed into a larger animation somewhere.&#160; A peek at the function headers for Group and Wait functions should make the ease and power of this design clear.       </p>
<p></span></p>
<p style="margin:0;"><span style="font-size:10pt;"></span></p>
<p style="margin:0;"><span style="font-size:10pt;"></span></p>
<p style="margin:0;"><span style="font-size:10pt;"></span><span style="font-family:consolas;color:blue;font-size:10pt;">static</span><span style="font-family:consolas;font-size:10pt;"> </span><b><span style="font-family:consolas;color:#72830f;font-size:10pt;">Animate</span></b><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">object</span> </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:green;font-size:10pt;">// a stream is the only parameter </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;"><b><span style="color:#1f497d;">Group</span></b> <span style="color:#72830f;">GroupAnimation</span> (Animations <span style="color:#72830f;">Animation*</span> <span style="color:blue;">params</span>) </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;">} </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:green;font-size:10pt;">// a stream is the last parameter, so [ list ] syntax can still be used</span><span style="font-family:consolas;font-size:10pt;"> </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;"><b><span style="color:#1f497d;">Wait</span></b> <span style="color:#72830f;">GroupAnimation</span> (WaitTime <span style="color:#72830f;">TimeSpan</span>, Animations <span style="color:#72830f;">Animation*</span> <span style="color:blue;">params</span>) </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;">} </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">} </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p> <span style="font-size:10pt;">
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal">Because the class is static, individual members are assumed to be static as well. </p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal">&#160;</p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal">T<span style="font-size:10pt;">he easiest way to support this would be to allow this initializer block to be used with a params parameter that’s declared last.</span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<h1>Null Coalescing Operators</h1>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">The null coalescing operator in C# allows you to compare a value to null, and to supply a default value to use in its place.&#160; This is handy in scenarios like this:      </p>
<p></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;"></span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">var</span><span style="font-family:consolas;font-size:10pt;"> location = (cust.Address.City ?? <span style="color:#c00000;">&quot;Unknown&quot;)</span> + &quot;, &quot; + (cust.Address.State ?? <span style="color:#c00000;">&quot;Unknown&quot;)</span>;</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">&#160;</span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">Chris Eargle makes a good point <a href="http://www.kodefuguru.com/post/2010/01/07/Null-Coalescing-Assignment-Operator-for-CSharp-5.aspx">in his article</a> suggesting a “null coalescing assignment operator” when making assignments such as:       </p>
<p></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">cust.Address.City = cust.Address.City ?? <span style="color:#c00000;">&quot;Unknown&quot;</span>;</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">&#160;</span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">There should be a way to eliminate this redundancy.&#160; By combining null coalescing with assignment, we can do this:      </p>
<p></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">cust.Address.City ??= <span style="color:#c00000;">&quot;Unknown&quot;</span>;</span></p>
<p> <span style="font-family:consolas;font-size:10pt;"></span><span style="font-size:10pt;"><span style="font-size:10pt;">
<p style="margin:0;">Groovy’s <a href="http://groovy.codehaus.org/Operators#Operators-ElvisOperator%28%3F%3A%29">Elvis Operator</a> serves a similar role, but operates on a value of false in addition to null.        </p>
<p style="margin:0;">
<p>   </span></span><br />
<h1>Safe Navigation Operator</h1>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">There are many situations where we find ourselves needing to check the value of a deeply nested member, but if we access it directly without first checking whether each part of the path is null, we get a NullReferenceException.      </p>
<p></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;"></span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">var</span><span style="font-family:consolas;font-size:10pt;"> city = cust.Address.City;</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">&#160;</span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">If either cust or Address are null, an exception will be thrown.&#160; To get around this problem, we have to do something like this in C#:      </p>
<p></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;"></span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">string</span><span style="font-family:consolas;font-size:10pt;"> city = null; </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">if</span><span style="font-family:consolas;font-size:10pt;"> (cust != <span style="color:blue;">null</span> &amp;&amp; cust.Address != <span style="color:blue;">null</span>) </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;">city = cust.Address.City;</span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;">&#160;</span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">The &amp;&amp; operator is short-circuiting, which means that if the first boolean expression evaluates to false, the rest of the expression—which would produce a NullReferenceException—never gets executed.&#160; As tedious as this is, without short circuiting operators, our error-prevention code would be even longer.      </p>
<p></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">Jeff Handley wrote a clever safe navigation operator of sorts for C#, using an extension method called _ that takes a delegate (supplied as a lambda).&#160; You can find that <a href="http://www.forkcan.com/viewcode/277/Null-Dot-Operator-Extension-Method">code here</a>.&#160; </span><span style="font-size:10pt;">In his code, he does return a null value when the path short circuits.&#160; As you can see, however, the limitations of C# cause this simple example to get confusing quickly, which you can see if we make City a non-primitive object as well:      </p>
<p></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;"></span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">var</span><span style="font-family:consolas;font-size:10pt;"> city = cust._(c =&gt; c.Address._(a =&gt; a.City.Name));      </p>
<p></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">Groovy implements a <a href="http://groovy.codehaus.org/Operators#Operators-SafeNavigationOperator%28%3F.%29">Safe Navigation Operator</a> in the language itself, which is cleaner:       <br /></span><span style="font-size:10pt;">&#160; <br /></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;"></span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">var</span><span style="font-family:consolas;font-size:10pt;"> city = cust?.Address.City;</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">&#160;</span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">This is equivalent to the more verbose code above.&#160; </span><span style="font-size:10pt;">Archetype takes a similar approach:      </p>
<p></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">var</span><span style="font-family:consolas;font-size:10pt;"> city = cust..Address.City;      </p>
<p></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span><span style="font-size:10pt;">Because of the .. operator in this member access expression, the type of the <strong>city</strong> variable is Option&lt;string&gt; (<a href="http://en.wikipedia.org/wiki/Option_type">more on Option types</a>).&#160; </span><span style="font-size:10pt;">If the path leading up to City is invalid (because Address is null), the value of <strong>city </strong>will be <strong>None</strong>.&#160; This works the same as Nullable&lt;T&gt;, except that <strong>None</strong> means “doesn’t have a value; not even null”.      </p>
<p></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">I like to think of <strong>None</strong> as the “mu constant”.&#160; What is <a href="http://en.wikipedia.org/wiki/Mu_(negative)">mu</a>?&#160; It’s the Japanese word that variously means “not”, “doesn’t exist”, etc., and is illustrated by the well-known Zen Buddhist koan:</span></p>
<blockquote><p>A monk asked <a href="http://en.wikipedia.org/wiki/Zhaozhou_Congshen">Zhaozhou Congshen</a>, a Chinese Zen master (known as <i>Jōshū</i> in Japanese), &quot;Has a dog <a href="http://en.wikipedia.org/wiki/Buddha-nature">Buddha-nature</a> or not?&quot; Zhaozhou answered, <i>&quot;Wú&quot;</i> (in Japanese, <i>Mu</i>)</p>
<p>—<i><a href="http://en.wikipedia.org/wiki/The_Gateless_Gate">The Gateless Gate</a></i>, koan 1, <cite>translation by Robert Aitken</cite></p>
<p><a href="http://en.wikipedia.org/wiki/Yasutani_Haku%27un">Yasutani Haku&#8217;un</a> of the <a href="http://en.wikipedia.org/wiki/Sanbo_Kyodan">Sanbo Kyodan</a> maintained that &quot;the koan is not about whether a dog does or does not have a Buddha-nature because everything is Buddha-nature, and either a positive or negative answer is absurd because there is no particular thing called Buddha-nature.</p>
</blockquote>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">In other words, Mu has often been used to mean “I disagree with the presuppositions of the question.”     <br /></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">There are a few basic patterns around options, nullable objects, and safe navigation that occur frequently, so I’ll outline them here with examples:     </p>
<p></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="margin:0;"><span style="font-family:consolas;color:green;font-size:10pt;">// if Address is null, this evaluates to false </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">if</span><span style="font-family:consolas;font-size:10pt;"> (cust..Address.City == <span style="color:#c00000;">&quot;Milwaukee&quot;</span>) </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;">WorkHarder(); </span></p>
<p style="margin:0;"><span style="font-family:&quot;font-size:11pt;">&#160; </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:green;font-size:10pt;">// if City is None because Address is null, set to &quot;Address Missing&quot;; otherwise, get the city text </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">var</span><span style="font-family:consolas;font-size:10pt;"> city = cust..Address.City ?! <span style="color:#c00000;">&quot;Address Missing&quot;</span>; </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:green;font-size:10pt;">// if City is Some&lt;string&gt; and City == null, set to empty string </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">var</span><span style="font-family:consolas;font-size:10pt;"> city = cust..Address.City ?? <span style="color:#72830f;">string</span>.Empty; </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:green;font-size:10pt;">// if Address is null (City is None), set to &quot;Address Not Found&quot;; </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:green;font-size:10pt;">// but if City == null, set to empty string </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">var</span><span style="font-family:consolas;font-size:10pt;"> city = cust..Address.City ?! <span style="color:#c00000;">&quot;Address Not Found&quot; </span>?? <span style="color:#72830f;">string</span>.Empty; </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:green;font-size:10pt;">// if Address points to an object, leave it alone; otherwise, create a new object </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">cust.Address ??= <span style="color:blue;">new</span> <span style="color:#72830f;">Address</span>(City=<span style="color:#c00000;">&quot;Milwaukee&quot;</span>); </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:green;font-size:10pt;">// an assertion </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">cust..Address ?! <span style="color:blue;">new</span><span style="color:#c00000;"> </span><span style="color:#72830f;">Exception</span>(<span style="color:#c00000;">&quot;Address missing&quot;</span>); </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:green;font-size:10pt;">// set the city if possible, throw a specific exception if not </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">var</span><span style="font-family:consolas;font-size:10pt;"> city = cust..Address.City ?! <span style="color:blue;">new</span><span style="color:#c00000;"> </span><span style="color:#72830f;">Exception</span>(<span style="color:#c00000;">&quot;Address missing&quot;</span>);</span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">&#160;</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<h1>Summary</h1>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">By now it should be obvious that Archetype aims to liberate the developer from the constraints and inefficiencies of ordinary programming languages.&#160; It is designed with modern practices in mind such as fluent-style development and declarative object graph construction.      </p>
<p></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">This article wraps up the material started in <a href="http://dvanderboom.wordpress.com/2010/10/01/the-archetype-language-part-8/">Part 8</a> on declarative programming in Archetype.&#160; In addition, I introduced the safe navigation and null coelescing operators.&#160; These are simple but powerful language elements for cleanly and succinctly specifying common <a href="http://en.wikipedia.org/wiki/Programming_idiom">idioms</a> that come up in daily coding.       </p>
<p></span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dvanderboom.wordpress.com/1387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dvanderboom.wordpress.com/1387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dvanderboom.wordpress.com/1387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dvanderboom.wordpress.com/1387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dvanderboom.wordpress.com/1387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dvanderboom.wordpress.com/1387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dvanderboom.wordpress.com/1387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dvanderboom.wordpress.com/1387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dvanderboom.wordpress.com/1387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dvanderboom.wordpress.com/1387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dvanderboom.wordpress.com/1387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dvanderboom.wordpress.com/1387/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dvanderboom.wordpress.com/1387/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dvanderboom.wordpress.com/1387/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dvanderboom.wordpress.com&amp;blog=2293322&amp;post=1387&amp;subd=dvanderboom&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dvanderboom.wordpress.com/2010/10/03/the-archetype-language-part-9/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a59dbf3cc9c673540221e35e2c007ec1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Dan</media:title>
		</media:content>
	</item>
		<item>
		<title>The Archetype Language (Part 8)</title>
		<link>http://dvanderboom.wordpress.com/2010/10/01/the-archetype-language-part-8/</link>
		<comments>http://dvanderboom.wordpress.com/2010/10/01/the-archetype-language-part-8/#comments</comments>
		<pubDate>Fri, 01 Oct 2010 22:46:56 +0000</pubDate>
		<dc:creator>Dan Vanderboom</dc:creator>
				<category><![CDATA[Archetype Language]]></category>
		<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Language Innovation]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[User Interface Design]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">https://dvanderboom.wordpress.com/2010/10/01/the-archetype-language-part-8/</guid>
		<description><![CDATA[Overview This is part of a continuing series of articles about a new .NET language under development called Archetype.&#160; Archetype is a C-style (curly brace) functional, object-oriented (class-based), metaprogramming-capable language with features and syntax borrowed from many languages, as well as some new constructs.&#160; A major design goal is to succinctly and elegantly implement common [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dvanderboom.wordpress.com&amp;blog=2293322&amp;post=1328&amp;subd=dvanderboom&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong><font color="#800000">Overview</font></strong></p>
<p><font color="#800000">This is part of a continuing series of articles about a new .NET language under development called <strong>Archetype</strong>.&#160; Archetype is a C-style (curly brace) functional, object-oriented (class-based), metaprogramming-capable language with features and syntax borrowed from many languages, as well as some new constructs.&#160; A major design goal is to succinctly and elegantly implement common patterns that normally require a lot of boilerplate code which can be difficult, error-prone, or just plain onerous to write.</font></p>
<p><font color="#800000">You can follow the news and progress on the Archetype compiler on twitter<font color="#800000"> </font><a href="http://twitter.com/archetypelang"><font color="#800000">@archetypelang</font></a>.</font></p>
<p><font color="#800000">Links to the individual articles:</font></p>
<blockquote><p><a href="http://dvanderboom.wordpress.com/2010/04/26/new-language-code-named-archetype/"><font color="#800000">Part 1</font></a><font color="#800000"> – Properties and fields, function syntax, the me keyword</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/04/27/the-archetype-language-part-2/"><font color="#800000">Part 2</font></a><font color="#800000"> – Start function, named and anonymous delegates, delegate duck typing, bindable properties, composite bindings, binding expressions, namespace imports, string concatenation</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/04/27/the-archetype-language-part-3/"><font color="#800000">Part 3</font></a><font color="#800000"> – Exception handling, local variable definition, namespace imports, aliases, iteration (loop, fork-join, while, unless), calling functions and delegates asynchronously, messages</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/05/08/the-archetype-language-part-4/"><font color="#800000">Part 4</font></a><font color="#800000"> – Conditional selection (<strong>if</strong>), pattern matching, regular expression literals, agents, classes and traits</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/05/24/the-archetype-language-part-5/"><font color="#800000">Part 5</font></a><font color="#800000"> – Type extensions, custom control structures</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/06/14/the-archetype-language-part-6/"><font color="#800000">Part 6</font></a><font color="#800000"> – If expressions, enumerations, nullable types, tuples, streams, list comprehensions, subrange types, type constraint expressions</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/09/27/the-archetype-language-part-7/"><font color="#800000">Part 7</font></a><font color="#800000"><font color="#c0504d"><font color="#c0504d"> –</font> </font><font color="#800000">Semantic</font> density, operator overloading, custom operators</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/10/01/the-archetype-language-part-8/"><font color="#800000">Part 8</font></a><font color="#800000"> – Constructors, declarative Archetype: the initializer body</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/10/03/the-archetype-language-part-9/"><font color="#800000">Part 9</font></a><font color="#800000"> – Params &amp; fluent syntax, safe navigation operator, null coalescing operators</font></p>
</blockquote>
<p><font color="#800000">Conceptual articles about language design and development tools:</font></p>
<blockquote><p><a href="http://dvanderboom.wordpress.com/2010/06/14/language-design-complexity-extensibility-and-intention/"><font color="#800000">Language Design: Complexity, Extensibility, and Intention</font></a></p>
<p><a href="http://dvanderboom.wordpress.com/2010/05/31/reimagining-the-integrated-development-environment/"><font color="#800000">Reimagining the IDE</font></a></p>
<p><a href="http://dvanderboom.wordpress.com/2009/09/07/better-tool-support-for-net/"><font color="#800000">Better Tool Support for .NET</font></a></p>
</blockquote>
<h1>Constructors</h1>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">A constructor in Archetype is a recommended, predefined prototype for instantiating an object correctly. </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">The default parameterless constructor is defined implicitly (it&#8217;s defined even if it isn&#8217;t written), even if other constructors are defined explicitly. This last part<span> </span>is unlike other languages that hide the parameterless constructor when others are defined.<span>&#160; </span>This will make classes with these default constructors common in Archetype, to more easily support behaviors like serialization and dynamic construction.&#160; When it needs to be hidden, it can be defined with reduced visibility, such as private.</span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">A constructor is defined with the name <b>new</b>, consistent with how it’</span><span style="font-size:10pt;">s invoked.</span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">Let&#8217;s start with a very basic class, and build up to more complicated examples. </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><b><span style="font-family:consolas;color:#72830f;font-size:10pt;">Customer</span></b><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">object</span> </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><b><span style="font-family:consolas;color:#1f497d;font-size:10pt;">FirstName</span></b><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">string</span>; </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><b><span style="font-family:consolas;color:#1f497d;font-size:10pt;">LastName</span></b><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">string</span>; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">} </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">Despite the lack of an explicit constructor, it&#8217;s important for Archetype to define constructs that are useful in their default configurations.<span>&#160; </span>You couldn&#8217;t get more basic that the Customer class above.<span>&#160; </span>If we want to define the constructor explicitly, we can do so. </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><b><span style="font-family:consolas;color:#72830f;font-size:10pt;">Customer</span></b><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">object</span> </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><b><span style="font-family:consolas;color:#1f497d;font-size:10pt;">FirstName</span></b><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">string</span>; </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><b><span style="font-family:consolas;color:#1f497d;font-size:10pt;">LastName</span></b><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">string</span>; </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><b><span style="font-family:consolas;color:blue;font-size:10pt;">new</span></b><span style="font-family:consolas;color:blue;font-size:10pt;"> </span><span style="font-family:consolas;font-size:10pt;">() </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;color:green;font-size:10pt;">// do nothing </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">} </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">} </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">Instantiating a Customer object is easy. With the parameterless constructor, parentheses are optional. </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><b><span style="font-family:consolas;color:blue;font-size:10pt;">var</span></b><span style="font-family:consolas;font-size:10pt;"> dilbert = <b><span style="color:blue;">new</span></b> <span style="color:#72830f;">Customer</span>; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">Archetype, like C#, supports constructor initializers: </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><b><span style="font-family:consolas;color:blue;font-size:10pt;">var</span></b><span style="font-family:consolas;font-size:10pt;"> dilbert = <b><span style="color:blue;">new</span></b> <span style="color:#72830f;">Customer</span> </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">FirstName</span><span style="font-family:consolas;font-size:10pt;"> = <span style="color:#c00000;">&quot;Dilbert&quot;</span>, </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">LastName</span><span style="font-family:consolas;font-size:10pt;"> = <span style="color:#c00000;">&quot;Smith&quot;</span> </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">}; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">When you have few parameters and want to compress this call to a single line, the curly braces end up feeling a little too much (too formal?). </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><b><span style="font-family:consolas;color:blue;font-size:10pt;">var</span></b><span style="font-family:consolas;font-size:10pt;"> dilbert = <b><span style="color:blue;">new</span></b> <span style="color:#72830f;">Customer </span>{ <b><span style="color:#1f497d;">FirstName</span></b> = <span style="color:#c00000;">&quot;Dilbert&quot;</span>, <b><span style="color:#1f497d;">LastName</span></b> = <span style="color:#c00000;">&quot;Smith&quot;</span> }; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">Archetype supports passing these assignment statements as final arguments of the constructor parameter list, like this: </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><b><span style="font-family:consolas;color:blue;font-size:10pt;">var</span></b><span style="font-family:consolas;font-size:10pt;"> dilbert = <b><span style="color:blue;">new</span></b> <span style="color:#72830f;">Customer</span>(<b><span style="color:#1f497d;">FirstName</span></b> = <span style="color:#c00000;">&quot;Dilbert&quot;</span>, <b><span style="color:#1f497d;">LastName</span></b> = <span style="color:#c00000;">&quot;Smith&quot;</span>); </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">As a result, there isn&#8217;t much need to define constructors that only set fields and properties to the value of constructor parameters.<span>&#160; </span>Because Archetype has this mechanism for fluidly initializing objects at construction, the only time constructors really need to be defined is when construction of the object is complicated or unintuitive, in which case a supplied construction pattern is a sure way to make sure it&#8217;s done correctly.<span>&#160; </span>Our Customer example doesn&#8217;t meet those criteria, but if it did, this is one way we could write it: </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><b><span style="font-family:consolas;color:#72830f;font-size:10pt;">Customer</span></b><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">object</span> </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><b><span style="font-family:consolas;color:#1f497d;font-size:10pt;">FirstName</span></b><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">string</span>; </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><b><span style="font-family:consolas;color:#1f497d;font-size:10pt;">LastName</span></b><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">string</span>; </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:green;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><b><span style="font-family:consolas;color:blue;font-size:10pt;">new</span></b><span style="font-family:consolas;color:blue;font-size:10pt;"> </span><span style="font-family:consolas;font-size:10pt;">(FirstName <span style="color:#72830f;">string</span>, LastName <span style="color:#72830f;">string</span>) </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">this</span><span style="font-family:consolas;font-size:10pt;">.FirstName = FirstName; </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">this</span><span style="font-family:consolas;font-size:10pt;">.LastName = LastName; </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">} </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">} </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">To avoid having to qualify FirstName with the <b>this</b> keyword, many people prefer naming their parameters with the first character lower-cased.<span>&#160; T</span>hat&#8217;s an unfortunate compromise.<span>&#160; </span>When viewing at least the public members of a type, in a sense you&#8217;re creating an outward-facing API, and I think Pascal casing more naturally respects English grammar, not downplaying the signficance of the most-important first word in an identifier by lower-casing it to get around some unfortunate syntax limitation.</span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">But instead of taking sides in a naming convention war, we can solve the problem in the language and remove the need to make any compromise. </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><b><span style="font-family:consolas;color:blue;font-size:10pt;">new</span></b><span style="font-family:consolas;color:blue;font-size:10pt;"> </span><span style="font-family:consolas;font-size:10pt;">(FirstName <span style="color:#72830f;">string</span>, LastName <span style="color:#72830f;">string</span>) </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">set </span><span style="font-family:consolas;font-size:10pt;">FirstName, LastName; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">} </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;color:#72830f;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">This lets us set individual properties named the same as constructor parameters.<span>&#160; </span>It&#8217;s flexible enough to set some and consume other parameters differently, but when you want to set all parameters with matching member names, you can use the shortcut <b>set all</b>.<span>&#160; </span>If that&#8217;s all the constructor needs to do, we can do away with the curly braces:</span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><b><span style="font-family:consolas;color:blue;font-size:10pt;">new</span></b><span style="font-family:consolas;color:blue;font-size:10pt;"> </span><span style="font-family:consolas;font-size:10pt;">(FirstName <span style="color:#72830f;">string</span>, LastName <span style="color:#72830f;">string</span>) <span style="color:blue;">set all</span>; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">If our Customer class contained a BirthDate property, we could use this constructor and pass in an initializer statement as a final parameter. </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><b><span style="font-family:consolas;color:blue;font-size:10pt;">var</span></b><span style="font-family:consolas;font-size:10pt;"> dilbert = <b><span style="color:blue;">new</span></b> <span style="color:#72830f;">Customer</span>(<span style="color:#c00000;">&quot;Dilbert&quot;</span>, <span style="color:#c00000;">&quot;Smith&quot;</span>, <span style="color:#1f497d;">BirthDate</span> = <span style="color:#72830f;">DateTime</span>.<span style="color:#1f497d;">Parse</span>(<span style="color:#c00000;">&quot;7/4/1970&quot;</span>); </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">This works with multiple initializers.<span>&#160; </span>Alternatively, we could use an initializer body after the parameter list:</span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><b><span style="font-family:consolas;color:blue;font-size:10pt;">var</span></b><span style="font-family:consolas;font-size:10pt;"> dilbert = <b><span style="color:blue;">new</span></b> <span style="color:#72830f;">Customer</span>(<span style="color:#c00000;">&quot;Dilbert&quot;</span>, <span style="color:#c00000;">&quot;Smith&quot;</span>) </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">BirthDate</span><span style="font-family:consolas;font-size:10pt;"> = <span style="color:#72830f;">DateTime</span>.<span style="color:#1f497d;">Parse</span>(<span style="color:#c00000;">&quot;7/4/1970&quot;</span>) </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">}; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">Note how we have two places to supply data to a new object, if needed: the parameter list for simple, short values, and the initializer body for much larger assignments.</span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span><span style="font-size:10pt;">     <br />Another common construction pattern is for one or more constructors to call another constructor with a default set of properties.<span>&#160; </span>Typically the constructor with the full list of parameters performs the actual work, while the shorter constructors call into the main one, passing in some default values and passing the others through.</span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><b><span style="font-family:consolas;color:blue;font-size:10pt;">new</span></b><span style="font-family:consolas;color:blue;font-size:10pt;"> </span><span style="font-family:consolas;font-size:10pt;">(EvaluateFunc <span style="color:#72830f;">sFunc</span><span style="color:#663300;">&lt;</span><i><span style="color:#72830f;">T</span></i><span style="color:#663300;">&gt;</span>) <span style="color:blue;">new</span>(<span style="color:blue;">null</span>, <span style="color:blue;">null</span>, EvaluateFunc); </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><b><span style="font-family:consolas;color:blue;font-size:10pt;">new</span></b><span style="font-family:consolas;color:blue;font-size:10pt;"> </span><span style="font-family:consolas;font-size:10pt;">(BaseObject <span style="color:#72830f;">object</span>, EvaluateFunc<span style="color:#72830f;">sFunc</span><span style="color:#663300;">&lt;</span><i><span style="color:#72830f;">T</span></i><span style="color:#663300;">&gt;</span>) <span style="color:blue;">new</span>(<span style="color:blue;">null</span>, BaseObject, EvaluateFunc); </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><b><span style="font-family:consolas;color:blue;font-size:10pt;">new</span></b><span style="font-family:consolas;color:blue;font-size:10pt;"> </span><span style="font-family:consolas;font-size:10pt;">(Name <span style="color:#72830f;">string</span>, BaseObject <span style="color:#72830f;">object</span>, EvaluateFunc<span style="color:#72830f;"> Func</span><span style="color:#663300;">&lt;</span><i><span style="color:#72830f;">T</span></i><span style="color:#663300;">&gt;</span>) </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">set all</span><span style="font-family:consolas;font-size:10pt;">; </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:green;font-size:10pt;">// do all the real work&#8230; </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:green;font-size:10pt;">// &#8230; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">} </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span>&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><b><span style="color:#17365d;font-size:16pt;">Declarative Archetype: The Initializer Body</span></b><span style="color:#17365d;font-size:16pt;"> </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span>&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">The initializer body mentioned above has a special structure in Archetype.<span>&#160; </span>Member assignment statements can appear side-by-side with value expressions that are processed by a special function called <b>value</b>.<span>&#160; </span>This can be used, among other things, to add items to a collection.<span>&#160; </span>It&#8217;s best to see in an example: </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span>&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><b><span style="font-family:consolas;color:blue;font-size:10pt;">var</span></b><span style="font-family:consolas;font-size:10pt;"> dilbert = <b><span style="color:blue;">new</span></b> <span style="color:#72830f;">Customer</span> </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">FirstName</span><span style="font-family:consolas;font-size:10pt;"> = <span style="color:#c00000;">&quot;Dilbert&quot;</span>, </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">LastName</span><span style="font-family:consolas;font-size:10pt;"> = <span style="color:#c00000;">&quot;Smith&quot;</span>, </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">BirthDate</span><span style="font-family:consolas;font-size:10pt;"> = <span style="color:#72830f;">DateTime</span>.<span style="color:#1f497d;">Parse</span>(<span style="color:#c00000;">&quot;7/4/1970&quot;</span>), </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><b><span style="font-family:consolas;color:blue;font-size:10pt;">new</span></b><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">SalesOrder</span><span style="color:#663300;">(</span><span style="color:#1f497d;">OrderCode</span> = <span style="color:#c00000;">&quot;ORD012940&quot;</span>), </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><b><span style="font-family:consolas;color:blue;font-size:10pt;">new</span></b><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">SalesOrder</span> </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">OrderCode</span><span style="font-family:consolas;font-size:10pt;"> = <span style="color:#c00000;">&quot;ORD012941&quot;</span>, </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">new</span><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">SalesOrderLine</span>(<span style="color:#1f497d;">ItemCode</span> = <span style="color:#c00000;">&quot;S0139&quot;</span>, <span style="color:#1f497d;">Quantity</span> = 3), </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">new</span><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">SalesOrderLine</span>(<span style="color:#1f497d;">ItemCode</span> = <span style="color:#c00000;">&quot;S0142&quot;</span>, <span style="color:#1f497d;">Quantity</span> = 1) </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">} </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">}; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span>&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">The first three lines of the initializer set members with assignment statements.<span>&#160; </span>The next expression (<strong>new SalesOrder …</strong>) in the list creates an object, but there&#8217;s no assignment.<span>&#160; </span>It returns a value, but where does it go? <span>&#160;</span>Take a look at the <b>value</b> functions below for the answer: </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span>&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><b><span style="font-family:consolas;color:#72830f;font-size:10pt;">Customer</span></b><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">object</span> </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><b><span style="font-family:consolas;color:#1f497d;font-size:10pt;">FirstName</span></b><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">string</span>; </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><b><span style="font-family:consolas;color:#1f497d;font-size:10pt;">LastName</span></b><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">string</span>; </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><b><span style="font-family:consolas;color:#1f497d;font-size:10pt;">Orders </span></b><span style="font-family:consolas;color:#72830f;font-size:10pt;">SalesOrder* </span><span style="font-family:consolas;color:#663300;font-size:10pt;">=</span><span style="font-family:consolas;color:#72830f;font-size:10pt;"> </span><span style="font-family:consolas;color:blue;font-size:10pt;">new</span><span style="font-family:consolas;font-size:10pt;">; </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><b><span style="font-family:consolas;color:#1f497d;font-size:10pt;">Invoices </span></b><span style="font-family:consolas;color:#72830f;font-size:10pt;">Invoice* </span><span style="font-family:consolas;color:#663300;font-size:10pt;">=</span><span style="font-family:consolas;color:#72830f;font-size:10pt;"> </span><span style="font-family:consolas;color:blue;font-size:10pt;">new</span><span style="font-family:consolas;font-size:10pt;">; </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:green;font-size:10pt;">// formatted inline </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><b><span style="font-family:consolas;color:blue;font-size:10pt;">value </span></b><span style="font-family:consolas;font-size:10pt;">(Order <span style="color:#72830f;">SalesOrder</span>) Orders += Order; </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:green;font-size:10pt;">// formatted with full code block </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><b><span style="font-family:consolas;color:blue;font-size:10pt;">value </span></b><span style="font-family:consolas;font-size:10pt;">(Invoice <span style="color:#72830f;">Invoice</span>) </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">Invoices += Invoice; </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">} </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">} </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span>&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">A Customer has several collections of things&#8211;Orders and Invoices here&#8211;and because there are two <b>value</b> functions in the class, any expressions of type SalesOrder or Invoice will be evaluated and their values passed to the appropriate <b>value</b> function. Expressions of other types will trigger a compile-time error.</span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">The += and -= operators haven&#8217;t been shown before.<span>&#160; </span>Their use is a very natural fit for stream and list types.<span>&#160; </span>The += operator appends an object to a stream, and -= removes the first occurrence of that object. </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">This simple addition of a <b>value</b> function in types (classes and structs) gives Archetype the ability to represent hierarchical structures in a clean, declarative way.<span>&#160; </span>Sure it&#8217;s always been possible to format expressions similarly, but the syntactic trappings of imperative languages have made this difficult and unattractive at best, and in most real-world cases impractical. </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">When I experimented in <a href="http://dvanderboom.wordpress.com/2008/07/03/concurrency-with-futures/"><span style="color:blue;">creating a Future class</span></a>, I came up with a pattern in C# to nest structures in a tree for large future expressions, but the need to match parentheses gets in the way and consumes too much attention that’s better focused on the logic itself: </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span>&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;color:#2b91af;font-size:10pt;">Future</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&lt;</span><span style="font-family:consolas;color:blue;font-size:10pt;">string</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&gt; FuturePi = </span><span style="font-family:consolas;color:blue;font-size:10pt;">null</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">, FutureOmega = </span><span style="font-family:consolas;color:blue;font-size:10pt;">null</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">, FutureConcat = </span><span style="font-family:consolas;color:blue;font-size:10pt;">null</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">, FutureParen = </span><span style="font-family:consolas;color:blue;font-size:10pt;">null</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">;</span><span style="font-family:consolas;font-size:10pt;"> </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">var </span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">result = </span><span style="font-family:consolas;color:blue;font-size:10pt;">new </span><span style="font-family:consolas;color:#2b91af;font-size:10pt;">Future</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&lt;</span><span style="font-family:consolas;color:blue;font-size:10pt;">string</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&gt;(</span><span style="font-family:consolas;color:#a31515;font-size:10pt;">&quot;bracket&quot;</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">,      <br />&#160;&#160;&#160; () =&gt; Bracket(FutureParen),       <br /><span>&#160;&#160;&#160; </span>(FutureParen = </span><span style="font-family:consolas;color:blue;font-size:10pt;">new </span><span style="font-family:consolas;color:#2b91af;font-size:10pt;">Future</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&lt;</span><span style="font-family:consolas;color:blue;font-size:10pt;">string</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&gt;(</span><span style="font-family:consolas;color:#a31515;font-size:10pt;">&quot;parenthesize&quot;</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">,      <br /><span>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>() =&gt; Parenthesize(FutureConcat),       <br /><span>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>(FutureConcat = </span><span style="font-family:consolas;color:blue;font-size:10pt;">new </span><span style="font-family:consolas;color:#2b91af;font-size:10pt;">Future</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&lt;</span><span style="font-family:consolas;color:#2b91af;font-size:10pt;">String</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&gt;(</span><span style="font-family:consolas;color:#a31515;font-size:10pt;">&quot;concat&quot;</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">,      <br /><span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>() =&gt; FuturePi + </span><span style="font-family:consolas;color:#a31515;font-size:10pt;">&quot; &lt; &quot; </span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">+ FutureOmega,      <br /><span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>(FuturePi = </span><span style="font-family:consolas;color:blue;font-size:10pt;">new </span><span style="font-family:consolas;color:#2b91af;font-size:10pt;">Future</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&lt;</span><span style="font-family:consolas;color:blue;font-size:10pt;">string</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&gt;(</span><span style="font-family:consolas;color:#a31515;font-size:10pt;">&quot;pi&quot;</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">, () =&gt; CalculatePi(10))),      <br /><span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>(FutureOmega = </span><span style="font-family:consolas;color:blue;font-size:10pt;">new </span><span style="font-family:consolas;color:#2b91af;font-size:10pt;">Future</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&lt;</span><span style="font-family:consolas;color:blue;font-size:10pt;">string</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&gt;(</span><span style="font-family:consolas;color:#a31515;font-size:10pt;">&quot;omega&quot;</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">, () =&gt; CalculateOmega()))      <br /><span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>))       <br /><span>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>))       <br />&#160;&#160;&#160; );</span><span style="font-family:consolas;font-size:10pt;"> </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">The difference finally occurred to me between the need to set few simple members and the definition of larger, more structured content&#8211;including nested structures&#8211;that begged for a way to supply them without carrying the end parenthesis down multiple lines or letting them build up into <em>parentheses knots </em>that must be carefully counted.<span>&#160; </span>One gets to fidgeting with where to put them, and sometimes there&#8217;s no good answer to that.</span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">     <br />Another feature we need to make this declarative notation ability robust is inline variable declaration and assignment.<span>&#160; </span>Notice in the last example how several <i>intermediary structures</i> have variable names defined for them ahead of time, outside the expression.<span> </span>Writing that Future code, I felt it was unfortunate these variables couldn&#8217;t be defined inline as part of the expression.<span>&#160; </span>Doing so would allow us to define any kind of structure we might see in XML or JSON, such as this XAML UI code. </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span>&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">new </span><span style="font-family:consolas;color:#72830f;font-size:10pt;">Canvas </span><span style="font-family:consolas;font-size:10pt;">-&gt; LayoutRoot </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">Height</span><span style="font-family:consolas;font-size:10pt;"> = Auto, </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">Width</span><span style="font-family:consolas;font-size:10pt;"> = Auto, </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">new </span><span style="font-family:consolas;color:#72830f;font-size:10pt;">StackPanel </span><span style="font-family:consolas;font-size:10pt;">-&gt; sp </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">Orientation </span><span style="font-family:consolas;font-size:10pt;">= Vertical, </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">Height</span><span style="font-family:consolas;font-size:10pt;"> = 150, </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">Width</span><span style="font-family:consolas;font-size:10pt;"> = Auto, </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;color:#72830f;font-size:10pt;">Canvas</span><span style="font-family:consolas;font-size:10pt;">.<span style="color:#1f497d;">Top </span>= 10, </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;color:#72830f;font-size:10pt;">Canvas</span><span style="font-family:consolas;font-size:10pt;">.<span style="color:#1f497d;">Left </span>= 20, </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">with</span><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">Canvas</span> </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 81pt;" class="MsoNormal"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">Top</span><span style="font-family:consolas;font-size:10pt;"> = 10, </span></p>
<p style="line-height:normal;margin:0 0 0 81pt;" class="MsoNormal"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">Left</span><span style="font-family:consolas;font-size:10pt;"> = 20, </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">}, </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">with</span><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">Canvas </span>{ <span style="color:#1f497d;">Top</span> = 10, <span style="color:#1f497d;">Left</span> = 20 }, </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">Loaded</span><span style="font-family:consolas;font-size:10pt;"> += (sender, e) </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 81pt;" class="MsoNormal"><span style="font-family:consolas;color:#72830f;font-size:10pt;">Debug</span><span style="font-family:consolas;font-size:10pt;">.<span style="color:#1f497d;">WriteLine</span>(<span style="color:#c00000;">&quot;StackPanel sp.Loaded running&quot;</span>); </span></p>
<p style="line-height:normal;margin:0 0 0 81pt;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">sp.<span style="color:#1f497d;">ResizeTo</span>(0.5 <span style="color:#1f497d;">seconds</span>, Auto, 200).<span style="color:#1f497d;">Begin</span>(); </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">}, </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">LayoutUpdated</span><span style="font-family:consolas;font-size:10pt;"> += <span style="color:#1f497d;">HandleLayoutUpdated</span>, </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">new</span><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">TextBlock</span> </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 81pt;" class="MsoNormal"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">FontSize</span><span style="font-family:consolas;font-size:10pt;"> = 18, </span></p>
<p style="line-height:normal;margin:0 0 0 81pt;" class="MsoNormal"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">Text</span><span style="font-family:consolas;font-size:10pt;"> = <span style="color:#c00000;">&quot;Title&quot;</span> </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">}, </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">new</span><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">TextBlock</span> { <span style="color:#1f497d;">Text</span> = <span style="color:#c00000;">&quot;Paragraph 1&quot;</span> }, </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">new</span><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">TextBlock </span>{ <span style="color:#1f497d;">Text</span> = <span style="color:#c00000;">&quot;Paragraph 2&quot;</span> }, </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">new</span><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">TextBlock<font color="#72830f">(</font></span><span style="color:#1f497d;">Text</span> = <span style="color:#c00000;">&quot;Paragraph 3&quot;</span>) </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">} </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">}; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span>&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">A few notes are needed here: </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;text-indent:-.25in;vertical-align:middle;margin:0 0 0 27pt;" class="MsoNormal"><font face="Verdana"><span style="font-family:symbol;font-size:10pt;"><span>·<span style="font:7pt &quot;"><font face="Verdana">&#160;&#160; </font></span></span></span><span style="font-size:10pt;">Wow, this looks a lot like XAML, but much friendlier to developers who have to actually read and edit it!<span>&#160; </span><span style="color:#1f497d;">Yes, good observation.</span></span><span style="font-family:&quot;font-size:12pt;"><font size="2"> </font></span></font></p>
<p style="line-height:normal;text-indent:-.25in;vertical-align:middle;margin:0 0 0 27pt;" class="MsoNormal"><font face="Verdana"><span style="font-family:symbol;font-size:10pt;"><span>·<span style="font:7pt &quot;"><font size="2" face="Verdana">&#160; </font></span></span></span><span style="font-size:10pt;">Unlike XAML, every identifier here works with the all-important Rename refactoring, go to definition, find all references to, etc.<span> </span><span style="color:#1f497d;">This is great for reducing the amount of work to find relationships among things and manually update related files.</span></span><span style="font-family:&quot;font-size:12pt;"><font size="2"> </font></span></font></p>
<p style="line-height:normal;text-indent:-.25in;vertical-align:middle;margin:0 0 0 27pt;" class="MsoNormal"><font face="Verdana"><span style="font-family:&quot;font-size:12pt;"></span></font><font face="Verdana"><span style="font-family:symbol;font-size:10pt;"><span>·<span style="font:7pt &#039;"><font size="2" face="Verdana">&#160; </font></span></span></span></font><span style="font-size:10pt;">Also unlike XAML, code for event handlers can be defined here. <span style="color:#1f497d;">I’m not saying you should cram all of your event handler logic here, but it could come in quite handy at times and I can’t see any reason to disable it.</span></span><span style="font-family:&quot;font-size:12pt;"><font size="2" face="Verdana">&#160;</font></span></p>
<p style="line-height:normal;text-indent:-.25in;vertical-align:middle;margin:0 0 0 27pt;" class="MsoNormal"><font face="Verdana"><span style="font-family:symbol;font-size:10pt;"><span>·<span style="font:7pt &quot;"><font size="2" face="Verdana">&#160; </font></span></span></span><span style="font-size:10pt;">The <b>with</b> token is a custom operator (see <a href="http://dvanderboom.wordpress.com/2010/09/27/the-archetype-language-part-7/">Part 7</a>) that provides access to attached properties through an initializer body.</span><span style="font-size:10pt;">&#160;<span style="color:#1f497d;">Custom extensions allow you to access these properties with a natural member-access style.</span></span></font></p>
<p style="line-height:normal;text-indent:-.25in;vertical-align:middle;margin:0 0 0 27pt;" class="MsoNormal"><font face="Verdana"><span style="font-family:symbol;font-size:10pt;"><span>·<span style="font:7pt &#039;"><font size="2" face="Verdana">&#160; </font></span></span></span><span style="font-size:10pt;">It hasn’t been possible to use generic classes in XAML. S</span></font><span style="font-family:&#039;font-size:12pt;"><font size="2" face="Verdana">pecifying UI in Archetype, this would be trivial, and I suspect they could be used to good effect in many ways. Of course, in doing this you’d lose support for the designers in VS and Blend, which would be awfui.</font></span></p>
<p style="line-height:normal;text-indent:-.25in;vertical-align:middle;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:symbol;font-size:10pt;"><span><span style="font:7pt &#039;"></span></span></span><font face="Verdana"><span style="font-family:symbol;font-size:10pt;"><span>·<span style="font:7pt &quot;"><font size="2" face="Verdana">&#160; </font></span></span></span><span style="font-size:10pt;">Auto is simply an alias for double.NaN.</span><span style="font-family:&quot;font-size:12pt;"><font size="2"> </font></span></font></p>
<p style="line-height:normal;text-indent:-.25in;vertical-align:middle;margin:0 0 0 27pt;" class="MsoNormal"><font face="Verdana"><span style="font-family:symbol;font-size:10pt;"><span>·<span style="font:7pt &quot;"><font size="2" face="Verdana">&#160; </font></span></span></span><span style="font-size:10pt;">The -&gt; custom operator in these expressions defines a variable and sets it to the value of the new object.<span> </span>The order of execution is:</span><span style="font-family:&quot;font-size:12pt;"><font size="2"> </font></span></font></p>
<p style="line-height:normal;text-indent:-.25in;vertical-align:middle;margin:0 0 0 81pt;" class="MsoNormal"><span style="font-size:10pt;"><span>1.<span style="font:7pt &quot;"><font size="2" face="Verdana"> </font></span></span></span><span style="font-size:10pt;">Evaluate constructor parameters, if any are supplied. </span></p>
<p style="line-height:normal;text-indent:-.25in;vertical-align:middle;margin:0 0 0 81pt;" class="MsoNormal"><span style="font-size:10pt;"><span>2.<span style="font:7pt &quot;"><font size="2" face="Verdana"> </font></span></span></span><span style="font-size:10pt;">Assign the object to the variable defined with -&gt;, if supplied. </span></p>
<p style="line-height:normal;text-indent:-.25in;vertical-align:middle;margin:0 0 0 81pt;" class="MsoNormal"><span style="font-size:10pt;"><span>3.<span style="font:7pt &quot;"><font size="2" face="Verdana"> </font></span></span></span><span style="font-size:10pt;">Set any fields or properties with assignment statements. </span></p>
<p style="line-height:normal;text-indent:-.25in;vertical-align:middle;margin:0 0 0 81pt;" class="MsoNormal"><span style="font-size:10pt;"><span>4.<span style="font:7pt &quot;"><font size="2" face="Verdana"> </font></span></span></span><span style="font-size:10pt;">Evaluate value expressions, if supplied, and call the class&#8217;s <b>value</b> function with each one, if a<b> value</b> function has been defined. </span></p>
<p style="line-height:normal;text-indent:-.25in;vertical-align:middle;margin:0 0 0 81pt;" class="MsoNormal"><span style="font-size:10pt;"><span>5.<span style="font:7pt &quot;"><font size="2" face="Verdana"> </font></span></span></span><span style="font-size:10pt;">Invoke any matching <b>value</b> function defined in class extensions. </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">By following this design, the example above can be translated into this C# code by the Archetype compiler: </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">var </span><span style="font-family:consolas;font-size:10pt;">LayoutRoot<span style="color:blue;"> </span>=<span style="color:blue;"> new </span><span style="color:#72830f;">Canvas</span>() </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">Height</span><span style="font-family:consolas;font-size:10pt;"> = <span style="color:#72830f;">double</span>.<span style="color:#1f497d;">NaN</span>, </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">Width</span><span style="font-family:consolas;font-size:10pt;"> = <span style="color:#72830f;">double</span>.<span style="color:#1f497d;">NaN</span> </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">}; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">var</span><span style="font-family:consolas;font-size:10pt;"> sp = <span style="color:blue;">new</span> <span style="color:#72830f;">StackPanel</span>() </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">Orientation</span><span style="font-family:consolas;font-size:10pt;"> = <span style="color:#72830f;">Orientation</span>.<span style="color:#1f497d;">Vertical</span>, </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">Height</span><span style="font-family:consolas;font-size:10pt;"> = 150.0, </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">Width</span><span style="font-family:consolas;font-size:10pt;"> = <span style="color:#72830f;">double</span>.<span style="color:#1f497d;">NaN</span> </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">}; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">LayoutRoot.<span style="color:#1f497d;">Children</span>.Add(sp); </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">sp.<span style="color:#1f497d;">SetValue</span>(<span style="color:#72830f;">Canvas</span>.<span style="color:#1f497d;">TopProperty</span>, 10.0); </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">sp.<span style="color:#1f497d;">SetValue</span>(<span style="color:#72830f;">Canvas</span>.<span style="color:#1f497d;">LeftProperty</span>, 20.0); </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">sp.<span style="color:#1f497d;">Loaded</span> += (sender, e) </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:#72830f;font-size:10pt;">Debug</span><span style="font-family:consolas;font-size:10pt;">.<span style="color:#1f497d;">WriteLine</span>(<span style="color:#c00000;">&quot;StackPanel sp.Loaded running&quot;</span>); </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">sp.<span style="color:#1f497d;">ResizeTo</span>(0.5.<span style="color:#1f497d;">seconds</span>(), <span style="color:#72830f;">double</span>.<span style="color:#1f497d;">NaN</span>, 200.0).<span style="color:#1f497d;">Begin</span>(); </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">}, </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">sp.<span style="color:#1f497d;">LayoutUpdated</span> += <span style="color:#1f497d;">HandleLayoutUpdated</span>; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">sp.<span style="color:#1f497d;">Children</span>.<span style="color:#1f497d;">Add</span>(<span style="color:blue;">new</span> <span style="color:#72830f;">TextBlock</span>() { <span style="color:#1f497d;">FontSize</span> = 18, <span style="color:#1f497d;">Text</span> = <span style="color:#c00000;">&quot;Title&quot;</span>}); </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">sp.<span style="color:#1f497d;">Children</span>.<span style="color:#1f497d;">Add</span>(<span style="color:blue;">new</span> <span style="color:#72830f;">TextBlock</span>() { <span style="color:#1f497d;">Text</span> = <span style="color:#c00000;">&quot;Paragraph 1&quot;</span>}); </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">sp.<span style="color:#1f497d;">Children</span>.<span style="color:#1f497d;">Add</span>(<span style="color:blue;">new</span> <span style="color:#72830f;">TextBlock</span>() { <span style="color:#1f497d;">Text</span> = <span style="color:#c00000;">&quot;Paragraph 2&quot;</span>}); </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">sp.<span style="color:#1f497d;">Children</span>.<span style="color:#1f497d;">Add</span>(<span style="color:blue;">new</span> <span style="color:#72830f;">TextBlock</span>() { <span style="color:#1f497d;">Text</span> = <span style="color:#c00000;">&quot;Paragraph 3&quot;</span>}); </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">var </span><span style="font-family:consolas;font-size:10pt;">VisualTree<span style="color:blue;"> </span>= LayoutRoot; </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="color:#1f497d;font-size:10pt;">&#160; </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">Compare the two approaches.<span> </span>The C# code is a typical example of imperative structure building, while the Archetype code is arguably as declarative as XAML, and with many advantages over XAML for developers.</span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;">     <br />Going back to the Future example, we could rewrite this in Archetype a few different ways.&#160; I’ll present two.&#160; In the first one, <strong>value</strong> functions are used to receive the future’s evaluation function as well as any Future objects the expression depends on.</span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">     <br />new </span><span style="font-family:consolas;color:#72830f;font-size:10pt;">Future</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&lt;</span><span style="font-family:consolas;color:#72830f;font-size:10pt;">string</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&gt;(</span><span style="font-family:consolas;color:#a31515;font-size:10pt;">&quot;bracket&quot;</span><span style="font-family:consolas;font-size:10pt;">) -&gt; result </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">() =&gt; Bracket(FutureParen),      <br /></span><span style="font-family:consolas;color:blue;font-size:10pt;">new </span><span style="font-family:consolas;color:#72830f;font-size:10pt;">Future</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&lt;</span><span style="font-family:consolas;color:#72830f;font-size:10pt;">string</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&gt;(</span><span style="font-family:consolas;color:#a31515;font-size:10pt;">&quot;parenthesize&quot;</span><span style="font-family:consolas;font-size:10pt;">)<span style="color:#a31515;"> </span><span style="color:#2a2a2a;">-&gt; FutureParen</span> </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">() =&gt; Parenthesize(FutureConcat),      <br /></span><span style="font-family:consolas;color:blue;font-size:10pt;">new </span><span style="font-family:consolas;color:#72830f;font-size:10pt;">Future</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&lt;</span><span style="font-family:consolas;color:#72830f;font-size:10pt;">string</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&gt;(</span><span style="font-family:consolas;color:#a31515;font-size:10pt;">&quot;concat&quot;) </span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">-&gt; FutureConcat</span><span style="font-family:consolas;font-size:10pt;"> </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 81pt;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">() =&gt; FuturePi + </span><span style="font-family:consolas;color:#a31515;font-size:10pt;">&quot; &lt; &quot; </span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">+ FutureOmega,      <br /></span><span style="font-family:consolas;color:blue;font-size:10pt;">new </span><span style="font-family:consolas;color:#72830f;font-size:10pt;">Future</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&lt;</span><span style="font-family:consolas;color:#72830f;font-size:10pt;">string</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&gt;(</span><span style="font-family:consolas;color:#a31515;font-size:10pt;">&quot;pi&quot;</span><span style="font-family:consolas;font-size:10pt;">)<span style="color:#2a2a2a;"> -&gt; FuturePi</span> </span></p>
<p style="line-height:normal;margin:0 0 0 81pt;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 1.5in;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">() =&gt; CalculatePi(10) </span></p>
<p style="line-height:normal;margin:0 0 0 81pt;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">}, </span></p>
<p style="line-height:normal;margin:0 0 0 81pt;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">new </span><span style="font-family:consolas;color:#72830f;font-size:10pt;">Future</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&lt;</span><span style="font-family:consolas;color:#72830f;font-size:10pt;">string</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&gt;(</span><span style="font-family:consolas;color:#a31515;font-size:10pt;">&quot;omega&quot;</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">) -&gt; FutureOmega</span><span style="font-family:consolas;font-size:10pt;"> </span></p>
<p style="line-height:normal;margin:0 0 0 81pt;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 1.5in;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">() =&gt; CalculateOmega() </span></p>
<p style="line-height:normal;margin:0 0 0 81pt;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">} </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">} </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">} </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">} </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;"></span><span style="font-size:10pt;">     <br />The shorter approach passes an evaluation delegate in as a parameter.</span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">     <br />new </span><span style="font-family:consolas;color:#72830f;font-size:10pt;">Future</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&lt;</span><span style="font-family:consolas;color:#72830f;font-size:10pt;">string</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&gt;(</span><span style="font-family:consolas;font-size:10pt;"><span style="color:#2a2a2a;">() =&gt; </span><span style="color:#1f497d;">Bracket</span><span style="color:#2a2a2a;">(FutureParen))</span> -&gt; result </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">new </span><span style="font-family:consolas;color:#72830f;font-size:10pt;">Future</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&lt;</span><span style="font-family:consolas;color:#72830f;font-size:10pt;">string</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&gt;(</span><span style="font-family:consolas;font-size:10pt;"><span style="color:#2a2a2a;">() =&gt; Parenthesize(FutureConcat))</span><span style="color:#a31515;"> </span><span style="color:#2a2a2a;">-&gt; FutureParen</span> </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">new </span><span style="font-family:consolas;color:#72830f;font-size:10pt;">Future</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&lt;</span><span style="font-family:consolas;color:#72830f;font-size:10pt;">string</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&gt;(</span><span style="font-family:consolas;font-size:10pt;"><span style="color:#2a2a2a;">() =&gt; FuturePi + </span><span style="color:#a31515;">&quot; &lt; &quot; </span><span style="color:#2a2a2a;">+ FutureOmega</span><span style="color:#a31515;"><font color="#000000">)</font> </span><span style="color:#2a2a2a;">-&gt; FutureConcat</span> </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">{ </span></p>
<p style="line-height:normal;margin:0 0 0 81pt;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">new </span><span style="font-family:consolas;color:#72830f;font-size:10pt;">Future</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&lt;</span><span style="font-family:consolas;color:#72830f;font-size:10pt;">string</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&gt;(</span><span style="font-family:consolas;font-size:10pt;"><span style="color:#2a2a2a;">() =&gt; CalculatePi(10)</span>)<span style="color:#2a2a2a;"> -&gt; FuturePi,</span> </span></p>
<p style="line-height:normal;margin:0 0 0 81pt;" class="MsoNormal"><span style="font-family:consolas;color:blue;font-size:10pt;">new </span><span style="font-family:consolas;color:#72830f;font-size:10pt;">Future</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&lt;</span><span style="font-family:consolas;color:#72830f;font-size:10pt;">string</span><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">&gt;(</span><span style="font-family:consolas;font-size:10pt;"><span style="color:#2a2a2a;">() =&gt; CalculateOmega()) -&gt; FutureOmega</span> </span></p>
<p style="line-height:normal;margin:0 0 0 .75in;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">} </span></p>
<p style="line-height:normal;margin:0 0 0 27pt;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">} </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;">} </span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-family:consolas;color:#2a2a2a;font-size:10pt;"></span></p>
<p> <span style="font-family:consolas;color:#2a2a2a;font-size:10pt;"></span><span style="font-size:10pt;">
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal">&#160;</p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal">The name string parameter is missing from the last example.&#160; This was only for use during debugging.&#160; Now what we have is a very direct description of futures that are dependent on other futures in a dependency graph.      </p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal">
<p> </span>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<p style="line-height:normal;margin-bottom:0;" class="MsoNormal"><span style="font-size:10pt;"></span></p>
<h1>Summary</h1>
<p><font size="2">Object construction is a crucial part of an object-oriented language, and Archetype is advanced with its options for constructing arbitrary object graphs and initializing even complicated state in a single expression.&#160; These fluent declarative syntax features are ideal for representing structures such as XAML UI, state machines, dependency graphs, and much more.</font></p>
<p><font size="2">XAML is a language.&#160; The question this work has me asking is: do we really need a separate language if our general purpose language supports highly declarative syntax? It’s a provocative question without an easy answer, but it seems clear that many DSLs could emerge within a language that so richly supports composition.</font></p>
<p><font size="2">With the ability to define arbitrarily complex structures in code—from declarative object graphs to rich functional expressions—it’s hard to think of a situation that would be too difficult to model and build an API or application around.</font></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dvanderboom.wordpress.com/1328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dvanderboom.wordpress.com/1328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dvanderboom.wordpress.com/1328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dvanderboom.wordpress.com/1328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dvanderboom.wordpress.com/1328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dvanderboom.wordpress.com/1328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dvanderboom.wordpress.com/1328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dvanderboom.wordpress.com/1328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dvanderboom.wordpress.com/1328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dvanderboom.wordpress.com/1328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dvanderboom.wordpress.com/1328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dvanderboom.wordpress.com/1328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dvanderboom.wordpress.com/1328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dvanderboom.wordpress.com/1328/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dvanderboom.wordpress.com&amp;blog=2293322&amp;post=1328&amp;subd=dvanderboom&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dvanderboom.wordpress.com/2010/10/01/the-archetype-language-part-8/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a59dbf3cc9c673540221e35e2c007ec1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Dan</media:title>
		</media:content>
	</item>
		<item>
		<title>The Archetype Language (Part 7)</title>
		<link>http://dvanderboom.wordpress.com/2010/09/27/the-archetype-language-part-7/</link>
		<comments>http://dvanderboom.wordpress.com/2010/09/27/the-archetype-language-part-7/#comments</comments>
		<pubDate>Mon, 27 Sep 2010 06:48:23 +0000</pubDate>
		<dc:creator>Dan Vanderboom</dc:creator>
				<category><![CDATA[Archetype Language]]></category>
		<category><![CDATA[Composability]]></category>
		<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Language Innovation]]></category>

		<guid isPermaLink="false">https://dvanderboom.wordpress.com/2010/09/27/the-archetype-language-part-7/</guid>
		<description><![CDATA[Overview This is part of a continuing series of articles about a new .NET language under development called Archetype.&#160; Archetype is a C-style (curly brace) functional, object-oriented (class-based), metaprogramming-capable language with features and syntax borrowed from many languages, as well as some new constructs.&#160; A major design goal is to succinctly and elegantly implement common [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dvanderboom.wordpress.com&amp;blog=2293322&amp;post=1224&amp;subd=dvanderboom&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong><font color="#800000">Overview</font></strong></p>
<p><font color="#800000">This is part of a continuing series of articles about a new .NET language under development called <strong>Archetype</strong>.&#160; Archetype is a C-style (curly brace) functional, object-oriented (class-based), metaprogramming-capable language with features and syntax borrowed from many languages, as well as some new constructs.&#160; A major design goal is to succinctly and elegantly implement common patterns that normally require a lot of boilerplate code which can be difficult, error-prone, or just plain onerous to write.</font></p>
<p><font color="#800000">You can follow the news and progress on the Archetype compiler on twitter<font color="#800000"> </font><a href="http://twitter.com/archetypelang"><font color="#800000">@archetypelang</font></a>.</font></p>
<p><font color="#800000">Links to the individual articles:</font></p>
<blockquote><p><a href="http://dvanderboom.wordpress.com/2010/04/26/new-language-code-named-archetype/"><font color="#800000">Part 1</font></a><font color="#800000"> – Properties and fields, function syntax, the me keyword</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/04/27/the-archetype-language-part-2/"><font color="#800000">Part 2</font></a><font color="#800000"> – Start function, named and anonymous delegates, delegate duck typing, bindable properties, composite bindings, binding expressions, namespace imports, string concatenation</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/04/27/the-archetype-language-part-3/"><font color="#800000">Part 3</font></a><font color="#800000"> – Exception handling, local variable definition, namespace imports, aliases, iteration (loop, fork-join, while, unless), calling functions and delegates asynchronously, messages</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/05/08/the-archetype-language-part-4/"><font color="#800000">Part 4</font></a><font color="#800000"> – Conditional selection (<strong>if</strong>), pattern matching, regular expression literals, agents, classes and traits</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/05/24/the-archetype-language-part-5/"><font color="#800000">Part 5</font></a><font color="#800000"> – Type extensions, custom control structures</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/06/14/the-archetype-language-part-6/"><font color="#800000">Part 6</font></a><font color="#800000"> – If expressions, enumerations, nullable types, tuples, streams, list comprehensions, subrange types, type constraint expressions</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/09/27/the-archetype-language-part-7/"><font color="#800000">Part 7</font></a><font color="#800000"><font color="#c0504d"><font color="#c0504d"> –</font> </font><font color="#800000">Semantic</font> density, operator overloading, custom operators</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/10/01/the-archetype-language-part-8/"><font color="#800000">Part 8</font></a><font color="#800000"> – Constructors, declarative Archetype: the initializer body</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/10/03/the-archetype-language-part-9/"><font color="#800000">Part 9</font></a><font color="#800000"> – Params &amp; fluent syntax, safe navigation operator, null coalescing operators</font></p>
</blockquote>
<p><font color="#800000">Conceptual articles about language design and development tools:</font></p>
<blockquote><p><a href="http://dvanderboom.wordpress.com/2010/06/14/language-design-complexity-extensibility-and-intention/"><font color="#800000">Language Design: Complexity, Extensibility, and Intention</font></a></p>
<p><a href="http://dvanderboom.wordpress.com/2010/05/31/reimagining-the-integrated-development-environment/"><font color="#800000">Reimagining the IDE</font></a></p>
<p><a href="http://dvanderboom.wordpress.com/2009/09/07/better-tool-support-for-net/"><font color="#800000">Better Tool Support for .NET</font></a></p>
</blockquote>
<h1>Semantic Density</h1>
<p>As an avid reader growing up, I noticed that my knowledge and understanding of a topic grew more easily the faster I read.&#160; Instead of going through a chapter every day or two, which puts weeks or months between the front and back covers, I devoured 200-300 pages in a night, getting through the largest books in a couple days.&#160; And in reading multiple books on a subject back-to-back, it was easier to find relationships and tie together concepts for things that were still so fresh in my memory.</p>
<p>In my study of linguistics, I learned that legends like <a href="http://en.wikipedia.org/wiki/Noam_Chomsky">Noam Chomsky</a> could learn hundreds of langauges; the previous librarian at the Vatican could read 97.&#160; Bodmer’s excellent book <a href="http://www.amazon.com/Loom-Language-Approach-Mastery-Languages/dp/039330034X/ref=sr_1_1?s=gateway&amp;ie=UTF8&amp;qid=1285561628&amp;sr=8-1">The Loom of Language</a> attempts to teach 10 languages at once, and it seems that the more languages you learn, the easier it is to pick up others.</p>
<p>What these examples have in common is semantic density.&#160; It might seem from what I’ve said that this would be like drinking from a firehose which only the most gifted could endure, but I would argue that intensely-focused learning puts our minds in a highly alert and receptive condition.&#160; In such a state, being able to draw more connections between statements and ideas, we are better able to comprehend the whole in a holistic, intuitive way.</p>
<h2>Code Example</h2>
<p>Semantic density is important in code, too.&#160; With a pattern like INotifyPropertyChanged, formatted as I have it below, it’s 12 lines of code, 13 if you separate your fields and properties with a blank line, but in the ballpark of a dozen lines of code.&#160; (This is additional explanation for a feature described in <a href="http://dvanderboom.wordpress.com/2010/04/27/the-archetype-language-part-2/">part 2 of this series</a>.)</p>
<p><font face="Consolas"><font size="2"><strong>1:</strong>&#160;&#160; </font></font><font face="Consolas"><font size="2"><span style="color:blue;">string </span>_Display;         <br /><strong>2:</strong>&#160;&#160; <span style="color:blue;">public string </span>Display         <br /><strong>3:</strong>&#160;&#160; {         <br /><strong>4:</strong>&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">get </span>{ <span style="color:blue;">return </span>_Display; }         <br /><strong>5:</strong>&#160;&#160;&#160;&#160;&#160;&#160; </font></font><font face="Consolas"><font size="2"><span style="color:blue;">set          <br /><font color="#000000"><strong>6:</strong></font>&#160;&#160;&#160;&#160;&#160;&#160; </span>{         <br /><strong>7:</strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _Display = <span style="color:blue;">value</span>;         <br /><strong>8:</strong>&#160; <br /><strong>9:</strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">if </span>(PropertyChanged != <span style="color:blue;">null</span>)         <br /><strong>10:</strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; PropertyChanged(<span style="color:blue;">this</span>, <span style="color:blue;">new </span><span style="color:#2b91af;">PropertyChangedEventArgs</span>(<span style="color:#a31515;">&quot;Display&quot;</span>));         <br /><strong>11:</strong>&#160;&#160;&#160;&#160;&#160; }         <br /><strong>12:</strong>&#160; }</font></font></p>
<p>Does the ability to inform external code of changes seem like it should take a dozen lines to get there?&#160; <font size="2" face="Consolas">This can be somewhat compressed by defining a SetProperty method:</font></p>
<pre class="code"><font face="Consolas"><font size="2"><strong>1:</strong>   </font></font><font face="Consolas"><font size="2"><span style="color:blue;">string </span>_Display;
<strong>2:</strong>   <span style="color:blue;">public string </span>Display
<strong>3:</strong>   {
<strong>4:</strong>       <span style="color:blue;">get </span>{ <span style="color:blue;">return </span>_Display; }
<strong>5:</strong>       <span style="color:blue;">set </span>{ SetProperty(<span style="color:#a31515;">&quot;Display&quot;</span>, <span style="color:blue;">ref </span>_Display, <span style="color:blue;">value</span>); }
<strong>6:</strong>   }</font></font></pre>
<p>
  <br />This chops the line count in half, bringing it down to six lines&#8211;seven if you include a space above or below to separate it from other members.&#160; On my monitor, that means I can see about eight property definitions at a time.&#160; Now that’s usually enough, but I’ve written a few custom controls&#160; that have upwards of 30 properties.&#160; For a new pair of eyes, getting the gist of that class is going to involve a lot of scrolling, never seeing more than a small slice at a time of a much large picture.&#160; The frame of time I mentioned earlier in regard to studying a subject is analogous here to the frame of space.&#160; Seeing 20% of a class at any time lends itself to faster grokking than seeing a 2% sliver at a time.&#160; Our minds, marvelous as they are, do have limits.&#160; Lowering semantic density, such as by spreading meaning over large distances or time spans, makes us work harder to accomplish the same task, trying to put all the pieces together, and the differences are often dramatic.</p>
<p>Just as nouns can be modified by adjectives in natural languages, types in Archetype support user-defined type modifiers.&#160; By defining a new type modifier called <strong>bindable </strong>to encapsulate the INotifyPropertyChanged pattern, we can collapse the above example into a single line:</p>
<p style="margin:0;"><font face="Consolas"><font size="2"><strong>1:&#160;&#160; </strong><span style="font-family:consolas;font-size:11pt;">Age <span style="color:blue;">bindable</span> <span style="color:#72830f;">int</span>;</span></font></font></p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">I have no problem stacking these properties right on top of one another.&#160; Although expressed in a highly dense form, it’s actually easier to understand at a glance in these three simple tokens than in the half-dozen lines above, which beg for interpretation to assemble their meaning.&#160; Even if we have 30 of these, they’d all fit on one screen, and the purpose of the class as a whole is quickly gathered.</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">One thing I noticed in developing the animation library <a href="http://animatedotnet.codeplex.com/">Animate.NET</a> is how much code I saved: not having to worry about the details of storyboard creation, key frames, and so on.&#160; It allows you to get right to the point of stating your intention.&#160; Often a library like this is enough, but once in a while language extensibility is a much better approach; and when it is, not having the option can be painful and time consuming.</p>
<p style="margin:0;">&#160;</p>
<h1>Custom Operators &amp; Operator Overloading</h1>
<p>As in most languages, Archetype supports two forms of syntax for operations: functions and operators.&#160; Functions are invoked by including a pair of parentheses after their name that contain any arguments to pass in, whereas operators appear adjacent to or between sub-expressions.&#160; </p>
<p>In C#, some operators are available for overloading.&#160; Archetype supports these operator overloads by using the same names for them.&#160; This allows Archetype to use operators defined in C# and to expose supported operators to C# consumers.</p>
<p>However, Archetype goes one step further and allows you to define custom operators.&#160; There are three basic kinds of custom operator:</p>
<ol>
<li>unary prefix </li>
<li>unary suffix </li>
<li>binary </li>
</ol>
<p>If we wanted an easy way to duplicate strings in C#, we might define an extension method called <strong>Dup</strong>, but in Archetype we also have this option:</p>
<p style="margin:0;"><span style="font-family:consolas;color:green;font-size:11pt;">// &quot;ABC&quot; dup 3 == &quot;ABCABCABC&quot; </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:#0066cc;font-size:11pt;">binary</span><span style="font-family:consolas;font-size:11pt;"> dup <span style="color:#72830f;">string </span>(left <span style="color:#72830f;">string</span>, right <span style="color:#72830f;">int</span>) </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#0066cc;font-size:11pt;">return</span><span style="font-family:consolas;font-size:11pt;"> <span style="color:#72830f;">string</span>.<span style="color:#1f497d;">Repeat</span>(left, right)</span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:11pt;"></span></p>
<p>
  <br />The expression parser sees “ABC”, identifies it as a string value, and then looks at the next token.&#160; If the dot operator were found (.), it would look for a member of string or an extension member on string, but because the next token isn’t the dot operator, it looks up the token in the operator table.&#160; An operator called <strong>dup</strong> is defined with a left string argument and a right int argument, matching the expression.&#160; If the operator were more complicated, it would have a curly-brace code block, but because it’s a single return statement, that’s optional.</p>
<p>Archetype operators aren’t limited to letters, though.&#160; We can also use symbols (but not numbers) in our operator names.&#160; Here’s a “long forward arrow” (compiled with name DashDashGreaterThan) that allows us to write a single function parameter before the function name itself:</p>
<p style="margin:0;"><span style="font-family:consolas;color:green;font-size:11pt;">// &quot;Hey&quot; &#8211;&gt; Console.WriteLine; </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:#0066cc;font-size:11pt;">binary</span><span style="font-family:consolas;font-size:11pt;">&lt;<span style="color:#72830f;">T</span>&gt; &#8211;&gt; <span style="color:#72830f;">void </span>(left <span style="color:#72830f;">T</span>, right <span style="color:#72830f;">Action&lt;T&gt;</span>) </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:11pt;">right(left);</span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:11pt;"></span></p>
<p>
  <br />Note that the generic type parameter is attached to the <strong>binary</strong> keyword.&#160; I arrived at this placement through much experimentation.&#160; Names like &#8211;&gt;&lt;T&gt; are difficult to read and can be trickier to parse.</p>
<p>There is a special binary operator called <strong>adjacent</strong> which you can think of as an “invisible operator” capable of inserting an operation between two sub-expressions.&#160; In the following example, two adjacent strings are interpreted as a concatenation of the two.</p>
<p style="margin:0;"><span style="font-family:consolas;color:green;font-size:11pt;">// &quot;123&quot; &quot;45&quot; == &quot;12345&quot; </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:#0066cc;font-size:11pt;">binary</span><span style="font-family:consolas;font-size:11pt;"> <span style="color:#0066cc;">adjacent</span> <span style="color:#72830f;">string </span>(left <span style="color:#72830f;">string</span>, right <span style="color:#72830f;">string</span>) </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#0066cc;font-size:11pt;">return</span><span style="font-family:consolas;font-size:11pt;"> left + right;</span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:11pt;"></span></p>
<p><font></font></p>
<p>With custom operators, what was originally part of the language can now be defined in a library instead.&#160; This greatly simplifies the language.&#160; Just as methods can be shadowed to override them, so too will some ability be needed in Archetype to block or override operators that would otherwise be imported along with a namespace.</p>
<p>The next operator we’ll look at is the <strong>unary suffix</strong>.&#160; The example consists of units of time: minutes and seconds.</p>
<p style="margin:0;"><span style="font-family:consolas;color:green;font-size:11pt;">// 12 minutes == TimeSpan.FromMinutes(12) </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:#0066cc;font-size:11pt;">unary suffix</span><span style="font-family:consolas;font-size:11pt;"> minutes <span style="color:#72830f;">TimeSpan </span>(<span style="color:#72830f;">short</span>, <span style="color:#72830f;">int</span>) </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#0066cc;font-size:11pt;">return</span><span style="font-family:consolas;font-size:11pt;"> <span style="color:#72830f;">TimeSpan</span>.<span style="color:#1f497d;">FromMinutes</span>((<span style="color:#72830f;">int</span>)value); </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:11pt;">&#160; </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:green;font-size:11pt;">// 3 seconds == TimeSpan.FromSeconds(3) </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:#0066cc;font-size:11pt;">unary suffix</span><span style="font-family:consolas;font-size:11pt;"> seconds <span style="color:#72830f;">TimeSpan </span>(<span style="color:#72830f;">short</span>, <span style="color:#72830f;">int</span>) </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#0066cc;font-size:11pt;">return</span><span style="font-family:consolas;font-size:11pt;"> <span style="color:#72830f;">TimeSpan</span>.<span style="color:#1f497d;">FromSeconds</span>((<span style="color:#72830f;">int</span>)value);</span></p>
<p>
  <br />With support for extension properties, we could have also said 12.minutes or 3.seconds, which is already better than C#’s 12.minutes() and 3.seconds(), but by defining these tokens as unary suffix operators, we can eliminate even the dot operator and make it that much more fluent and natural to type (without losing any syntactic precision).&#160; Notice how a list of types is provided instead of a parameter list.&#160; Unary operators by definition have only a single argument, but we often want them to operate on several different types.</p>
<p>Here’s a floating point operator for <strong>seconds</strong>.</p>
<p style="margin:0;"><span style="font-family:consolas;color:green;font-size:11pt;">// 2.5 seconds == (2 seconds).Add(0.5 * 1000 milliseconds) </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:green;font-size:11pt;">// WholeNumber and Fraction are extension properties on float, double, and decimal </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:#0066cc;font-size:11pt;">unary suffix</span><span style="font-family:consolas;font-size:11pt;"> seconds <span style="color:#72830f;">TimeSpan </span>(<span style="color:#72830f;">float</span>, <span style="color:#72830f;">double</span>, <span style="color:#72830f;">decimal</span>) </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#0066cc;font-size:11pt;">return value</span><span style="font-family:consolas;font-size:11pt;">.<span style="color:#1f497d;">WholeNumber</span> seconds + <span style="color:#0066cc;">value</span>.<span style="color:#1f497d;">Fraction</span> * 1000 milliseconds; </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:11pt;"></span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:11pt;"></span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:11pt;"></span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:11pt;"></span></p>
<h2></h2>
<p>We can use the adjacent operator on TimeSpans the same that we did for strings above.</p>
<p style="margin:0;"><span style="font-family:consolas;color:green;font-size:11pt;">// 4 minutes 10 seconds == (4 minutes).Add(10 seconds) </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:#0066cc;font-size:11pt;">binary adjacent </span><span style="font-family:consolas;color:#72830f;font-size:11pt;">TimeSpan </span><span style="font-family:consolas;font-size:11pt;">(left <span style="color:#72830f;">TimeSpan</span>, right <span style="color:#72830f;">TimeSpan</span>) </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#0066cc;font-size:11pt;">return </span><span style="font-family:consolas;font-size:11pt;">left.Add(right);</span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:11pt;"></span></p>
<p><font></font></p>
<p>Now let’s combine the use of a few of these operators into a single example.</p>
<p style="margin:0;"><span style="font-family:consolas;color:#0066cc;font-size:11pt;">alias </span><span style="font-family:consolas;font-size:11pt;">min = minutes; </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:#0066cc;font-size:11pt;">alias </span><span style="font-family:consolas;font-size:11pt;">s = seconds; </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:11pt;"></span></p>
<p style="margin:0;"><span style="font-family:consolas;color:#0066cc;font-size:11pt;"></span></p>
<p style="margin:0;"><span style="font-family:consolas;color:#0066cc;font-size:11pt;">var </span><span style="font-family:consolas;font-size:11pt;">later = DateTime.Now + 2 min 15 s;</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:11pt;"></span></p>
<p><font></font></p>
<p style="margin:0;"><span style="font-family:consolas;color:green;font-size:11pt;">// Schedule is an extension method on DateTime </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:11pt;">later.Schedule </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:11pt;">{ </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:green;font-size:11pt;">// schedule this to run later </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:11pt;">}</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:11pt;"></span></p>
<p><font></font></p>
<p>We can also define our DateTime without assigning its value to a variable.</p>
<p style="margin:0;"><span style="font-family:consolas;font-size:11pt;">(<span style="color:#72830f;">DateTime</span>.<span style="color:#1f497d;">Now</span> + 10 seconds).<span style="color:#1f497d;">Schedule</span> </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:11pt;">{ </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:11pt;">} </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:11pt;">&#160; </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:11pt;">(<span style="color:#72830f;">DateTime</span>.<span style="color:#1f497d;">Now</span> + 10 seconds).<span style="color:#1f497d;">Schedule</span> (<span style="color:#1f497d;">Repeat</span>=10 seconds) </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:11pt;">{ </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:11pt;">}</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:11pt;"></span></p>
<p><font></font></p>
<p>Repeat is an optional parameter of Schedule, defaulting to TimeSpan.Zero, meaning “don’t repeat”.</p>
<h2>Additional Notes</h2>
<p>When more than one operator is valid in a given position, the most specific operator (in terms of its parameter types) is used.&#160; If there’s any ambiguity or overlap remaining, a compiler error is issued.</p>
<p>Unary operators will take precedence over binary operators, but it hasn’t been determined yet what precedence either one will actually have in relation to all of the other operators, or whether this will be specified in the operator definition.</p>
<p>Because of this design for custom operators, I’ve been able to remove things from the language itself and include them as operator definitions in a library.</p>
<h1>Summary</h1>
<p>This article provided some deeper explanation into previously covered material and introduced the syntax for Archetype’s very powerful custom operator declaration syntax.&#160; The next article will cover some special operators built into Archetype, and property path syntax which is something I came up with a while back to safely reference identifiers that would be impervious to both refactoring and obfuscation.</p>
<p>I’m curious to read your feedback on custom operators in particular, so keep the great comments coming!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dvanderboom.wordpress.com/1224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dvanderboom.wordpress.com/1224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dvanderboom.wordpress.com/1224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dvanderboom.wordpress.com/1224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dvanderboom.wordpress.com/1224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dvanderboom.wordpress.com/1224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dvanderboom.wordpress.com/1224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dvanderboom.wordpress.com/1224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dvanderboom.wordpress.com/1224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dvanderboom.wordpress.com/1224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dvanderboom.wordpress.com/1224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dvanderboom.wordpress.com/1224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dvanderboom.wordpress.com/1224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dvanderboom.wordpress.com/1224/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dvanderboom.wordpress.com&amp;blog=2293322&amp;post=1224&amp;subd=dvanderboom&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dvanderboom.wordpress.com/2010/09/27/the-archetype-language-part-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a59dbf3cc9c673540221e35e2c007ec1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Dan</media:title>
		</media:content>
	</item>
		<item>
		<title>Fun with the .NET Micro Framework &amp; the FEZ Mini Robot</title>
		<link>http://dvanderboom.wordpress.com/2010/09/24/fun-with-the-net-micro-framework-the-fez-mini-robot/</link>
		<comments>http://dvanderboom.wordpress.com/2010/09/24/fun-with-the-net-micro-framework-the-fez-mini-robot/#comments</comments>
		<pubDate>Fri, 24 Sep 2010 13:53:29 +0000</pubDate>
		<dc:creator>Dan Vanderboom</dc:creator>
				<category><![CDATA[Micro Framework]]></category>
		<category><![CDATA[Mobile Devices]]></category>
		<category><![CDATA[Robotics]]></category>
		<category><![CDATA[Edge Detection]]></category>
		<category><![CDATA[FEZ Mini]]></category>

		<guid isPermaLink="false">https://dvanderboom.wordpress.com/2010/09/24/fun-with-the-net-micro-framework-the-fez-mini-robot/</guid>
		<description><![CDATA[Microcontrollers can drive anything from watches and tiny MP3 players to industrial control systems and sophisticated robotics, so the opportunity to write C# .NET code on a small and cheap microcontroller is very exciting.&#160; In April 2008 I wrote an article comparing the .NET Micro Framework to Robotics Development Studio (RDS), since they are both [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dvanderboom.wordpress.com&amp;blog=2293322&amp;post=1212&amp;subd=dvanderboom&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Microcontrollers can drive anything from watches and tiny MP3 players to industrial control systems and sophisticated robotics, so the opportunity to write C# .NET code on a small and cheap microcontroller is very exciting.&#160; In April 2008 I wrote <a href="http://dvanderboom.wordpress.com/2008/04/12/net-micro-framework-vs-microsoft-robotics-studio/">an article</a> comparing the .NET Micro Framework to Robotics Development Studio (RDS), since they are both used for driving robotics applications.&#160; RDS requires at least the Compact Framework, which in turn requires Windows CE hardware, which is a good deal more power-hungry and more expensive than tiny microcontrollers that can cost as little as a few dollars each (in bulk, developer kits go for $35 and up).</p>
<p>You may have heard of the popular Linux-based <a href="http://arduino.org/">Arduino</a> microcontroller prototyping boards.&#160; These boards have standard ports for plugging in other boards (called shields) for adding functionality such as motor and servo controllers, sensor input expansions, radio communications, and much more.&#160; These are really cool boards, but being a spoiled .NET developer myself, I haven’t been strongly motivated to program without my beloved Visual Studio tools, and hitting the steep learning curve of Linux development just never happens during the little free time that I have.</p>
<p>Fortunately, there are now some .NET Micro Framework boards that are Arduino board compatible, providing you the comfort of .NET development with the ability to use any of the Arduino-compatible boards that are out there.&#160; <a href="http://www.netduino.com/">Netduino</a> is a popular, low-cost ($34.95), open source option that makes it easy for any .NET developer to get started.&#160; Another great Arduino-compatible option is the <a href="http://www.tinyclr.com/hardware/1/fez-domino/">FEZ Domino</a> board from <a href="http://tinyclr.com/">TinyCLR.com</a>.&#160; It’s more expensive than the Netduino ($74.95), but also more powerful.</p>
<p>I’m also a big fan of Phidgets boards, which are USB and therefore very easily extensible for those unfamiliar with the various microcontroller communication standards.&#160; I wrote an article on <a href="http://dvanderboom.wordpress.com/2008/04/21/phidgets-robotics-programming-in-c/">Phidgets Robotics Programming</a> where I built a pan-tilt camera system controlled by a Wii remote.</p>
<p>Since I enjoy working with robotics applications so much, I decided to try out the <a href="http://www.tinyclr.com/hardware/2/fez-mini/">FEZ Mini Robot Kit</a> for $149.95.&#160; This is a great kit for beginners as it includes all the tools necessary and can be assembled within 15-20 minutes.&#160; It uses the FEZ Mini board (included with the kit) which is an astonishing 1.1” x 1.9” tiny.&#160; When not being used in the robot, it would be ideal for my own custom MP3 player as well.</p>
<p><a href="http://dvanderboom.files.wordpress.com/2010/09/fezmini.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;margin:5px;" title="Fez Mini" border="0" alt="Fez Mini" src="http://dvanderboom.files.wordpress.com/2010/09/fezmini_thumb.png?w=240&#038;h=208" width="240" height="208" /></a></p>
<p>The robot kit instructions are a bit rough: lots of pretty bad spelling and grammar errors, but the assembly instructions are easy enough to follow.&#160; The worst part is the code.&#160; Getting the various sensors, motors, and other things to work properly requires that you download individual C# files from all over their website: the reflective sensor code is found on their reflective sensor product page, and so on.&#160; Stitching this all together and correcting mistakes took me a while.&#160; It’s also evident that the folks writing this code are not fluent C# developers.&#160; By the look and feel of things, they’re probably used to low-level assembly and unmanaged C development.</p>
<p>To save you some pain and discomfort, I’ve gone ahead and rewritten all of the drivers for all the components involved, and have reorganized it from the perspective of someone who’s been writing business applications in C# since .NET 1.0.&#160; I’ve reshaped the API to look and feel a lot more natural to those unfamiliar with the gory details of pulse width modulation (PWM) and similar protocols.&#160; And instead of delivering individual code files scattered across a website, I’ve packaged them all in one place as a Visual Studio 2010 solution, which you can download here:</p>
<p><a href="http://danvanderboom.com/Examples/MiniRobot.zip">FEZ Mini Robot – Visual Studio Solution</a></p>
<p>Have fun developing!</p>
<p>Here’s the robot in action:</p>
<div style="display:inline;float:left;margin:0;padding:0;" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:1650b2ce-d953-4594-af11-72243aca5a6d" class="wlWriterEditableSmartContent">
<div><span style="text-align:center; display: block;"><a href="http://dvanderboom.wordpress.com/2010/09/24/fun-with-the-net-micro-framework-the-fez-mini-robot/"><img src="http://img.youtube.com/vi/kymJlIevdoE/2.jpg" alt="" /></a></span></div>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dvanderboom.wordpress.com/1212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dvanderboom.wordpress.com/1212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dvanderboom.wordpress.com/1212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dvanderboom.wordpress.com/1212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dvanderboom.wordpress.com/1212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dvanderboom.wordpress.com/1212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dvanderboom.wordpress.com/1212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dvanderboom.wordpress.com/1212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dvanderboom.wordpress.com/1212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dvanderboom.wordpress.com/1212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dvanderboom.wordpress.com/1212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dvanderboom.wordpress.com/1212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dvanderboom.wordpress.com/1212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dvanderboom.wordpress.com/1212/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dvanderboom.wordpress.com&amp;blog=2293322&amp;post=1212&amp;subd=dvanderboom&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dvanderboom.wordpress.com/2010/09/24/fun-with-the-net-micro-framework-the-fez-mini-robot/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a59dbf3cc9c673540221e35e2c007ec1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Dan</media:title>
		</media:content>

		<media:content url="http://dvanderboom.files.wordpress.com/2010/09/fezmini_thumb.png" medium="image">
			<media:title type="html">Fez Mini</media:title>
		</media:content>
	</item>
		<item>
		<title>OneNote to Live Writer: Copying Text and Graphics</title>
		<link>http://dvanderboom.wordpress.com/2010/09/18/onenote-to-live-writer-copying-text-and-graphics/</link>
		<comments>http://dvanderboom.wordpress.com/2010/09/18/onenote-to-live-writer-copying-text-and-graphics/#comments</comments>
		<pubDate>Sat, 18 Sep 2010 17:30:09 +0000</pubDate>
		<dc:creator>Dan Vanderboom</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[kludge]]></category>
		<category><![CDATA[Live Writer]]></category>
		<category><![CDATA[Word]]></category>
		<category><![CDATA[workaround]]></category>
		<category><![CDATA[WYSIWYG]]></category>

		<guid isPermaLink="false">https://dvanderboom.wordpress.com/2010/09/18/onenote-to-live-writer-copying-text-and-graphics/</guid>
		<description><![CDATA[Blogging Blues I’ve been using Microsoft Live Writer since shoftly after starting my blog in 2007.&#160; I can’t call it awesome by any stretch of the imagination, but it’s the least painful option that I’ve found so far.&#160; Having to paste images of screenshots of code, and having to change multiple image properties on different [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dvanderboom.wordpress.com&amp;blog=2293322&amp;post=1205&amp;subd=dvanderboom&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h1>Blogging Blues</h1>
<p>I’ve been using Microsoft Live Writer since shoftly after starting my blog in 2007.&#160; I can’t call it awesome by any stretch of the imagination, but it’s the least painful option that I’ve found so far.&#160; Having to paste images of screenshots of code, and having to change multiple image properties on different property pages for every single screenshot I paste into an article is grueling, as is having to dig through menus just to change font size or color.&#160; The newer versions have a nice ribbon control which exposes font settings, but the auto-update feature didn’t work on the version I was using, so I was using an old version for way too long.</p>
<p>Upon upgrading to the 2011 beta of Live Writer, I noticed I could no longer paste an image into a post by using the familiar Control-V.&#160; Just as I was about to give up on Live Writer altogether, someone pointed me to Clipboard Live, which allows you to paste images once again, however by pressing a button on one of the ribbon menu pages instead of the more familiar Control-V paste command.</p>
<p>I work in OneNote quite a bit to take notes, and especially when working on language design for Archetype, since OneNote makes formatting and colorizing code fairly easy.&#160; But getting that formatted text from OneNote to Live Writer is another story.</p>
<p>I decided to experiment a little.&#160; Copying and pasting from OneNote to Live Writer stripped all of the color and formatting away, but going from OneNote to Word actually preserved them.&#160; I remembered seeing some blog publishing settings in Word, so I published my formatted text from there to see how well it worked.&#160; Despite Word’s excellent ability to work with text formatting in general, I was quite disappointed to encounter two major flaws:</p>
<ol>
<li>Ending a line with a carriage return translated into an “end of paragraph” character in Word. Although it displayed fine in Word, on my blog it added extra spacing between “paragraphs”.</li>
<li>Changing paragraph endings with Shift-Enter (whatever that’s called) didn’t work either, because all lines of text so separated had to exist at the same level of indentation.</li>
<li>Lines of text which were very short (30-50 characters) were often word-wrapped and continued on the next line on the web page, though such was not the case in Word.</li>
</ol>
<p>This effectively renders Word useless to me as blogging software, except to take part in the work-around hack I describe below.</p>
<p>There seems to be no such thing yet as WYSIWYG (What You See Is What You Get) between thick client applications and the web, or even between two thick-client applications when it comes to rich text formatting.</p>
<h1>The Workaround</h1>
<p>But worry not, because there is a way, ugly as it is!</p>
<p>First you’ll need to install Clipboard Live, a plugin for Live Writer, which you can <a href="http://gallery.live.com/LiveItemDetail.aspx?li=326740b7-413b-4e0a-bf51-dd49258fd84a">download here</a>.</p>
<p>Here’s what you do:</p>
<ol>
<li>Copy your colorized and/or formatted text from OneNote.</li>
<li>Paste into Microsoft Word.</li>
<li>Copy the same text from Word.</li>
<li>Switch to Live Writer, and in the Insert ribbon menu, click on Clipboard Live.</li>
</ol>
<p>Your text will appear in all its formatted glory.</p>
<p>Images can be pasted using Clipboard Live as well, but they don’t require using Word as an intermediary.</p>
<h1>Example</h1>
<p style="margin:0;"><span style="font-family:consolas;color:#72830f;font-size:11pt;">IStream</span><b><i><span style="font-family:consolas;font-size:11pt;">&lt;</span></i></b><i><span style="font-family:consolas;color:#72830f;font-size:11pt;">TItem</span></i><b><i><span style="font-family:consolas;font-size:11pt;">&gt;</span></i></b><span style="font-family:consolas;font-size:11pt;"> : <span style="color:#72830f;">IStream</span>         </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:11pt;">{        </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#1f497d;font-size:11pt;">Length</span><span style="font-family:consolas;font-size:11pt;"> <span style="color:#72830f;">long</span>;         </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#1f497d;font-size:11pt;">Head</span><span style="font-family:consolas;font-size:11pt;"> <span style="color:#72830f;">StreamItem</span><b><i>&lt;</i></b><i><span style="color:#72830f;">TItem</span><b>&gt;</b></i>;         </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#1f497d;font-size:11pt;">Tail</span><span style="font-family:consolas;font-size:11pt;"> <span style="color:#72830f;">StreamItem</span><b><i>&lt;</i></b><i><span style="color:#72830f;">TItem</span><b>&gt;</b></i>;         </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#1f497d;font-size:11pt;">ChildStreams </span><span style="font-family:consolas;color:#72830f;font-size:11pt;">IStream</span><b><span style="font-family:consolas;font-size:11pt;">&lt;</span></b><i><span style="font-family:consolas;color:#72830f;font-size:11pt;">TItem</span></i><b><span style="font-family:consolas;font-size:11pt;">&gt;</span></b><span style="font-family:consolas;color:#72830f;font-size:11pt;">*</span><span style="font-family:consolas;font-size:11pt;">;        </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#1f497d;font-size:11pt;">ReadingIdleDuration</span><span style="font-family:consolas;font-size:11pt;"> <span style="color:#72830f;">TimeSpan</span>;         </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#1f497d;font-size:11pt;">WritingIdleDuration</span><span style="font-family:consolas;font-size:11pt;"> <span style="color:#72830f;">TimeSpan</span>;         </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:11pt;">&#160;    </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#953734;font-size:11pt;">Append<b>(</b></span><span style="font-family:consolas;font-size:11pt;">Item <i><span style="color:#72830f;">TItem</span></i><b><span style="color:#953734;">)</span></b>; <span style="color:green;">// make Item the new Tail</span>         </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#953734;font-size:11pt;">Inject<b>(</b></span><span style="font-family:consolas;font-size:11pt;">Item <i><span style="color:#72830f;">TItem</span></i><b><span style="color:#953734;">)</span></b>; <span style="color:green;">// make Item the new Head</span>         </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#953734;font-size:11pt;">Inject<b>(</b></span><span style="font-family:consolas;font-size:11pt;">Item <i><span style="color:#72830f;">TItem</span></i>, Index <span style="color:#72830f;">int</span><b><span style="color:#953734;">)</span></b>; <span style="color:green;">// insert in the middle; indexed from the front</span>         </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:11pt;">&#160;    </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#953734;font-size:11pt;">Peek<b>(</b></span><span style="font-family:consolas;font-size:11pt;">Index <span style="color:#72830f;">int</span><b><span style="color:#953734;">)</span> </b><i><span style="color:#72830f;">TItem</span></i>;         </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#953734;font-size:11pt;">Extract<b>(</b></span><span style="font-family:consolas;font-size:11pt;">Index <span style="color:#72830f;">int</span><b><span style="color:#953734;">)</span></b> <i><span style="color:#72830f;">TItem</span></i>;         </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#953734;font-size:11pt;">Extract<b>(</b></span><span style="font-family:consolas;font-size:11pt;">Index <span style="color:#72830f;">int</span><span style="color:blue;">, </span>Count<span style="color:blue;"> </span><span style="color:#72830f;">int</span><b><span style="color:#953734;">)</span></b> <i><span style="color:#72830f;">TItem</span></i>;         </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#953734;font-size:11pt;">Read<b>(</b></span><span style="font-family:consolas;font-size:11pt;">Count <span style="color:#72830f;">int</span><b><span style="color:#953734;">)</span></b> <i><span style="color:#72830f;">TItem</span></i><span style="color:#72830f;">*</span>; <span style="color:green;">// extract from the front</span>         </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#953734;font-size:11pt;">Read<b>()</b></span><span style="font-family:consolas;font-size:11pt;"> <i><span style="color:#72830f;">TItem</span></i>; <span style="color:green;">// extract the Head</span>         </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:11pt;">}        </span></p>
<p>&#160;</p>
<p>Now the code appearing in my articles will be text instead of images. Much better.</p>
<p>Happy blogging!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dvanderboom.wordpress.com/1205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dvanderboom.wordpress.com/1205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dvanderboom.wordpress.com/1205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dvanderboom.wordpress.com/1205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dvanderboom.wordpress.com/1205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dvanderboom.wordpress.com/1205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dvanderboom.wordpress.com/1205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dvanderboom.wordpress.com/1205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dvanderboom.wordpress.com/1205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dvanderboom.wordpress.com/1205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dvanderboom.wordpress.com/1205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dvanderboom.wordpress.com/1205/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dvanderboom.wordpress.com/1205/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dvanderboom.wordpress.com/1205/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dvanderboom.wordpress.com&amp;blog=2293322&amp;post=1205&amp;subd=dvanderboom&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dvanderboom.wordpress.com/2010/09/18/onenote-to-live-writer-copying-text-and-graphics/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a59dbf3cc9c673540221e35e2c007ec1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Dan</media:title>
		</media:content>
	</item>
		<item>
		<title>Locate Project Item in Solution Explorer &#8211; Improved</title>
		<link>http://dvanderboom.wordpress.com/2010/08/24/locate-project-item-in-solution-explorer-improved/</link>
		<comments>http://dvanderboom.wordpress.com/2010/08/24/locate-project-item-in-solution-explorer-improved/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 23:48:39 +0000</pubDate>
		<dc:creator>Dan Vanderboom</dc:creator>
				<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio Extensibility]]></category>

		<guid isPermaLink="false">https://dvanderboom.wordpress.com/2010/08/24/locate-project-item-in-solution-explorer-improved/</guid>
		<description><![CDATA[Way back in March 2008, I wrote an article sharing a macro to locate the current document in Solution Explorer without having to have the annoying setting “Track current item in Solution Explorer” always turned on.&#160; I map this to my F1 key (I get my help online) and all is good in the world. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dvanderboom.wordpress.com&amp;blog=2293322&amp;post=1191&amp;subd=dvanderboom&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Way back in March 2008, I wrote <a href="http://dvanderboom.wordpress.com/2008/03/21/visual-studio-macro-track-item-in-solution-explorer-on-demand/">an article</a> sharing a macro to locate the current document in Solution Explorer without having to have the annoying setting “Track current item in Solution Explorer” always turned on.&#160; I map this to my F1 key (I get my help online) and all is good in the world.</p>
<p>When I wrote this macro, I remember reading some documentation for VS2003 or VS2005 saying that it wasn’t possible to update this “Track current item” setting programmatically.&#160; This has changed, and in VS2008 and VS2010 these can indeed be triggered programmatically.&#160; Rob posted the much abbreviated code in one of the comments.</p>
<pre class="code"><font size="2"><span style="color:blue;">Public Sub </span>TrackProjectItem()
    DTE.ExecuteCommand(<span style="color:#a31515;">&quot;View.TrackActivityinSolutionExplorer&quot;</span>, <span style="color:blue;">True</span>)
    DTE.ExecuteCommand(<span style="color:#a31515;">&quot;View.TrackActivityinSolutionExplorer&quot;</span>, <span style="color:blue;">False</span>)
    DTE.ExecuteCommand(<span style="color:#a31515;">&quot;View.SolutionExplorer&quot;</span>)
<span style="color:blue;">End Sub</span></font></pre>
<p>Thanks to Rob and all the others who left comments on that article.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dvanderboom.wordpress.com/1191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dvanderboom.wordpress.com/1191/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dvanderboom.wordpress.com/1191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dvanderboom.wordpress.com/1191/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dvanderboom.wordpress.com/1191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dvanderboom.wordpress.com/1191/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dvanderboom.wordpress.com/1191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dvanderboom.wordpress.com/1191/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dvanderboom.wordpress.com/1191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dvanderboom.wordpress.com/1191/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dvanderboom.wordpress.com/1191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dvanderboom.wordpress.com/1191/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dvanderboom.wordpress.com/1191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dvanderboom.wordpress.com/1191/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dvanderboom.wordpress.com&amp;blog=2293322&amp;post=1191&amp;subd=dvanderboom&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dvanderboom.wordpress.com/2010/08/24/locate-project-item-in-solution-explorer-improved/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a59dbf3cc9c673540221e35e2c007ec1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Dan</media:title>
		</media:content>
	</item>
		<item>
		<title>Windows Phone 7 &#8211; Platform</title>
		<link>http://dvanderboom.wordpress.com/2010/08/20/windows-phone-7-platform/</link>
		<comments>http://dvanderboom.wordpress.com/2010/08/20/windows-phone-7-platform/#comments</comments>
		<pubDate>Fri, 20 Aug 2010 16:26:31 +0000</pubDate>
		<dc:creator>Dan Vanderboom</dc:creator>
				<category><![CDATA[Compact Framework]]></category>
		<category><![CDATA[Development Environment]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[PDC10]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Windows Phone 7]]></category>

		<guid isPermaLink="false">https://dvanderboom.wordpress.com/2010/08/20/windows-phone-7-platform/</guid>
		<description><![CDATA[A Scorching Hot Market The smart phone market is the hottest market in the computer world, based on unbelievable growth.&#160; It surpasses the desktop “personal computer”, the PC, in finding its way into the pockets and hands of consumers who might not otherwise buy a larger computer; and in doing so, has established itself as [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dvanderboom.wordpress.com&amp;blog=2293322&amp;post=1172&amp;subd=dvanderboom&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h1>A Scorching Hot Market</h1>
<p>The smart phone market is <strong>the</strong> hottest market in the computer world, based on unbelievable growth.&#160; It surpasses the desktop “personal computer”, the PC, in finding its way into the pockets and hands of consumers who might not otherwise buy a larger computer; and in doing so, has established itself as the ultimate personal computer.</p>
<p>It’s like filling a ditch with large boulders until no more will fit, and then filling the remaining space with smaller debris.&#160; Smart phones, and all cell phones to an even larger extent, are that debris.&#160; And in the future, we’ll fill what space is left with granules of sand.</p>
<p>Looking at the Windows Phone from every angle, from features to development patterns, from its role in the market to its potential in peer-to-peer and cloud computing scenarios, overall I have to admit I am very impressed and quite excited.&#160; I also have some harsh criticism; and because of my excitement and optimism, strong hope that these concerns will be addressed as matters of great urgency.&#160; If Microsoft is serious about competing with Android and iPhone, they’ll have to invest heavily in doing what they’ve been so good at: giving developers what they want.</p>
<h1>The Consumer Experience: Entertainment</h1>
<p>Microsoft’s primary focus is on the consumer experience, and I think that focus is aptly set.&#160; But that’s the goal, and supporting developers is the means to accomplish that.&#160; You can’t separate one from the other.&#160; However, you must always prioritize; and while features like background thread execution has many solid business cases, it has to wait for consumer experience features to be refined and reliability guarantees to be worked out.</p>
<p>What this means is that Microsoft is paying much more attention to Design with a capital D.&#160; They’re taking tight control over the operating system’s shell UI in order to provide consistency across devices and carriers –taking a lesson from Android, which is painfully fragmented—and have announced some exciting new controls such as <a href="http://www.jeff.wilcox.name/2010/08/tiltcontentcontrol/">TiltContentControl</a>, <a href="http://www.jeff.wilcox.name/2010/08/looking-ahead-at-panorama-and-pivot/">Panorama and Pivot</a>.</p>
<p>By focusing on the consumer, Microsoft is in essence really just reminding themselves <em>not </em>to think like a company for enterprise customers.&#160; Let’s face it: Microsoft is first and foremost an enterprise products company.&#160; But by integrating XNA and Xbox Live into the Windows Phone platform, they’re creating a phone with a ton of gamer&#8211;and therefore non-enterprise&#8211;buzz.</p>
<p>Entertainment is Windows Phone’s number one priority.&#160; Don’t worry: the enterprise capabilities you want will come: as services in the OS or as apps that Microsoft and third-parties publish.&#160; But those enterprise scenarios will be even more valuable as the entertaining nature of the device puts it into millions and millions of hands.</p>
<h1>Introducing Funderbolt Games</h1>
<p>To take advantage of this explosion of interest in smart phones and gaming, and having developed mobile device software for the past five years, I’ve recently started a company called Funderbolt Games.&#160; We’re developing games (initially targeting Windows Phone and Android) for children from about one to five years old, and will eventually publish casual games for adults as well.</p>
<p>I’ve been working with a fantastic artist, Shannon Lazcano, in building our first Silverlight game for Windows Phone.&#160; It will be a simple adventure game with lots of places and activities to explore as a family of mice interact with a rabbit, a dog, a frog, some fireflies, dragonflies, and more.&#160; Based on heaps of research of kids games on the iPhone, and having watched young children play most of the games in the App Store over the past two years, the games we’re creating are guaranteed to keep young kids entertained for dozens of hours.</p>
<p>In the next few weeks, I’ll publish more details and some screen shots.&#160; The target for our first title is October 27th (<a href="http://microsoftpdc.com/">PDC 2010</a>).</p>
<h1>The Shell User Interface</h1>
<p>The Android operating system’s openness has become one of its weaknesses.&#160; Shell UI replacements like Motorola’s Blur and HTC’s Sense are modifications of the operating system itself.&#160; When a new version of Android is released, these manufacturer’s take their sweet time making the necessary adaptations with their custom front ends, and customers end up several versions behind&#8211;much to their chagrin.</p>
<p>It would be much better to write shell replacements as loosely coupled applications or services, and design the OS to make this easy.&#160; I <em>completely support</em> companies innovating in the shell UI space!&#160; We need to encourage more of this, not to lock them out.&#160; These experiments advance the state of the art in user experience design and provide users with more options.&#160; If anything, the only rule coming from the platform should be that nobody shall prevent users from changing shells.</p>
<p>Because the smartphone is such a personal device, it makes sense that different modes of interaction might rely in part on personal taste.&#160; Some users are simply more technical than others (developers), or need to be shielded from content as well as messing things up (children), and there are people with various disabilities to consider as well.&#160; One UI to rule them all can’t possibly be the right approach.</p>
<p>Despite this, it’s really not a shock then that Windows Phone 7 will have a locked down shell UI in its first and probably second versions.&#160; Flexibility and choice sound good in theory, but in reality can create quite a mess when done without careful planning, and the Windows Phone team has a substantial challenge in figuring out how to open things up without producing or encouraging many of the same problems they see elsewhere.&#160; I’ll be eagerly watching this drama unfold over the first year that Windows Phones are in the wild.</p>
<p>That being said, I have to admit I’m not a fan of the Windows Phone 7 Start Menu.&#160; It feels disappointingly flat and imbalanced, wasting a good bit of screen real estate to the right of the tile buttons.&#160; I’m glad they attempted something different, but I think they have a long way to go toward making it that sexy at-a-glance dashboard that would inspire any onlooker to go wide-eyed with envy.</p>
<p>The demo videos of Office applications are likewise drab.&#160; Don’t get me wrong: the fonts, as everyone is quick to point out, are beautiful, and we all love the parallax scrolling effects.&#160; But we’ve come to expect and appreciate some chrome: those color gradients and rounded corners and other interesting geometrical shapes that help to define a sense of visual structure.&#160; As noted by several tweeple, it sometimes looks like a hearkening back to ye olden days of text-only displays.&#160; More beautiful text, but nothing beyond that to suggest that we’ve evolved beyond the printing press.</p>
<p>The one line I keep hearing over and over again is that Microsoft is serious about keeping an aggressive development cycle, revving Windows Phone quickly to catch up to their competitors.&#160; The sting of Windows Mobile’s abysmal failure is still fresh enough to serve as an excellent motivator to make the right decisions and investments, and do well by consumers this time.</p>
<h1>A Managed World</h1>
<p>There are a few brilliant features of Windows Phone 7.&#160; One of them is the requirement for a hardware “Navigate Back” button.&#160; As a Windows Mobile developer working within the constraints of small screens, I never had enough room, and sacrificing space on nearly every screen for a back button was painful.&#160; Not only did you have to give up space, you also had to make it fit your application’s style.&#160; Windows Forms with the Compact Framework (Rest In Peace) was not fun to work with.</p>
<p>We’re entering a new era.&#160; The Windows Phone will only allow third party applications to be written in managed code.&#160; <em>I couldn’t imagine any better news!</em>&#160; Why?&#160; We don’t have to concern ourselves with PInvoke or trying to interoperate with COM objects.&#160; We also don’t have to worry about memory leaks or buffer overruns: the garbage collection and strong-type system in the CLR takes care of these.&#160; Not only do I not have to worry about these problems as a .NET developer, I also don’t have to worry about my app being negatively impacted by an unmanaged app on the same device, and I don’t have to worry about these problems emerging on my own personal phone despite what apps are installed.</p>
<p>I’ve been plagued by my iPhone lately because of unstable apps, especially since I upgraded to iOS 4.x.&#160; I can’t tell you how many times that an app dies because it’s just so damn frequent, and my frustration level is rising.&#160; The quality of Apple’s own apps are just as bad: not only does iTunes sync not work correctly on a PC, but I can’t listen to my podcasts through the iPod app without finding that I can’t play a podcast I downloaded (but I can stream it), or that playback works for a while before it starts to stutter the audio and locks up my whole phone.&#160; These are signs of a fragile platform and an immature, unmanaged execution environment.</p>
<p>I used to be a technology apologist, but I find myself increasingly critical when it relates to my smart phone.&#160; I demand reliability.&#160; Forcing applications to use managed code is an excellent way to do that.&#160; Once your code is wrapped in such a layer, the wrapper itself can evolve to provide continuously improving reliability and performance.</p>
<p>If you have significant investments in unmanaged code for Windows Mobile devices, it’s too late for sympathy.&#160; The .NET platform is over a decade old, and managed execution environments have clearly been the future path for a long time now.&#160; You’ve had your chance to convert your code many times over.&#160; If you haven’t done so yet and you still think your old algorithms and workflows are valuable, it’s time to get on board and start porting.&#160; Pressuring Microsoft to open up Windows Phone to unmanaged code is a recipe for continued instability and ultimately disaster for the platform.</p>
<p>In fact, I would consider the Windows Phone 7 OS to be one step closer to an OS like <a href="http://research.microsoft.com/en-us/projects/singularity/">Singularity</a>, which is a research operating system written in managed code.&#160; As some pundits have predicted or recommended that Apple extrapolate iOS to the desktop and eventually drop OSX, we might see a merge of desktop and mobile OS technologies at Microsoft, or at least a borrowing of ideas, to move us closer to a Singularity-like OS whose purpose is improving the reliability of personal computing.</p>
<h1>A Bazillion Useless Apps</h1>
<p>There are a ton of crappy apps in the Apple App Store and the Android Marketplace.&#160; I’d say it’s a pretty heavy majority.&#160; Perhaps they shouldn’t be boasting how many apps they have, as if quality and quantity were somehow related.&#160; I have a feeling that Microsoft’s much stronger developer platform will produce a higher signal-to-noise ratio in their own marketplace, and I’ll explain why.</p>
<p>Web developers spend their time attempting cross-browser and cross-version support, Apple developers spend their time tracking down bugs that prevents even basic functionality from working well, and Android developers spend their time trying to support a fragmented collection of phone form factors, screen sizes, and graphics processors.&#160; I suspect Microsoft developers will find a sweet spot in being able to spend the majority of their time building the actual features that have business or entertainment value.</p>
<p>Why?&#160; There are only two supported screen resolutions for Windows Phone 7, and the nice list of <a href="http://en.wikipedia.org/wiki/Windows_Phone_7#Hardware_requirements">hardware requirements</a> give developers a strong common foundation they can count on (while still leaving room for innovation above and beyond that), providing the same kind of consistent platform that Apple developers enjoy.&#160; In addition, the operating system will be updated over the air, so all connected devices will run the same version.&#160; Without OS modifications like shell UI replacements that can delay that version’s readiness, there’s greater consistency and therefore less friction.</p>
<p>These factors don’t account for problems that can still result from sloppy programming and low standards, but fewer obstacles will remain to building high quality applications.&#160; A rich ecosystem of Silverlight and XNA control libraries, frameworks, and tooling already exists.&#160; With incredible debugging tools that further help to improve quality, my bet is that we’ll see much more focus on valuable feature development.</p>
<h1>PDC 2010</h1>
<p>I’m one of the lucky 1000 developers going to the <a href="http://www.microsoftpdc.com/">Professional Developer Conference</a> this year at Microsoft’s Campus in Redmond, WA from October 27-29.&#160; I’m looking forward to learning more about the platform and hope to get my hands on one.&#160; I’m also working on two Windows Azure projects, a big one for a consulting project and a personal one which will be accessed through a Windows Phone app, so I’m excited to catch some of the Azure sessions and meet their team as well.</p>
<p>If you’re also headed to PDC and are interested in meeting up while in Redmond/Seattle, leave me a comment! I’m always interested to hear and share development and technology ideas.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dvanderboom.wordpress.com/1172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dvanderboom.wordpress.com/1172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dvanderboom.wordpress.com/1172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dvanderboom.wordpress.com/1172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dvanderboom.wordpress.com/1172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dvanderboom.wordpress.com/1172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dvanderboom.wordpress.com/1172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dvanderboom.wordpress.com/1172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dvanderboom.wordpress.com/1172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dvanderboom.wordpress.com/1172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dvanderboom.wordpress.com/1172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dvanderboom.wordpress.com/1172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dvanderboom.wordpress.com/1172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dvanderboom.wordpress.com/1172/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dvanderboom.wordpress.com&amp;blog=2293322&amp;post=1172&amp;subd=dvanderboom&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dvanderboom.wordpress.com/2010/08/20/windows-phone-7-platform/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a59dbf3cc9c673540221e35e2c007ec1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Dan</media:title>
		</media:content>
	</item>
		<item>
		<title>Language Design: Complexity, Extensibility, and Intention</title>
		<link>http://dvanderboom.wordpress.com/2010/06/14/language-design-complexity-extensibility-and-intention/</link>
		<comments>http://dvanderboom.wordpress.com/2010/06/14/language-design-complexity-extensibility-and-intention/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 02:22:29 +0000</pubDate>
		<dc:creator>Dan Vanderboom</dc:creator>
				<category><![CDATA[Archetype Language]]></category>
		<category><![CDATA[Composability]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Language Extensions]]></category>
		<category><![CDATA[Language Innovation]]></category>
		<category><![CDATA[Linguistics]]></category>
		<category><![CDATA[Metaprogramming]]></category>
		<category><![CDATA[Object Oriented Design]]></category>
		<category><![CDATA[Software Architecture]]></category>

		<guid isPermaLink="false">https://dvanderboom.wordpress.com/2010/06/14/the-human-factor-complexity-extensibility-and-intention/</guid>
		<description><![CDATA[Introduction The object-oriented approach to software is great, and that greatness draws from the power of extensibility.&#160; That we can create our own types, our own abstractions, has opened up worlds of possibilities.&#160; System design is largely focused on this element of development: observing and repeating object-oriented patterns, analyzing their qualities, and adding to our [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dvanderboom.wordpress.com&amp;blog=2293322&amp;post=1086&amp;subd=dvanderboom&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h1>Introduction</h1>
<p>The object-oriented approach to software is great, and that greatness draws from the power of extensibility.&#160; That we can create our own types, our own abstractions, has opened up <em>worlds</em> of possibilities.&#160; System design is largely focused on this element of development: observing and repeating object-oriented patterns, analyzing their qualities, and adding to our mental toolbox the ones that serve us best.&#160; We also focus on collecting libraries and controls because they encapsulate the patterns we need.</p>
<p>This article explores computer languages as a human-machine interface, the purpose and efficacy of languages, complexity of syntactic structure, and the connection between human and computer languages.&#160; The <a href="http://dvanderboom.wordpress.com/2010/04/26/new-language-code-named-archetype/">Archetype</a> project is an on-going effort to incorporate these ideas into language design.&#160; In the same way that some furniture is designed ergonomically, Archetype is an attempt to design a powerful programming language with an ergonomic focus; in other words, with the human element always in mind.</p>
<h1>Programming Language as Human-Machine Interface</h1>
<p>A programming language is the interface between the human mind and executable code.&#160; The point isn’t to turn human programmers into pure mathematical or machine thinkers, but to leverage the talent that people are born with to manipulate abstract symbols in language.&#160; There is an elite class of computer language experts who have trained themselves to think in terms of purely functional approaches, low-level assembly instructions, or regular, monotonous expression structures—and this is necessary for researchers pushing themselves to understand ever more—but for the every day developer, a more practical approach is required.</p>
<p>Archetype is a series of experiments to build the perfect bridge between the human mind and synthetic computation.&#160; As such, it is based as much as possible on a small core of extensible syntax and maintains a uniformity of expression within each facet of syntax that the human mind can easily keep separate.&#160; At the same time, it honors syntactic variety and is being designed to shift us closer to a balance where all of the elements, blocks, clauses and operation types in a language can be extended or modified equally.&#160; These represent the two most important design tenets of Archetype: the intuitive, natural connection to the human mind, and the maximization of its expressive power.</p>
<p>These forces often seem at odds with each other—at first glance seemingly impossible to resolve—and yet experience has shown that the languages we use are limited in ways we’re often surprised by, indicating that processes such as <a href="http://www.bookrags.com/tandf/analogical-extension-tf/">analogical extension</a> are at work in our minds but not fully leveraged by those languages.</p>
<h1>Syntactic Complexity &amp; Extensibility</h1>
<p>Most of a programming language’s syntax is highly static, and just a few areas (such as types, members, and sometimes operators) can be extended.&#160; <a href="http://en.wikipedia.org/wiki/Lisp_%28programming_language%29">Lisp</a> is the most famous example of a highly extensible language with support for <a href="http://en.wikipedia.org/wiki/Macro_%28computer_science%29#Lisp_macros">macros</a> which allow the developer to manipulate code as if it were data, and to extend the language to encode data in the form of <a href="http://en.wikipedia.org/wiki/Finite-state_machine">state machines</a>.&#160; The highly regular, parenthesized syntax is very simple to parse and therefore to extend… so long as you don’t deviate from the parenthesized form.&#160; Therefore Lisp gets away with powerful extensibility at the cost of artificially limiting its structural syntax.</p>
<p>In Lisp we write <strong>(+ 4 5)</strong> to add two numbers, or <strong>(foo 1 2)</strong> to call a function with two parameters.&#160; Very uniform.&#160; In C we write <strong>4 + 5</strong> because the infix operator is what we grew up seeing in school, and we vary the syntax for calling the function <strong>foo(1, 2)</strong> to provide visual cues to the viewer’s brain that the function is qualitatively something different from a basic math operation, and that its name is somehow different from its parameters.</p>
<p>Think about syntax features as visual manifestations of the abstract logical concepts that provide the foundation for all algorithmic expression.&#160; A rich set of fundamental operations can be obscured by a monotony of syntax or confused by a poorly chosen syntactic style.&#160; Archetype involves a lot of research in finding the best features across many existing languages, and exploring the limits, benefits, problems, and other details of each feature and syntactic representation of it.</p>
<p>Syntactic complexity provides greater flexibility, and wider channels with which to convey intent.&#160; This is why people color code file folders and add graphic icons to public signage.&#160; More cues enable faster recognition.&#160; It’s possible to push complexity too far, of course, but we often underestimate what our minds are capable of when augmented by a system of external cues which is carefully designed and supported by good tools.</p>
<p>Imagine if your natural spoken language followed such simple and regular rules as Lisp: although everyone would learn to read and write easily, conversation would be monotonous.&#160; Extend this to semantics, for example with a constructed spoken language like <a href="http://www.lojban.org/tiki/Lojban">Lojban</a> which is logically pure and provably unambiguous, and it becomes obvious that our human minds aren’t well suited to communicating this way.</p>
<p>Now consider a language like C with its 15 levels of <a href="http://en.wikipedia.org/wiki/Order_of_operations#Programming_languages">operator precedence</a> which were designed to match programmers’ expectations (although the authors admitted to getting some of this “wrong”, which further proves the point).&#160; This language has given rise to very popular derivatives (C++, C#, Java) and are all easily learned, despite their syntactic complexity.</p>
<p>Natural languages and old world cities have grown with civilization organically, creating winding roads and wonderful linguistic variation.&#160; These complicated structures have been etched into our collective unconscious, stirring within us and giving rise to awareness, thought, and creativity.&#160; Although computers are excellent at processing regular, predictable patterns, it’s the complex interplay of external forces and inner voices that we’re most comfortable with.</p>
<h1>Risk, Challenge &amp; Opportunity</h1>
<p>There are always trade-offs.&#160; By focusing almost all extensibility in one or two small parts of a language, semantic analysis and code improvement optimizations are easier to develop and faster to execute.&#160; Making other syntactical constructs extensible, if one isn’t careful, can create complexity that quickly spirals out of control, resulting in unverifiable, unpredictable and unsafe logic.</p>
<p>The way this is being managed in Archetype so far isn’t to allow any piece of the syntax tree to be modified, but rather to design regions of syntax with extensibility points built-in.&#160; Outputting C# code as an intermediary (for now) lays a lot of burden on the C# compiler to ensure safety.&#160; It’s also possible to mitigate more computationally expensive semantic analysis and code generation by taking advantage of both multicore and cloud-based processing.&#160; What helps keep things in check is that potential extensibility points are being considered in the context of specific code scenarios and desired outcomes, based on over 25 years of real-world experience, not a disconnected sense of language purity or design ideals.</p>
<p>Creating a language that caters to the irregular texture of thought, while supporting a system of extensions that are both useful and safe, is not a trivial undertaking, but at the same time holds the greatest potential.&#160; The more that computers can accommodate people instead of forcing people to make the effort to cater to machines, the better.&#160; At least to the extent that it enables us to specify our designs unambiguously, which is somewhat unnatural for the human mind and will always require some training.</p>
<h1>Summary</h1>
<p>So much of the code we write is driven by a set of rituals that, while they achieve their purpose, often beg to be abstracted further away.&#160; Even when good object models exist, they often require intricate or tedious participation to apply (see <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx">INotifyPropertyChanged</a>).&#160; Having the ability to incorporate the most common and solid of those patterns into language syntax (or extensions which <em>appear</em> to modify the language) is the ultimate mechanism for abstraction, and goes furthest in minimizing development effort.&#160; By obviating the need to write convoluted yet routine boilerplate code, Archetype aims to filter out the noise and bring one’s intent more clearly into focus.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dvanderboom.wordpress.com/1086/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dvanderboom.wordpress.com/1086/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dvanderboom.wordpress.com/1086/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dvanderboom.wordpress.com/1086/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dvanderboom.wordpress.com/1086/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dvanderboom.wordpress.com/1086/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dvanderboom.wordpress.com/1086/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dvanderboom.wordpress.com/1086/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dvanderboom.wordpress.com/1086/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dvanderboom.wordpress.com/1086/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dvanderboom.wordpress.com/1086/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dvanderboom.wordpress.com/1086/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dvanderboom.wordpress.com/1086/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dvanderboom.wordpress.com/1086/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dvanderboom.wordpress.com&amp;blog=2293322&amp;post=1086&amp;subd=dvanderboom&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dvanderboom.wordpress.com/2010/06/14/language-design-complexity-extensibility-and-intention/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a59dbf3cc9c673540221e35e2c007ec1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Dan</media:title>
		</media:content>
	</item>
		<item>
		<title>The Archetype Language (Part 6)</title>
		<link>http://dvanderboom.wordpress.com/2010/06/14/the-archetype-language-part-6/</link>
		<comments>http://dvanderboom.wordpress.com/2010/06/14/the-archetype-language-part-6/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 16:39:51 +0000</pubDate>
		<dc:creator>Dan Vanderboom</dc:creator>
				<category><![CDATA[Archetype Language]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Language Innovation]]></category>

		<guid isPermaLink="false">https://dvanderboom.wordpress.com/2010/06/14/the-archetype-language-part-6/</guid>
		<description><![CDATA[Overview This is part of a continuing series of articles about a new .NET language under development called Archetype.&#160; Archetype is a C-style (curly brace) functional, object-oriented (class-based), metaprogramming-capable language with features and syntax borrowed from many languages, as well as some new constructs.&#160; A major design goal is to succinctly and elegantly implement common [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dvanderboom.wordpress.com&amp;blog=2293322&amp;post=1077&amp;subd=dvanderboom&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong><font color="#800000">Overview</font></strong></p>
<p><font color="#800000">This is part of a continuing series of articles about a new .NET language under development called <strong>Archetype</strong>.&#160; Archetype is a C-style (curly brace) functional, object-oriented (class-based), metaprogramming-capable language with features and syntax borrowed from many languages, as well as some new constructs.&#160; A major design goal is to succinctly and elegantly implement common patterns that normally require a lot of boilerplate code which can be difficult, error-prone, or just plain onerous to write.</font></p>
<p><font color="#800000">You can follow the news and progress on the Archetype compiler on twitter<font color="#800000"> </font><a href="http://twitter.com/archetypelang"><font color="#800000">@archetypelang</font></a>.</font></p>
<p><font color="#800000">Links to the individual articles:</font></p>
<blockquote><p><a href="http://dvanderboom.wordpress.com/2010/04/26/new-language-code-named-archetype/"><font color="#800000">Part 1</font></a><font color="#800000"> – Properties and fields, function syntax, the me keyword</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/04/27/the-archetype-language-part-2/"><font color="#800000">Part 2</font></a><font color="#800000"> – Start function, named and anonymous delegates, delegate duck typing, bindable properties, composite bindings, binding expressions, namespace imports, string concatenation</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/04/27/the-archetype-language-part-3/"><font color="#800000">Part 3</font></a><font color="#800000"> – Exception handling, local variable definition, namespace imports, aliases, iteration (loop, fork-join, while, unless), calling functions and delegates asynchronously, messages</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/05/08/the-archetype-language-part-4/"><font color="#800000">Part 4</font></a><font color="#800000"> – Conditional selection (<strong>if</strong>), pattern matching, regular expression literals, agents, classes and traits</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/05/24/the-archetype-language-part-5/"><font color="#800000">Part 5</font></a><font color="#800000"> – Type extensions, custom control structures</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/06/14/the-archetype-language-part-6/"><font color="#800000">Part 6</font></a><font color="#800000"> – If expressions, enumerations, nullable types, tuples, streams, list comprehensions, subrange types, type constraint expressions</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/09/27/the-archetype-language-part-7/"><font color="#800000">Part 7</font></a><font color="#800000"><font color="#c0504d"><font color="#c0504d"> –</font> </font><font color="#800000">Semantic</font> density, operator overloading, custom operators</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/10/01/the-archetype-language-part-8/"><font color="#800000">Part 8</font></a><font color="#800000"> – Constructors, declarative Archetype: the initializer body</font></p>
<p><a href="http://dvanderboom.wordpress.com/2010/10/03/the-archetype-language-part-9/"><font color="#800000">Part 9</font></a><font color="#800000"> – Params &amp; fluent syntax, safe navigation operator, null coalescing operators</font></p>
</blockquote>
<p><font color="#800000">Conceptual articles about language design and development tools:</font></p>
<blockquote><p><a href="http://dvanderboom.wordpress.com/2010/06/14/language-design-complexity-extensibility-and-intention/"><font color="#800000">Language Design: Complexity, Extensibility, and Intention</font></a></p>
<p><a href="http://dvanderboom.wordpress.com/2010/05/31/reimagining-the-integrated-development-environment/"><font color="#800000">Reimagining the IDE</font></a></p>
<p><a href="http://dvanderboom.wordpress.com/2009/09/07/better-tool-support-for-net/"><font color="#800000">Better Tool Support for .NET</font></a></p>
</blockquote>
<h1>If Expressions</h1>
<p>In Archetype, an <strong>if expression</strong> can be provided for any value.&#160; The expression variant of the if statement, instead of taking embedded statement clauses, takes value expressions for its &quot;consequence&quot; clauses.</p>
<p>The <strong>if expression</strong> serves the same purpose as the ternary conditional operator in C#:</p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">TextField.<span style="color:#1f497d;">PasswordChar</span> = DisplayStar ? &#8216;*&#8217; <span style="color:blue;">else</span> &#8216; &#8216;;</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p><font></font></p>
<h1>Enumerations</h1>
<p>Enumerations are represented syntactically like lists in Archetype, using the square brackets to enclose values.&#160; The idea is that an enumeration type is simply a list of possible values.</p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">enum</span><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">RainbowColor</span> [ Red, Orange, Yellow, Green, Blue, Indigo, Violet ];</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p><font></font></p>
<p>Enumerations are often formatted to display one value on each line.&#160; The following example demonstrates this, and defines a variable of the enumeration’s type.</p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">enum</span><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">RainbowColor</span> </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">[ </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;">Red, </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;">Orange, </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;">Yellow, </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;">Green, </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;">Blue, </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;">Indigo, </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;">Violet </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">]; </span></p>
<h4>Anonymous Enumeration Types</h4>
<p>It normally makes sense for an enumeration type to be named so it can be referenced and used elsewhere.&#160; But in cases where an enumeration is only needed privately within a single class or method, an anonymous enumeration type can be defined this way:</p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">ForegroundColor <span style="color:blue;">enum</span> [ Black, Gray, DarkBlue ]; </span></p>
<h4>Enumeration Assignment</h4>
<p>Regardless of whether you’re working with named or anonymous enumerations, assignment is the same.&#160; The enumeration type is not used in the assignment, which works well with anonymous enumerations since they don’t have a discoverable name.</p>
<p style="margin:0;"><span style="font-family:consolas;color:green;font-size:10pt;">// no need for an enumeration name </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:green;font-size:10pt;">// so it also works great with anonymous enumeration types </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">BackgroundColor = Green;</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p><font></font></p>
<p>Language services (Intellisense) can still inform the user of the possible values after the equals sign and space are entered.</p>
<h1>Nullable Types</h1>
<p>The nullable type operator converts a type T to Nullable&lt;T&gt;, the same as in C#.&#160; Consider the following examples of normal and bindable nullable properties, and a local variable with an initializer.</p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">Age <span style="color:blue;">int?</span>; </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">HighScore <span style="color:#cc9900;">bindable</span><span style="color:blue;"> int?</span>; </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">var</span><span style="font-family:consolas;font-size:10pt;"> Age <span style="color:blue;">int?</span> = <span style="color:blue;">null</span>;</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p><font></font></p>
<p>Additionally, we can define a local variable and infer its type from an assignment, using the nullable type operator to force type inference to use a nullable type.</p>
<p style="margin:0;"><span style="font-family:consolas;color:green;font-size:10pt;">// give me a nullable type, even though I&#8217;m not setting it to null no? </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">var</span><span style="font-family:consolas;font-size:10pt;"> Age ? = 4;</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p><font></font></p>
<p>From this point on, we can assign values (including null) to the Age variable without using the null type operator.&#160; In fact, including the ? operator would be invalid.</p>
<p style="margin:0;"><span style="font-family:consolas;color:green;font-size:10pt;">// update the value of Age; notice we don&#8217;t use the nullable ? symbol after the definition </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">Age = 9;</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p><font></font></p>
<h1>Tuples</h1>
<p>A tuple is an anonymous type consisting of an ordered set of heterogeneous fields. In Archetype, their fields can be named for Intellisense hinting when used as return types, or left unnamed. In local variable definitions, their individual members must either be named or use the anonymous member symbol, the underscore.</p>
<p>The following example shows the syntax for defining a tuple as a return type for a function.&#160; In this case, a pair of int values will be returned.</p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">GetMouseLocation (<span style="color:blue;">int</span>, <span style="color:blue;">int</span>) () </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;">return (100, 50); </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">}</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p><font></font></p>
<p>The members of a tuple in a return type can be named as a hint to the caller of the function.</p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">GetMouseLocation (x <span style="color:blue;">int</span>, y <span style="color:blue;">int</span>) () </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;">return (100, 50); </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">}</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p><font></font></p>
<p>The function is called and its return tuple value stored like this:</p>
<p><span style="line-height:115%;font-family:consolas;color:blue;font-size:10pt;">var</span><span style="line-height:115%;font-family:consolas;font-size:10pt;"> (x, y) = GetMouseLocation();</span></p>
<p><span style="line-height:115%;font-family:consolas;font-size:10pt;"></span>Here we’re defining a new tuple type, Tuple&lt;int, int&gt;, which is not named as a whole.&#160; We might call it an <strong>anonymous tuple</strong>.&#160; Instead of naming the whole, we’re naming the individual members.</p>
<p>Using the .NET Tuple type, we could also write this:</p>
<p style="margin:0;"><span style="font-family:consolas;color:green;font-size:10pt;">// we don&#8217;t care about the y value here </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">var</span><span style="font-family:consolas;font-size:10pt;"> (x, _) = GetMouseLocation();</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p><font></font></p>
<p>We would then have to reference loc.Item1 and loc.Item2 to access the individual members.&#160; Naming the members instead of the whole, however, makes more sense because it provides greater code readability.</p>
<p>This next example demonstrates how tuples can be defined using type inference.</p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">var</span><span style="font-family:consolas;font-size:10pt;"> (a, b) = (1, 2); </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">var</span><span style="font-family:consolas;font-size:10pt;"> (c, d) = (a, b); </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">var</span><span style="font-family:consolas;font-size:10pt;"> x = b;</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p><font></font></p>
<p>On the first line, <strong>a</strong> and <strong>b</strong> are defined as accessors into a new tuple: <strong>a</strong> is assigned to a value of 1, and <strong>b</strong> to a value of 2.&#160; On the second line, another tuple is defined and its member <strong>c</strong> is assigned to <strong>a</strong> while <strong>d</strong> is assigned to <strong>b</strong>.&#160; The third line demonstrates how you can use the tuple members independently of each other.&#160; In this case, the value of <strong>b</strong> is assigned to <strong>x</strong>.</p>
<p>If we don’t care about all of the members of a tuple, we can use the underscore character to ignore that member.&#160; The next example shows how to extract the <strong>x</strong> value from our GetMouseLocation function while ignoring the <strong>y</strong> value.</p>
<p style="margin:0;"><span style="font-family:consolas;color:green;font-size:10pt;">// we don&#8217;t care about the y value here </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">var</span><span style="font-family:consolas;font-size:10pt;"> (x, _) = GetMouseLocation();</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p><font></font></p>
<p>Finally, we have a handy way of swapping values without the need to introduce a third variable.</p>
<p>(a, b) = (b, a);</p>
<p>Archetype is not limited to two-member tuples.&#160; The .NET Framework defines tuples up to seven members, so Archetype will handle at least that many.&#160; If that proves inadequate, it should be relatively easy to extend this to any number of members.</p>
<h1>Streams</h1>
<p>I first read about streams (or lazy lists, as in Haskell) in a <a href="http://www.google.com/url?sa=t&amp;source=web&amp;cd=2&amp;ved=0CBsQFjAB&amp;url=http%3A%2F%2Fresearch.microsoft.com%2Fen-us%2Fum%2Fpeople%2Fgmb%2Fpapers%2Fecoop-corrected.pdf&amp;ei=IkMWTN7UEYP7lwf938zPDA&amp;usg=AFQjCNEcDR-J4nAXJ1ioqSaZ-Gmaa5QrTw&amp;sig2=beyzG0-XwnxBqYxAlI7RlQ">C Omega document</a> on a Microsoft Research site.&#160; They’re analogous to sequences in XQuery and XPath, and are implemented using the IEnumerable&lt;T&gt; type in an <a href="http://msdn.microsoft.com/en-us/library/dscyy5s0.aspx">iterator</a>.&#160; I liked C Omega’s * operator to define a stream because of the way it sets that type apart from a normal type.&#160; In C#, it’s not obvious that a function with a return type of IEnumerable&lt;T&gt; should behave any differently from another function until you notice the yield keyword.</p>
<p>If I want a stream defined as a property in C#, I’d have to write something like this:</p>
<p style="margin:0;"><span style="font-family:consolas;color:#72830f;font-size:11pt;">IEnumerable</span><span style="font-family:consolas;font-size:10pt;">&lt;</span><span style="font-family:consolas;color:#72830f;font-size:11pt;">int</span><span style="font-family:consolas;font-size:10pt;">&gt; Numbers </span><span style="font-family:consolas;"></span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:blue;font-size:10pt;">get</span><span style="font-family:consolas;font-size:10pt;"> </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="margin:0 0 0 .75in;"><span style="font-family:consolas;color:blue;font-size:10pt;">yield</span><span style="font-family:consolas;font-size:10pt;"> <span style="color:blue;">return</span> 1; </span></p>
<p style="margin:0 0 0 .75in;"><span style="font-family:consolas;color:blue;font-size:10pt;">yield</span><span style="font-family:consolas;font-size:10pt;"> <span style="color:blue;">return</span> 3; </span></p>
<p style="margin:0 0 0 .75in;"><span style="font-family:consolas;color:blue;font-size:10pt;">yield</span><span style="font-family:consolas;font-size:10pt;"> <span style="color:blue;">return</span> 5; </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;">} </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">} </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p><font></font></p>
<p>In Archetype, the syntax is more succinct and direct:</p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">Numbers </span><span style="font-family:consolas;color:#72830f;font-size:11pt;">int*</span><span style="font-family:consolas;"> </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:blue;font-size:10pt;">yield</span><span style="font-family:consolas;font-size:10pt;"> 1; </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:blue;font-size:10pt;">yield</span><span style="font-family:consolas;font-size:10pt;"> 2; </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:blue;font-size:10pt;">yield</span><span style="font-family:consolas;font-size:10pt;"> 3; </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">} </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p><font></font></p>
<p>We can be even more terse in such cases by using a comma in the yield list.</p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">Numbers </span><span style="font-family:consolas;color:#72830f;font-size:11pt;">int*</span><span style="font-family:consolas;"> </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:blue;font-size:10pt;">yield</span><span style="font-family:consolas;color:green;font-size:10pt;"> </span><span style="font-family:consolas;font-size:10pt;">1, 2, 3; </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">}</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p><font></font></p>
<p>Using list comprehensions, which we’ll explore in more detail later in this article, we can do this as well:</p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">Numbers </span><span style="font-family:consolas;color:#72830f;font-size:11pt;">int</span><span style="font-family:consolas;font-size:10pt;">*</span><span style="font-family:consolas;"> </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:blue;font-size:10pt;">yield</span><span style="font-family:consolas;color:green;font-size:10pt;"> </span><span style="font-family:consolas;font-size:10pt;">0..100 <span style="color:blue;">skip</span> 5; </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">}</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p><font></font></p>
<p>One note about the list comprehension here: we don’t use square brackets around the numeric range because they are implied in the yield statement.&#160; Including them here would cause the yield statement to return the list as a single yielded value.</p>
<p>These examples produce streams with a fixed number of elements, but streams can be infinite as well.&#160; This example returns all positive odd numbers starting with one.</p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">OddNumbers </span><span style="font-family:consolas;color:#72830f;font-size:11pt;">int</span><span style="font-family:consolas;font-size:10pt;">*</span><span style="font-family:consolas;"> </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:blue;font-size:10pt;">def</span><span style="font-family:consolas;font-size:10pt;"> i = 1; </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:blue;font-size:10pt;">loop </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="margin:0 0 0 .75in;"><span style="font-family:consolas;color:blue;font-size:10pt;">yield</span><span style="font-family:consolas;font-size:10pt;"> i; </span></p>
<p style="margin:0 0 0 .75in;"><span style="font-family:consolas;font-size:10pt;">i += 2; </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;font-size:10pt;">} </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">}</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p><font></font></p>
<p>Streams are lazy, so while it looks at first glance like an infinite loop from which you’ll never escape, in reality control is driven by the loop that accesses the stream.</p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">loop</span><span style="font-family:consolas;font-size:10pt;"> (<span style="color:blue;">var</span> n <span style="color:blue;">in</span> OddNumbers) </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:#72830f;font-size:11pt;">Console</span><span style="font-family:consolas;font-size:10pt;">.</span><span style="font-family:consolas;color:#1f497d;font-size:11pt;">WriteLine</span><span style="font-family:consolas;font-size:10pt;">(n);</span><span style="font-family:consolas;"> </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:blue;font-size:10pt;">if</span><span style="font-family:consolas;font-size:10pt;"> (n &gt; 100) </span></p>
<p style="margin:0 0 0 .75in;"><span style="font-family:consolas;color:blue;font-size:10pt;">break</span><span style="font-family:consolas;font-size:10pt;">; </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">}</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p><font></font></p>
<p>When other type operators are used, such as the nullable type operator, the stream operator must appear last.</p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">Ages </span><span style="font-family:consolas;color:#72830f;font-size:11pt;">int?*</span><span style="font-family:consolas;"> </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">{ </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:blue;font-size:10pt;">yield</span><span style="font-family:consolas;font-size:10pt;"> 35; </span></p>
<p style="margin:0 0 0 27pt;"><span style="font-family:consolas;color:blue;font-size:10pt;">yield null</span><span style="font-family:consolas;font-size:10pt;">; </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">}</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p><font></font></p>
<h1>List Comprehensions</h1>
<p>Archetype provides some special syntax for constructing lists called <a href="http://en.wikipedia.org/wiki/List_comprehension">list comprehensions</a>.&#160; This is syntactic sugar that provide shortcuts for building lists.</p>
<p>Consider the following syntax in C# and Archetype for constructing a list from 1 to 100.</p>
<p style="margin:0;"><span style="font-family:&quot;color:green;font-size:11pt;">// C# </span></p>
<p style="margin:0;"><span style="font-family:&quot;color:blue;font-size:11pt;">var</span><span style="font-family:&quot;font-size:11pt;"> FirstHundred = <span style="color:blue;">from</span> x in <span style="color:#2b91af;">Enumerable</span>.Range(1, 100) <span style="color:blue;">select</span> x; </span></p>
<p style="margin:0;"><span style="font-family:&quot;font-size:11pt;">&#160; </span></p>
<p style="margin:0;"><span style="font-family:&quot;color:green;font-size:11pt;">// Archetype </span></p>
<p style="margin:0;"><span style="font-family:&quot;color:blue;font-size:11pt;">var</span><span style="font-family:&quot;font-size:11pt;"> FirstHundred = [ 1..100 ];</span></p>
<p style="margin:0;"><span style="font-family:&quot;font-size:11pt;"></span></p>
<p><font></font></p>
<p>The square brackets in Archetype specify the construction of a list.&#160; Now consider a more complicated list construction.&#160; In this case, Linq is employed in both langauges:</p>
<p style="margin:0;"><span style="font-family:&quot;color:green;font-size:11pt;">// C# </span></p>
<p style="margin:0;"><span style="font-family:&quot;color:blue;font-size:11pt;">var</span><span style="font-family:&quot;font-size:11pt;"> FirstHundred = <span style="color:blue;">from</span> x in <span style="color:#2b91af;">Enumerable</span>.Range(1, 100) <span style="color:blue;">where</span> x*x &gt; 3 <span style="color:blue;">select</span> x*2; </span></p>
<p style="margin:0;"><span style="font-family:&quot;font-size:11pt;">&#160; </span></p>
<p style="margin:0;"><span style="font-family:&quot;color:green;font-size:11pt;">// Archetype </span></p>
<p style="margin:0;"><span style="font-family:&quot;color:blue;font-size:11pt;">var</span><span style="font-family:&quot;font-size:11pt;"> FirstHundred = <span style="color:blue;">from</span> x <span style="color:blue;">in</span> [ 1..100 ] <span style="color:blue;">where</span> x*x &gt; 3 <span style="color:blue;">select</span> x*2;</span></p>
<p style="margin:0;"><span style="font-family:&quot;font-size:11pt;"></span></p>
<p><font></font></p>
<p>Here you can see how a list can be used as the source of a query.</p>
<p>Here are some more list comprehension examples:</p>
<p><a href="http://dvanderboom.files.wordpress.com/2010/06/image33.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://dvanderboom.files.wordpress.com/2010/06/image_thumb33.png?w=946&#038;h=267" width="946" height="267" /></a> </p>
<h1>Subrange Types</h1>
<p>One of the gems in Pascal is <a href="http://en.wikipedia.org/wiki/Pascal_%28programming_language%29#Subrange_types">subrange types</a>.&#160; This allows a developer to define a new type that is structurally the same as another type, but whose values are constrained in some way.&#160; I’m often bothered by the disparity between database and .NET types.&#160; In a database, a string type (such as varchar) has a definite and usually small limit.&#160; In .NET, strings can be up to 2 MB, but there hasn’t been a good way in languages like C# and Visual Basic to constrain the length.&#160; In various <a href="http://en.wikipedia.org/wiki/Object-relational_mapping">object-relational mappers</a>, a <a href="http://blogs.msdn.com/b/efdesign/archive/2010/03/30/data-annotations-in-the-entity-framework-and-code-first.aspx">Size attribute</a> is often employed, but this is only metadata and does nothing to prevent the string from becoming too large, so additional work must be carefully performed to constrain the input using control properties and validation logic.</p>
<p>Archetype answers this with subrange types and type constraints.&#160; Consider the following:</p>
<p style="margin:0;"><span style="font-family:consolas;color:green;font-size:10pt;">// an int that can only have a value from 0 to 105 </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">type</span><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">ValidAge</span> <span style="color:#72830f;">int</span> <span style="color:blue;">in</span> [0..105];</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p><font></font></p>
<p>We can now use this ValidAge type to define our class properties:</p>
<p style="margin:0;"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">Age</span><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">ValidAge</span>;</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p><font></font></p>
<p>If a type is unlikely to be reused, we can also define subrange types anonymously.</p>
<p style="margin:0;"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">Age</span><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">int</span> <span style="color:blue;">in</span> [0..105];</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p><font></font></p>
<p>In fact, any list comprehension can be used in a subrange type expression, including multiple ranges, as long as a single base type is used.&#160; This example shows an age property that is valid for underage and retiring age people, but is invalid for any ages in between.</p>
<p style="margin:0;"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">Age</span><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">int</span> <span style="color:blue;">in</span> [0..17, 65..105];</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p><font></font></p>
<p>We can limit the length of a string simply:</p>
<p style="margin:0;"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">LastName</span><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">string#30</span>; </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p><font></font></p>
<p>Although in actual practice, it might make more sense to create several named types for various string lengths represented in a database:</p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">type</span><span style="font-family:consolas;font-size:10pt;"> Code <span style="color:#72830f;">string</span>#10; </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">type</span><span style="font-family:consolas;font-size:10pt;"> Name <span style="color:#72830f;">string</span>#20; </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">type</span><span style="font-family:consolas;font-size:10pt;"> Summary <span style="color:#72830f;">string</span>#100; </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:blue;font-size:10pt;">type</span><span style="font-family:consolas;font-size:10pt;"> Description <span style="color:#72830f;">string</span>; </span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;">&#160; </span></p>
<p style="margin:0;"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">LastName</span><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">Name;</span></span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"><span style="color:#72830f;"></span></span></p>
<p><font></font></p>
<p>By using a limited number of named string types, both in your code as well as in the database, it’s much easier to update the lengths as needed with a lot less effort.&#160; Archetype adds attributes to the members using these types as well, so this data can be queried and used to inform user interface controls and validation logic, enabling a stronger <a href="http://en.wikipedia.org/wiki/Model-driven_architecture">model-driven approach</a>.</p>
<p>The length of strings doesn’t need to be a single number representing the maximum, however.&#160; We can also specify a range of lengths.</p>
<p style="margin:0;"><span style="font-family:consolas;color:#1f497d;font-size:10pt;">Name</span><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">string</span>#2..3 = <span style="color:#c00000;">”ZZZ”</span>;</span></p>
<p style="margin:0;"><span style="font-family:consolas;font-size:10pt;"></span></p>
<p><font></font></p>
<p>Notice in this example how an initializer must be used.&#160; This is because a value of null is actually invalid for the Name property.&#160; The minimum allowed length is 2.&#160; Not providing an initializer with a valid value produces a compiler error.&#160; If we wanted to also allow a null value, we would do so like this:</p>
<p><span style="font-family:consolas;color:#1f497d;font-size:10pt;">Name</span><span style="font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">string?</span>#2..3 = “<span style="color:#c00000;">ZZZ”</span>;</span></p>
<p>As with type constraint expressions—discussed in the next section—Archetype injects the appropriate runtime checks in the property setter before any explicitly specified setter code, and throws an OutOfRangeException if the value doesn’t match the specified type criteria.</p>
<h1>Type Constraint Expressions</h1>
<p>Related to subrange types, type constraints can be applied equally to named or anonymous types.&#160; They allow you to specify a Linq-like <strong>where</strong> clause that will be used to check values being assigned to properties at runtime.&#160; Because they rely on property setter methods, type constraints cannot be used on fields.&#160; Fortunately, local variables within methods are also implemented like properties by default, so type constraints are also valid on local variables.</p>
<p>I’ve noticed that for some brands, or some stores carrying those brands, only even-numbered sizes of pants are stocked.&#160; This example shows a subrange type representing pants size, using both a subrange type as well as a type constraint expression.</p>
<p style="margin:0;"><span style="font-family:consolas;color:green;font-size:10pt;">// an int that can only be even </span></p>
<p><span style="line-height:115%;font-family:consolas;color:blue;font-size:10pt;">type</span><span style="line-height:115%;font-family:consolas;font-size:10pt;"> <span style="color:#72830f;">PantSize</span> <span style="color:#72830f;">int</span> <span style="color:blue;">in</span> [0..60]<span style="color:blue;"> where</span> <span style="color:blue;">value</span> % 2 == 0;</span></p>
<p><span style="line-height:115%;font-family:consolas;font-size:10pt;">     <br /></span>Using the modulus operator to obtain the remainder of division, we can be certain now that values of this type will only be even numbers.&#160; Type constraint expressions are allowed to call static or global functions, properties, and fields, but they cannot reference instance members.</p>
<h1>Summary</h1>
<p>This article covered a lot of type fundamentals.&#160; It should be obvious at this point how a common thread is being woven into the Archetype language.&#160; You’ve probably noticed how almost every construct has named and anonymous counterparts.&#160; Another important theme is the ability to extend types with syntax designed to shape them, and the use of Linq-like expressions throughout the language.</p>
<p>There is still some type content to cover, such as variant or tagged union types and duck typing, which I’ll save for a future article.&#160; Also coming soon is my work on defining custom query comprehensions for a Linq-like query language which can be easily extended with a simple language feature, as well as operators for higher-order functions like fold, map, and others.</p>
<p>Work on my goal of getting a basic Archetype compiler into everyone’s hands is going slowly but steadily.&#160; I have a simple Silverlight IDE running in the cloud that parses Archetype code and will return a .NET assembly.&#160; I got the Oslo tools to work on the server, and I’m partially building the AST I need to perform the semantic analysis and use to report compile errors to the user and to generate the C# code which I’ll then compile with csc.exe.&#160; I’m using a WCF publish-subscribe pattern to initiate a build from the client and report progress as messages going back to the client.&#160; In the next few weeks for sure, and possibly sooner, I’ll post a link to that so you can give Archetype a test drive yourself.</p>
<p><a href="http://dvanderboom.wordpress.com/2010/09/27/the-archetype-language-part-7/">[Part 7 of this series can be found here.]</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dvanderboom.wordpress.com/1077/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dvanderboom.wordpress.com/1077/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dvanderboom.wordpress.com/1077/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dvanderboom.wordpress.com/1077/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dvanderboom.wordpress.com/1077/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dvanderboom.wordpress.com/1077/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dvanderboom.wordpress.com/1077/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dvanderboom.wordpress.com/1077/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dvanderboom.wordpress.com/1077/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dvanderboom.wordpress.com/1077/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dvanderboom.wordpress.com/1077/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dvanderboom.wordpress.com/1077/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dvanderboom.wordpress.com/1077/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dvanderboom.wordpress.com/1077/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dvanderboom.wordpress.com&amp;blog=2293322&amp;post=1077&amp;subd=dvanderboom&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dvanderboom.wordpress.com/2010/06/14/the-archetype-language-part-6/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a59dbf3cc9c673540221e35e2c007ec1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Dan</media:title>
		</media:content>

		<media:content url="http://dvanderboom.files.wordpress.com/2010/06/image_thumb33.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
	</channel>
</rss>
