<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>VibrantCode - CMPT 376</title>
    <link>http://blog.andrewnurse.net/</link>
    <description>Oooh...pretty code</description>
    <language>en-us</language>
    <copyright>Andrew Nurse</copyright>
    <lastBuildDate>Wed, 01 Apr 2009 09:29:47 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>andrew@andrewnurse.net</managingEditor>
    <webMaster>andrew@andrewnurse.net</webMaster>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=027622e1-c0f4-4cb2-b75c-f990ef7d3ac4</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,027622e1-c0f4-4cb2-b75c-f990ef7d3ac4.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,027622e1-c0f4-4cb2-b75c-f990ef7d3ac4.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=027622e1-c0f4-4cb2-b75c-f990ef7d3ac4</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Microsoft is really taking major strides in terms of improving the programming experience
for developers on all current and <strong>future</strong> computing platforms. 
That’s why, earlier today, Microsoft released a beta of the new “System.QuantumEntanglement”
library.  This library, being considered for integration with .Net 4.1 (which,
my sources say, is codenamed “Looflirpa”), provides features for developers working
on quantum computers.  I won’t go in to too much detail, but this essentially
means working in an environment where objects can be in many different states (possibly
an infinite number) and where observation may change the state of an object. 
Microsoft has proposed a few options, but I have some additional ideas.
</p>
        <h2>Microsoft’s Proposal
</h2>
        <p>
          <a href="http://weblogs.asp.net/leftslipper/" target="_blank">Eilon Lipton</a>, of
the ASP.Net MVC team, <a href="http://weblogs.asp.net/leftslipper/archive/2009/04/01/the-string-or-the-cat-a-new-net-framework-library.aspx" target="_blank">is
proposing a number of new additions to the .Net BCL in 4.1</a>.  The first, is
a class called “StringOr&lt;T&gt;” which has the following API:
</p>
        <pre class="csharp" name="code">namespace System.QuantumEntanglement {
    public class StringOr&lt;TOther&gt; {
        public StringOr(string stringValue, TOther otherValue);

        public string StringValue { get; }
        public TOther OtherValue { get; }
    }
}</pre>
        <p>
This class is used to encapsulate a value which may be a string, but may be another
value.  This is a common user-input scenario, since almost all user input arrives
as strings, but will usually be converted to another data type.  He also proposes
a more general class called “SchrodingOr&lt;TDead, TAlive&gt;”
</p>
        <pre class="csharp" name="code">namespace System.QuantumEntanglement {
    public class SchrodingOr&lt;TDead, TAlive&gt; {
        public SchrodingOr(TDead dead, TAlive alive);

        public TAlive Alive { get; }
        public TDead Dead { get; }
    }
}</pre>
        <p>
This generalizes StringOr&lt;T&gt; to support any two types.  
</p>
        <p>
Eilon’s not the only one talking about this, <a href="http://www.hanselman.com/blog/NET41PreviewNewBaseClassLibraryBCLExtensionMethodsRFC.aspx" target="_blank">Scott
Hanselman</a> (well known Microsoft blogger), and <a href="http://blog.wekeroad.com/blog/cool-extension-methods-for-new-stringor/" target="_blank">Rob
Conery</a> (Author of the .Net Object-Relational Mapper: SubSonic) have also posted
on this topic.  So I figured I’d add my comments to the blogosphere.
</p>
        <p>
StringOr and SchrodingOr are great starts, but what if we need to represent objects
which may be in 2 states? What about 3 states? Infinite states?  That’s where
my proposals come in.  I propose the following additions to Eilon’s library:
</p>
        <h2>Generalizing SchrodingOr
</h2>
        <p>
The first is SchrodingOr&lt;T1, T2, T3, T4, T5, … , T<em>n</em>&gt; (for infinite <em>n</em>). 
This allows the developer to represent objects in as many states as they want.  
</p>
        <h2>C# 5.0 Compiler Support
</h2>
        <p>
I’m also proposing the following language syntax to help developers work with these
types.  Similar to the way the C# compiler converts “int?” to “Nullable&lt;int&gt;”
(which would now be replaced with “SchrodingOr&lt;int, Void&gt;” as it more accurately
represents the concept of a type which may or may not have a value), the new syntax
takes the following:
</p>
        <pre class="csharp" name="code">int?string?bool?DateTime? foo = GetUserInput(...);</pre>
        <p>
And produces output code which looks like this:
</p>
        <pre class="csharp" name="code">SchrodingOr&lt;int, DateTime, bool, string&gt; foo = GetUserInput(...);</pre>
        <p>
Then, we can defer observation until a later time, using the AsA&lt;T&gt;/AsAn&lt;T&gt;
method (since Eilon's Alive and Dead properties no longer work in an infinite state
environment). If we just want to observe the type and then make a decision, we can
use IsA&lt;T&gt;/IsAn&lt;T&gt; methods (of course, both are required, just in case
the type starts with a vowel), which returns a boolean indicating if the object is
of the type <em>T</em>. For example:
</p>
        <pre class="csharp" name="code">if(foo.IsA&lt;string&gt;()) { return foo.AsA&lt;string;&gt;; }</pre>
        <h2>
        </h2>
        <h2>Probabilistic Observation
</h2>
        <p>
Sometimes, we may want to observe an object only if there is a high probability of
it being in the right state, to avoid additional quantum variations. To do this, we
can use the CouldBeA&lt;T&gt;/CouldBeA&lt;T&gt; methods. These can, optionally, accept
a probability threshold beyond which a object is considered in the right state.
</p>
        <h2>Quantum Snapshots
</h2>
        <p>
Unfortunately, in between a call to IsA/An/CouldBeA/An and AsA/An, the state of the
object may change.  So, we may wish to observe an object and record the state
of the object at the time of observation.  Since in observing the object we may
change its state, our observations must be recorded in “Snapshots”.  The snapshot
is an instance of QuantumSnapshotOf&lt;TSchrodingOr&gt; (where <em>TSchrodingOr</em> must
be one of the SchrodingOr&lt;T1, ..., T<em>n</em>&gt; types), and has a property "Taken",
which is a DateTimeOffset (after all, we need precise timing here) containing the
exact time that the snapshot was taken. 
</p>
        <p>
Here’s an example combining Probabilistic Observation and Snapshots:
</p>
        <pre class="csharp" name="code">if(foo.CouldBeA&lt;string&gt;()) {
	QuantumSnapshotOf&lt;SchrodingOr&lt;int, string&gt;&gt; snapshot = foo.Observe();
	if(snapshot.Taken.Day == 1 &amp;&amp; snapshot.Taken.Month == 4) {
		throw new UnreliableObservationException(snapshot, "The data is unreliable");
	}
	return snapshot.AsA&lt;string&gt;();
}</pre>
        <h2>Summary
</h2>
        <p>
I think this is really interesting, forward-thinking, stuff from Microsoft. Eilon
has done some fantastic work getting the ball rolling, and its up to us to give our
feedback! Microsoft has created a section on MSDN for discussion on these new features: <a href="http://en.wikipedia.org/wiki/April_Fool%27s_Day" target="_blank">http://msdn.microsoft.com/en-US/QuantumEntanglement/Default.aspx</a></p>
        <img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=027622e1-c0f4-4cb2-b75c-f990ef7d3ac4" />
      </body>
      <title>Quantum Computing in .Net &amp;ldquo;Looflirpa&amp;rdquo;</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,027622e1-c0f4-4cb2-b75c-f990ef7d3ac4.aspx</guid>
      <link>http://blog.andrewnurse.net/2009/04/01/QuantumComputingInNetLdquoLooflirpardquo.aspx</link>
      <pubDate>Wed, 01 Apr 2009 09:29:47 GMT</pubDate>
      <description>&lt;p&gt;
Microsoft is really taking major strides in terms of improving the programming experience
for developers on all current and &lt;strong&gt;future&lt;/strong&gt; computing platforms.&amp;#160;
That’s why, earlier today, Microsoft released a beta of the new “System.QuantumEntanglement”
library.&amp;#160; This library, being considered for integration with .Net 4.1 (which,
my sources say, is codenamed “Looflirpa”), provides features for developers working
on quantum computers.&amp;#160; I won’t go in to too much detail, but this essentially
means working in an environment where objects can be in many different states (possibly
an infinite number) and where observation may change the state of an object.&amp;#160;
Microsoft has proposed a few options, but I have some additional ideas.
&lt;/p&gt;
&lt;h2&gt;Microsoft’s Proposal
&lt;/h2&gt;
&lt;p&gt;
&lt;a href="http://weblogs.asp.net/leftslipper/" target="_blank"&gt;Eilon Lipton&lt;/a&gt;, of
the ASP.Net MVC team, &lt;a href="http://weblogs.asp.net/leftslipper/archive/2009/04/01/the-string-or-the-cat-a-new-net-framework-library.aspx" target="_blank"&gt;is
proposing a number of new additions to the .Net BCL in 4.1&lt;/a&gt;.&amp;#160; The first, is
a class called “StringOr&amp;lt;T&amp;gt;” which has the following API:
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;namespace System.QuantumEntanglement {
    public class StringOr&amp;lt;TOther&amp;gt; {
        public StringOr(string stringValue, TOther otherValue);

        public string StringValue { get; }
        public TOther OtherValue { get; }
    }
}&lt;/pre&gt;
&lt;p&gt;
This class is used to encapsulate a value which may be a string, but may be another
value.&amp;#160; This is a common user-input scenario, since almost all user input arrives
as strings, but will usually be converted to another data type.&amp;#160; He also proposes
a more general class called “SchrodingOr&amp;lt;TDead, TAlive&amp;gt;”
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;namespace System.QuantumEntanglement {
    public class SchrodingOr&amp;lt;TDead, TAlive&amp;gt; {
        public SchrodingOr(TDead dead, TAlive alive);

        public TAlive Alive { get; }
        public TDead Dead { get; }
    }
}&lt;/pre&gt;
&lt;p&gt;
This generalizes StringOr&amp;lt;T&amp;gt; to support any two types.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
Eilon’s not the only one talking about this, &lt;a href="http://www.hanselman.com/blog/NET41PreviewNewBaseClassLibraryBCLExtensionMethodsRFC.aspx" target="_blank"&gt;Scott
Hanselman&lt;/a&gt; (well known Microsoft blogger), and &lt;a href="http://blog.wekeroad.com/blog/cool-extension-methods-for-new-stringor/" target="_blank"&gt;Rob
Conery&lt;/a&gt; (Author of the .Net Object-Relational Mapper: SubSonic) have also posted
on this topic.&amp;#160; So I figured I’d add my comments to the blogosphere.
&lt;/p&gt;
&lt;p&gt;
StringOr and SchrodingOr are great starts, but what if we need to represent objects
which may be in 2 states? What about 3 states? Infinite states?&amp;#160; That’s where
my proposals come in.&amp;#160; I propose the following additions to Eilon’s library:
&lt;/p&gt;
&lt;h2&gt;Generalizing SchrodingOr
&lt;/h2&gt;
&lt;p&gt;
The first is SchrodingOr&amp;lt;T1, T2, T3, T4, T5, … , T&lt;em&gt;n&lt;/em&gt;&amp;gt; (for infinite &lt;em&gt;n&lt;/em&gt;).&amp;#160;
This allows the developer to represent objects in as many states as they want.&amp;#160; 
&lt;/p&gt;
&lt;h2&gt;C# 5.0 Compiler Support
&lt;/h2&gt;
&lt;p&gt;
I’m also proposing the following language syntax to help developers work with these
types.&amp;#160; Similar to the way the C# compiler converts “int?” to “Nullable&amp;lt;int&amp;gt;”
(which would now be replaced with “SchrodingOr&amp;lt;int, Void&amp;gt;” as it more accurately
represents the concept of a type which may or may not have a value), the new syntax
takes the following:
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;int?string?bool?DateTime? foo = GetUserInput(...);&lt;/pre&gt;
&lt;p&gt;
And produces output code which looks like this:
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;SchrodingOr&amp;lt;int, DateTime, bool, string&amp;gt; foo = GetUserInput(...);&lt;/pre&gt;
&lt;p&gt;
Then, we can defer observation until a later time, using the AsA&amp;lt;T&amp;gt;/AsAn&amp;lt;T&amp;gt;
method (since Eilon's Alive and Dead properties no longer work in an infinite state
environment). If we just want to observe the type and then make a decision, we can
use IsA&amp;lt;T&amp;gt;/IsAn&amp;lt;T&amp;gt; methods (of course, both are required, just in case
the type starts with a vowel), which returns a boolean indicating if the object is
of the type &lt;em&gt;T&lt;/em&gt;. For example:
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;if(foo.IsA&amp;lt;string&amp;gt;()) { return foo.AsA&amp;lt;string;&amp;gt;; }&lt;/pre&gt;
&lt;h2&gt;
&lt;/h2&gt;
&lt;h2&gt;Probabilistic Observation
&lt;/h2&gt;
&lt;p&gt;
Sometimes, we may want to observe an object only if there is a high probability of
it being in the right state, to avoid additional quantum variations. To do this, we
can use the CouldBeA&amp;lt;T&amp;gt;/CouldBeA&amp;lt;T&amp;gt; methods. These can, optionally, accept
a probability threshold beyond which a object is considered in the right state.
&lt;/p&gt;
&lt;h2&gt;Quantum Snapshots
&lt;/h2&gt;
&lt;p&gt;
Unfortunately, in between a call to IsA/An/CouldBeA/An and AsA/An, the state of the
object may change.&amp;#160; So, we may wish to observe an object and record the state
of the object at the time of observation.&amp;#160; Since in observing the object we may
change its state, our observations must be recorded in “Snapshots”.&amp;#160; The snapshot
is an instance of QuantumSnapshotOf&amp;lt;TSchrodingOr&amp;gt; (where &lt;em&gt;TSchrodingOr&lt;/em&gt; must
be one of the SchrodingOr&amp;lt;T1, ..., T&lt;em&gt;n&lt;/em&gt;&amp;gt; types), and has a property &amp;quot;Taken&amp;quot;,
which is a DateTimeOffset (after all, we need precise timing here) containing the
exact time that the snapshot was taken. 
&lt;/p&gt;
&lt;p&gt;
Here’s an example combining Probabilistic Observation and Snapshots:
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;if(foo.CouldBeA&amp;lt;string&amp;gt;()) {
	QuantumSnapshotOf&amp;lt;SchrodingOr&amp;lt;int, string&amp;gt;&amp;gt; snapshot = foo.Observe();
	if(snapshot.Taken.Day == 1 &amp;amp;&amp;amp; snapshot.Taken.Month == 4) {
		throw new UnreliableObservationException(snapshot, &amp;quot;The data is unreliable&amp;quot;);
	}
	return snapshot.AsA&amp;lt;string&amp;gt;();
}&lt;/pre&gt;
&lt;h2&gt;Summary
&lt;/h2&gt;
&lt;p&gt;
I think this is really interesting, forward-thinking, stuff from Microsoft. Eilon
has done some fantastic work getting the ball rolling, and its up to us to give our
feedback! Microsoft has created a section on MSDN for discussion on these new features: &lt;a href="http://en.wikipedia.org/wiki/April_Fool%27s_Day" target="_blank"&gt;http://msdn.microsoft.com/en-US/QuantumEntanglement/Default.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=027622e1-c0f4-4cb2-b75c-f990ef7d3ac4" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,027622e1-c0f4-4cb2-b75c-f990ef7d3ac4.aspx</comments>
      <category>CMPT 376</category>
      <category>Cool Software</category>
    </item>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=4159504d-84ed-4198-abca-2e14bceecd83</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,4159504d-84ed-4198-abca-2e14bceecd83.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,4159504d-84ed-4198-abca-2e14bceecd83.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=4159504d-84ed-4198-abca-2e14bceecd83</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Did you know that the largest open-source project on the Microsoft platform was started
in Vancouver, Canada?  It’s true!  DotNetNuke is the largest Open-Source
community in the .Net by downloads (at least).  Since moving to CodePlex (Microsoft’s
Open-Source hosting platform) in January 2009, DNN has been downloaded over 180,000
times (at time of writing).  This makes it second only to a World Of Warcraft
Add-On development studio which has been on CodePlex since Sept 2007 (at least that
was the earliest check-in I could find).  Adding that to the all-time download
score on SourceForge (the project’s previous host) of <strong>4.3 Million downloads</strong>,
and you’ve got the the largest .Net open-source project (and one which I am proud
to <a href="http://www.dotnetnuke.com/Products/Development/Forge/ModuleReports/tabid/970/Default.aspx" target="_blank">contribute
to</a>)!
</p>
        <p>
And here’s the great part for us Canucks, DotNetNuke was created right here (by “here”,
I mean where I live :P) in Vancouver!
</p>
        <p>
Microsoft Canada is running a contest called the “Ignite It” award to honour Canadian
developers and IT professionals.  DotNetNuke is nominated in the Developer category,
and we’re looking for your votes!  There’s only 2 days left, and we’re in the
top 5 (which will go on to be judged).  Still, we’d like to be up at number one
before voting ends, so here comes the shameless plug :P.  Here’s the deal: You
can vote once per Windows Live account per day (though there aren’t many days left
:( ).  It only takes a second to vote, and I’ve even created a TinyURL to share
with your friends: <a href="http://tinyurl.com/dnnigniteit">http://tinyurl.com/dnnigniteit</a></p>
        <p>
Let’s push DNN into the top spot!
</p>
        <img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=4159504d-84ed-4198-abca-2e14bceecd83" />
      </body>
      <title>DotNetNuke on IgniteIT</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,4159504d-84ed-4198-abca-2e14bceecd83.aspx</guid>
      <link>http://blog.andrewnurse.net/2009/03/30/DotNetNukeOnIgniteIT.aspx</link>
      <pubDate>Mon, 30 Mar 2009 06:47:18 GMT</pubDate>
      <description>&lt;p&gt;
Did you know that the largest open-source project on the Microsoft platform was started
in Vancouver, Canada?&amp;#160; It’s true!&amp;#160; DotNetNuke is the largest Open-Source
community in the .Net by downloads (at least).&amp;#160; Since moving to CodePlex (Microsoft’s
Open-Source hosting platform) in January 2009, DNN has been downloaded over 180,000
times (at time of writing).&amp;#160; This makes it second only to a World Of Warcraft
Add-On development studio which has been on CodePlex since Sept 2007 (at least that
was the earliest check-in I could find).&amp;#160; Adding that to the all-time download
score on SourceForge (the project’s previous host) of &lt;strong&gt;4.3 Million downloads&lt;/strong&gt;,
and you’ve got the the largest .Net open-source project (and one which I am proud
to &lt;a href="http://www.dotnetnuke.com/Products/Development/Forge/ModuleReports/tabid/970/Default.aspx" target="_blank"&gt;contribute
to&lt;/a&gt;)!
&lt;/p&gt;
&lt;p&gt;
And here’s the great part for us Canucks, DotNetNuke was created right here (by “here”,
I mean where I live :P) in Vancouver!
&lt;/p&gt;
&lt;p&gt;
Microsoft Canada is running a contest called the “Ignite It” award to honour Canadian
developers and IT professionals.&amp;#160; DotNetNuke is nominated in the Developer category,
and we’re looking for your votes!&amp;#160; There’s only 2 days left, and we’re in the
top 5 (which will go on to be judged).&amp;#160; Still, we’d like to be up at number one
before voting ends, so here comes the shameless plug :P.&amp;#160; Here’s the deal: You
can vote once per Windows Live account per day (though there aren’t many days left
:( ).&amp;#160; It only takes a second to vote, and I’ve even created a TinyURL to share
with your friends: &lt;a href="http://tinyurl.com/dnnigniteit"&gt;http://tinyurl.com/dnnigniteit&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Let’s push DNN into the top spot!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=4159504d-84ed-4198-abca-2e14bceecd83" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,4159504d-84ed-4198-abca-2e14bceecd83.aspx</comments>
      <category>CMPT 376</category>
      <category>DNN</category>
    </item>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=b3dcd5f0-45b9-4454-bd29-604311e3166a</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,b3dcd5f0-45b9-4454-bd29-604311e3166a.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,b3dcd5f0-45b9-4454-bd29-604311e3166a.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=b3dcd5f0-45b9-4454-bd29-604311e3166a</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Back in January, I started <a href="http://blog.andrewnurse.net/2009/01/08/WritingABlogForFunAndProfithellipIMeanGrades.aspx" target="_blank">blogging
more frequently due to a course I was taking</a>.  As part of that, I started
using Windows Live Writer to write all my blog posts.  I use the <a href="http://www.dasblog.info/" target="_blank">DasBlog</a> engine
to power my blog, and it supports one of the many blogging APIs that Windows Live
Writer uses (I believe it’s MetaWeblog).  So, I hooked it up to my blog, and
everything just worked!
</p>
        <p>
My favorite feature is the ability to create and save drafts and then publish them
on demand.  I have inspiration at the strangest times, and often in large batches,
so I end up with a couple ideas of things to blog in a day, and no ideas the next
day.  So, I just create a bunch of drafts, get them ready to publish and then
publish them over a longer period of time (like say… a day :P).  For example,
I wrote this post 5 minutes after the previous post, but I thought it might overload
my readers to post it immediately :).  So, I save a draft and post it a bit later
(when I don’t have anything to blog about :D).
</p>
        <p>
If you have a blog, and it supports one of the blogging APIs, and you’re running on
Windows, you really should try Windows Live Writer!
</p>
        <img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=b3dcd5f0-45b9-4454-bd29-604311e3166a" />
      </body>
      <title>Windows Live Writer &amp;ndash; After 2 Months</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,b3dcd5f0-45b9-4454-bd29-604311e3166a.aspx</guid>
      <link>http://blog.andrewnurse.net/2009/03/27/WindowsLiveWriterNdashAfter2Months.aspx</link>
      <pubDate>Fri, 27 Mar 2009 07:39:23 GMT</pubDate>
      <description>&lt;p&gt;
Back in January, I started &lt;a href="http://blog.andrewnurse.net/2009/01/08/WritingABlogForFunAndProfithellipIMeanGrades.aspx" target="_blank"&gt;blogging
more frequently due to a course I was taking&lt;/a&gt;.&amp;#160; As part of that, I started
using Windows Live Writer to write all my blog posts.&amp;#160; I use the &lt;a href="http://www.dasblog.info/" target="_blank"&gt;DasBlog&lt;/a&gt; engine
to power my blog, and it supports one of the many blogging APIs that Windows Live
Writer uses (I believe it’s MetaWeblog).&amp;#160; So, I hooked it up to my blog, and
everything just worked!
&lt;/p&gt;
&lt;p&gt;
My favorite feature is the ability to create and save drafts and then publish them
on demand.&amp;#160; I have inspiration at the strangest times, and often in large batches,
so I end up with a couple ideas of things to blog in a day, and no ideas the next
day.&amp;#160; So, I just create a bunch of drafts, get them ready to publish and then
publish them over a longer period of time (like say… a day :P).&amp;#160; For example,
I wrote this post 5 minutes after the previous post, but I thought it might overload
my readers to post it immediately :).&amp;#160; So, I save a draft and post it a bit later
(when I don’t have anything to blog about :D).
&lt;/p&gt;
&lt;p&gt;
If you have a blog, and it supports one of the blogging APIs, and you’re running on
Windows, you really should try Windows Live Writer!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=b3dcd5f0-45b9-4454-bd29-604311e3166a" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,b3dcd5f0-45b9-4454-bd29-604311e3166a.aspx</comments>
      <category>CMPT 376</category>
      <category>Cool Software</category>
    </item>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=8c924228-f23a-4565-95f7-334eb0b4e338</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,8c924228-f23a-4565-95f7-334eb0b4e338.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,8c924228-f23a-4565-95f7-334eb0b4e338.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=8c924228-f23a-4565-95f7-334eb0b4e338</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Microsoft’s MIX Web Development conference was held in Las Vegas last week and while
I would have loved to go, the cost and scheduling just made it impossible :(. 
Despite that, I’ve been spending the past few days “attending” MIX virtually! 
Microsoft posts high quality WMV versions of the talks on the <a href="https://content.visitmix.com/2009/Sessions/" target="_blank">MIX
website</a>, perfect for catching up on the sessions.  With my Media Center PC
hooked up through my Xbox 360, I can browse through my rapidly growing collection
of talks and watch them at my leisure.  It’s almost like being there!  A
couple of my recommendations are below:
</p>
        <ul>
          <li>
            <a href="http://videos.visitmix.com/MIX09/KEY01" target="_blank">Day One Keynote</a> –
I haven’t had a chance to watch this yet, but it already has two things going for
it.  Bill Buxton talking about User Experiences and a live <a href="http://www.dotnetnuke.com/" target="_blank">DotNetNuke</a> installation
using the <a href="http://www.microsoft.com/web" target="_blank">Microsoft Web Platform
Installer 2.0 Beta</a>. 
</li>
          <li>
            <a href="http://videos.visitmix.com/MIX09/T50F" target="_blank">ASP.Net MVC: America’s
Next Top Model View Controller Framework</a> – I love ASP.Net MVC, and this is a great
intro.  Of course, I may be biased since I worked on the team last summer. BTW,
version 1.0 was released last Wednesday, and a large chunk of the AJAX stuff is my
code (my code is actually in a released Microsoft product! w00t!) 
</li>
          <li>
            <a href="http://videos.visitmix.com/MIX09/T44F" target="_blank">Microsoft ASP.NET
Model View Controller (MVC): Ninja on Fire Black Belt Tips</a> – If the previous talk
was MVC 101, this is MVC 201 :P.  Though I have to be honest, I haven’t actually
watched this one yet.  I’m sure its chock full of useful MVC tricks though! 
</li>
          <li>
            <a href="http://videos.visitmix.com/MIX09/T49F" target="_blank">File|New -&gt; Company:
Creating NerdDinner.com with Microsoft ASP.NET Model View Controller (MVC)</a> – I
know, yet another MVC talk, but if you’re more of a “get to the code” type of programmer,
this may be your style.  Plus, Scott Hanselman is an excellent presenter. 
</li>
          <li>
            <a href="http://videos.visitmix.com/MIX09/T79M" target="_blank">How'd they do it?
Real App. Real Code. Two Weeks. Nothing but .NET</a> – Another Scott Hanselman talk,
this one only 20mins long.  You hear people talk about “Rapid Application Development”
but in this talk Scott shows off a concrete example of a 2 week project that forms
part of the Adidas Motorsports portal. 
</li>
          <li>
            <a href="http://videos.visitmix.com/MIX09/T45F" target="_blank">Building Out of Browser
Experiences with Microsoft Silverlight 3</a> – This is another one I haven’t actually
watched yet but intrigued me.  With Silverlight 3, Microsoft is positioning itself
to take on both Adobe Flash and AIR. 
</li>
        </ul>
        <p>
That’s by no means a complete list of great talks, just my first impressions based
on the first few I’ve watched and the abstracts that interested me on the list. 
Feel free to post your own favourites in the comments!
</p>
        <img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=8c924228-f23a-4565-95f7-334eb0b4e338" />
      </body>
      <title>Virtually &amp;ldquo;Attending&amp;rdquo; MIX09</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,8c924228-f23a-4565-95f7-334eb0b4e338.aspx</guid>
      <link>http://blog.andrewnurse.net/2009/03/24/VirtuallyLdquoAttendingrdquoMIX09.aspx</link>
      <pubDate>Tue, 24 Mar 2009 06:10:38 GMT</pubDate>
      <description>&lt;p&gt;
Microsoft’s MIX Web Development conference was held in Las Vegas last week and while
I would have loved to go, the cost and scheduling just made it impossible :(.&amp;#160;
Despite that, I’ve been spending the past few days “attending” MIX virtually!&amp;#160;
Microsoft posts high quality WMV versions of the talks on the &lt;a href="https://content.visitmix.com/2009/Sessions/" target="_blank"&gt;MIX
website&lt;/a&gt;, perfect for catching up on the sessions.&amp;#160; With my Media Center PC
hooked up through my Xbox 360, I can browse through my rapidly growing collection
of talks and watch them at my leisure.&amp;#160; It’s almost like being there!&amp;#160; A
couple of my recommendations are below:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://videos.visitmix.com/MIX09/KEY01" target="_blank"&gt;Day One Keynote&lt;/a&gt; –
I haven’t had a chance to watch this yet, but it already has two things going for
it.&amp;#160; Bill Buxton talking about User Experiences and a live &lt;a href="http://www.dotnetnuke.com/" target="_blank"&gt;DotNetNuke&lt;/a&gt; installation
using the &lt;a href="http://www.microsoft.com/web" target="_blank"&gt;Microsoft Web Platform
Installer 2.0 Beta&lt;/a&gt;. 
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://videos.visitmix.com/MIX09/T50F" target="_blank"&gt;ASP.Net MVC: America’s
Next Top Model View Controller Framework&lt;/a&gt; – I love ASP.Net MVC, and this is a great
intro.&amp;#160; Of course, I may be biased since I worked on the team last summer. BTW,
version 1.0 was released last Wednesday, and a large chunk of the AJAX stuff is my
code (my code is actually in a released Microsoft product! w00t!) 
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://videos.visitmix.com/MIX09/T44F" target="_blank"&gt;Microsoft ASP.NET
Model View Controller (MVC): Ninja on Fire Black Belt Tips&lt;/a&gt; – If the previous talk
was MVC 101, this is MVC 201 :P.&amp;#160; Though I have to be honest, I haven’t actually
watched this one yet.&amp;#160; I’m sure its chock full of useful MVC tricks though! 
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://videos.visitmix.com/MIX09/T49F" target="_blank"&gt;File|New -&amp;gt; Company:
Creating NerdDinner.com with Microsoft ASP.NET Model View Controller (MVC)&lt;/a&gt; – I
know, yet another MVC talk, but if you’re more of a “get to the code” type of programmer,
this may be your style.&amp;#160; Plus, Scott Hanselman is an excellent presenter. 
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://videos.visitmix.com/MIX09/T79M" target="_blank"&gt;How'd they do it?
Real App. Real Code. Two Weeks. Nothing but .NET&lt;/a&gt; – Another Scott Hanselman talk,
this one only 20mins long.&amp;#160; You hear people talk about “Rapid Application Development”
but in this talk Scott shows off a concrete example of a 2 week project that forms
part of the Adidas Motorsports portal. 
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://videos.visitmix.com/MIX09/T45F" target="_blank"&gt;Building Out of Browser
Experiences with Microsoft Silverlight 3&lt;/a&gt; – This is another one I haven’t actually
watched yet but intrigued me.&amp;#160; With Silverlight 3, Microsoft is positioning itself
to take on both Adobe Flash and AIR. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
That’s by no means a complete list of great talks, just my first impressions based
on the first few I’ve watched and the abstracts that interested me on the list.&amp;#160;
Feel free to post your own favourites in the comments!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=8c924228-f23a-4565-95f7-334eb0b4e338" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,8c924228-f23a-4565-95f7-334eb0b4e338.aspx</comments>
      <category>CMPT 376</category>
      <category>MVC</category>
      <category>Silverlight</category>
    </item>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=5a920d46-e468-426d-bf69-1e045901f2ff</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,5a920d46-e468-426d-bf69-1e045901f2ff.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,5a920d46-e468-426d-bf69-1e045901f2ff.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=5a920d46-e468-426d-bf69-1e045901f2ff</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Having spent 5 years taking courses in the Computing Science department at Simon Fraser
University, I’ve become pretty familiar with the various web applications used to
track course projects, submit assignments, etc.  Over the same five years, I’ve
seen numerous technological changes, both in the “outside world” and within the University. 
For example, not too long ago, SFU switched to a central authentication service aptly
named “Central Authentication Service” (or <a href="http://www.jasig.org/cas" target="_blank">CAS</a>). 
It’s a pretty nice service, with a snazzy login screen (below).
</p>
        <p>
          <a href="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/AreallCSdepartmentsthisslowtoadoptnewtec_9F8F/image_6.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="SFU CAS Login Page" border="0" alt="SFU CAS Login Page" src="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/AreallCSdepartmentsthisslowtoadoptnewtec_9F8F/image_thumb_2.png" width="644" height="437" />
          </a>
        </p>
        <p>
        </p>
        <p>
It’s not only snazzy, but a pretty useful system.  I even integrated one of my
school projects (an online grade tracking application) with it without any external
support.  Let’s contrast that with the <strong>current</strong> login screen
for “Gradebook”, an application developed by the CS department and used in most CS
courses to track grades
</p>
        <p>
          <a href="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/AreallCSdepartmentsthisslowtoadoptnewtec_9F8F/image_8.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Gradebook Login Page" border="0" alt="Gradebook Login Page" src="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/AreallCSdepartmentsthisslowtoadoptnewtec_9F8F/image_thumb_3.png" width="644" height="297" />
          </a>
        </p>
        <p>
Ok, not as snazzy, but here’s the really frustrating thing:  My account here
is NOT the same as my SFU computing account!
</p>
        <p>
The “Gradebook” system also includes an electronic assignment submission server
</p>
        <p>
          <a href="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/AreallCSdepartmentsthisslowtoadoptnewtec_9F8F/image_10.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="CS Submission Server" border="0" alt="CS Submission Server" src="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/AreallCSdepartmentsthisslowtoadoptnewtec_9F8F/image_thumb_4.png" width="644" height="133" />
          </a>
        </p>
        <p>
(BTW: This is only a small snapshot of the page)
</p>
        <p>
Sure, it isn’t snazzy looking, but it’s simple and to the point (+10 points). 
However, it comes with a few caveats: I have to use my “Gradebook” account, not my
(so-called) “universal” SFU account (-25 points), and ALL submissions must be in ZIP,
GZIP or RAR format (-25 points)!  For many of my courses, the electronic submission
has been a single file, and the instructor often has to email the students to remind
them that they have to wrap their single PDF file (or Word Doc, etc.) in a ZIP file
to upload it.  I can understand the benefits as far as storage space, and bandwidth
consumption, but wouldn’t that be better achieved by simply placing a size restriction
and allowing any file to be uploaded?  Plus, when I do login, I get a page with
a drop-down list of courses.  Here’s the contents:
</p>
        <p>
          <a href="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/AreallCSdepartmentsthisslowtoadoptnewtec_9F8F/image_12.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/AreallCSdepartmentsthisslowtoadoptnewtec_9F8F/image_thumb_5.png" width="90" height="244" />
          </a>
        </p>
        <p>
See that scrollbar?  Yeah… I’m not registered in anywhere near that many courses
(the <strong><em><u>one</u></em></strong> course I’m registered in is a few scrolls
away), but it would appear the submission server doesn’t know that.
</p>
        <p>
It doesn’t end with the student interface.  In a course on “Web Information Systems,”
we were required to develop a web-based application of some sort, and my group chose
to build a grade tracking system (partly out of frustration with the current system). 
Before starting the project, we organized a meeting with our instructor to find out
what his frustrations were with the existing “Gradebook” system used by the department. 
He mentioned that instructors had to rebuild the structure of assignments, exams and
their relative contributions to the final grade every time they created a course. 
He continued to show us a tool he developed which allowed him to create more detailed
marks, give comments, and build an email to send off to the student.  He had
to build a custom tool to perform tasks which I would consider essential to a modern
grade tracking system.  In a few weeks, we hammered out a “school project quality”
system running on Ruby on Rails (ASP.Net MVC wasn’t out yet :P) which supported all
the features we discussed in our meeting with the prof.
</p>
        <p>
Granted, I know it’s not as simple to fix as it is to complain.  But, with the
tools out there, and the number of open-source and commercial courseware products,
I still don’t really understand why we’re using a system with so many annoying issues…
</p>
        <p>
For the CS students (or recent grads) who read my blog, is my experience atypical? 
Or are your school services as out of date as these?
</p>
        <img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=5a920d46-e468-426d-bf69-1e045901f2ff" />
      </body>
      <title>Are all CS departments this slow to adopt new tech?</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,5a920d46-e468-426d-bf69-1e045901f2ff.aspx</guid>
      <link>http://blog.andrewnurse.net/2009/03/11/AreAllCSDepartmentsThisSlowToAdoptNewTech.aspx</link>
      <pubDate>Wed, 11 Mar 2009 18:21:01 GMT</pubDate>
      <description>&lt;p&gt;
Having spent 5 years taking courses in the Computing Science department at Simon Fraser
University, I’ve become pretty familiar with the various web applications used to
track course projects, submit assignments, etc.&amp;#160; Over the same five years, I’ve
seen numerous technological changes, both in the “outside world” and within the University.&amp;#160;
For example, not too long ago, SFU switched to a central authentication service aptly
named “Central Authentication Service” (or &lt;a href="http://www.jasig.org/cas" target="_blank"&gt;CAS&lt;/a&gt;).&amp;#160;
It’s a pretty nice service, with a snazzy login screen (below).
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/AreallCSdepartmentsthisslowtoadoptnewtec_9F8F/image_6.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="SFU CAS Login Page" border="0" alt="SFU CAS Login Page" src="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/AreallCSdepartmentsthisslowtoadoptnewtec_9F8F/image_thumb_2.png" width="644" height="437" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
It’s not only snazzy, but a pretty useful system.&amp;#160; I even integrated one of my
school projects (an online grade tracking application) with it without any external
support.&amp;#160; Let’s contrast that with the &lt;strong&gt;current&lt;/strong&gt; login screen
for “Gradebook”, an application developed by the CS department and used in most CS
courses to track grades
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/AreallCSdepartmentsthisslowtoadoptnewtec_9F8F/image_8.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Gradebook Login Page" border="0" alt="Gradebook Login Page" src="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/AreallCSdepartmentsthisslowtoadoptnewtec_9F8F/image_thumb_3.png" width="644" height="297" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Ok, not as snazzy, but here’s the really frustrating thing:&amp;#160; My account here
is NOT the same as my SFU computing account!
&lt;/p&gt;
&lt;p&gt;
The “Gradebook” system also includes an electronic assignment submission server
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/AreallCSdepartmentsthisslowtoadoptnewtec_9F8F/image_10.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="CS Submission Server" border="0" alt="CS Submission Server" src="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/AreallCSdepartmentsthisslowtoadoptnewtec_9F8F/image_thumb_4.png" width="644" height="133" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
(BTW: This is only a small snapshot of the page)
&lt;/p&gt;
&lt;p&gt;
Sure, it isn’t snazzy looking, but it’s simple and to the point (+10 points).&amp;#160;
However, it comes with a few caveats: I have to use my “Gradebook” account, not my
(so-called) “universal” SFU account (-25 points), and ALL submissions must be in ZIP,
GZIP or RAR format (-25 points)!&amp;#160; For many of my courses, the electronic submission
has been a single file, and the instructor often has to email the students to remind
them that they have to wrap their single PDF file (or Word Doc, etc.) in a ZIP file
to upload it.&amp;#160; I can understand the benefits as far as storage space, and bandwidth
consumption, but wouldn’t that be better achieved by simply placing a size restriction
and allowing any file to be uploaded?&amp;#160; Plus, when I do login, I get a page with
a drop-down list of courses.&amp;#160; Here’s the contents:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/AreallCSdepartmentsthisslowtoadoptnewtec_9F8F/image_12.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/AreallCSdepartmentsthisslowtoadoptnewtec_9F8F/image_thumb_5.png" width="90" height="244" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
See that scrollbar?&amp;#160; Yeah… I’m not registered in anywhere near that many courses
(the &lt;strong&gt;&lt;em&gt;&lt;u&gt;one&lt;/u&gt;&lt;/em&gt;&lt;/strong&gt; course I’m registered in is a few scrolls
away), but it would appear the submission server doesn’t know that.
&lt;/p&gt;
&lt;p&gt;
It doesn’t end with the student interface.&amp;#160; In a course on “Web Information Systems,”
we were required to develop a web-based application of some sort, and my group chose
to build a grade tracking system (partly out of frustration with the current system).&amp;#160;
Before starting the project, we organized a meeting with our instructor to find out
what his frustrations were with the existing “Gradebook” system used by the department.&amp;#160;
He mentioned that instructors had to rebuild the structure of assignments, exams and
their relative contributions to the final grade every time they created a course.&amp;#160;
He continued to show us a tool he developed which allowed him to create more detailed
marks, give comments, and build an email to send off to the student.&amp;#160; He had
to build a custom tool to perform tasks which I would consider essential to a modern
grade tracking system.&amp;#160; In a few weeks, we hammered out a “school project quality”
system running on Ruby on Rails (ASP.Net MVC wasn’t out yet :P) which supported all
the features we discussed in our meeting with the prof.
&lt;/p&gt;
&lt;p&gt;
Granted, I know it’s not as simple to fix as it is to complain.&amp;#160; But, with the
tools out there, and the number of open-source and commercial courseware products,
I still don’t really understand why we’re using a system with so many annoying issues…
&lt;/p&gt;
&lt;p&gt;
For the CS students (or recent grads) who read my blog, is my experience atypical?&amp;#160;
Or are your school services as out of date as these?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=5a920d46-e468-426d-bf69-1e045901f2ff" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,5a920d46-e468-426d-bf69-1e045901f2ff.aspx</comments>
      <category>CMPT 376</category>
      <category>Rants</category>
      <category>School</category>
    </item>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=097ca941-0cda-4b30-906d-eb100045537c</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,097ca941-0cda-4b30-906d-eb100045537c.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,097ca941-0cda-4b30-906d-eb100045537c.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=097ca941-0cda-4b30-906d-eb100045537c</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
My laptop is rapidly becoming obsolete, particularly when it comes to disk space :(. 
I want to install my games on it, so I have something to do <strike>in class </strike>between
classes, but I’m running out space.  So, I came up with an idea: Buy a 16GB USB
Key, and put a bunch of games on that!  I keep my USB keys in my backpack, so
they’re never too far away.  It sounded like the perfect solution, until I noticed
that many programs can’t be installed on Removable Drives!
</p>
        <p>
So, I came up with a simple workaround, once again using an awesome tool from Sysinternals
:).  I used <a href="http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx" target="_blank">Junction</a> to
create a junction folder called “C:\Program Files\Games” which points to a “Games”
folder on my USB Key.  The following command line does the trick (assuming F:\Games
is the folder on the USB key, and <strong>it already exists</strong>):
</p>
        <p>
junction.exe “C:\Program Files\Games” “F:\Games”
</p>
        <p>
Seems to be working so far!  I just install the game into that folder, and all
the files go to the USB Key.  Of course, its not quite the same as a <a href="http://portableapps.com/" target="_blank">portable
app</a>, since it will only run on the machine it was installed on, but it takes some
of the burden off of my hard drive.  If my laptop supported SDHC, I’d probably
use a 16GB SD card and just leave it plugged in to my laptop, but unfortunately, that’s
not an option.
</p>
        <img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=097ca941-0cda-4b30-906d-eb100045537c" />
      </body>
      <title>Tips and Tricks: Installing Programs to a USB Key</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,097ca941-0cda-4b30-906d-eb100045537c.aspx</guid>
      <link>http://blog.andrewnurse.net/2009/03/04/TipsAndTricksInstallingProgramsToAUSBKey.aspx</link>
      <pubDate>Wed, 04 Mar 2009 17:43:24 GMT</pubDate>
      <description>&lt;p&gt;
My laptop is rapidly becoming obsolete, particularly when it comes to disk space :(.&amp;#160;
I want to install my games on it, so I have something to do &lt;strike&gt;in class &lt;/strike&gt;between
classes, but I’m running out space.&amp;#160; So, I came up with an idea: Buy a 16GB USB
Key, and put a bunch of games on that!&amp;#160; I keep my USB keys in my backpack, so
they’re never too far away.&amp;#160; It sounded like the perfect solution, until I noticed
that many programs can’t be installed on Removable Drives!
&lt;/p&gt;
&lt;p&gt;
So, I came up with a simple workaround, once again using an awesome tool from Sysinternals
:).&amp;#160; I used &lt;a href="http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx" target="_blank"&gt;Junction&lt;/a&gt; to
create a junction folder called “C:\Program Files\Games” which points to a “Games”
folder on my USB Key.&amp;#160; The following command line does the trick (assuming F:\Games
is the folder on the USB key, and &lt;strong&gt;it already exists&lt;/strong&gt;):
&lt;/p&gt;
&lt;p&gt;
junction.exe “C:\Program Files\Games” “F:\Games”
&lt;/p&gt;
&lt;p&gt;
Seems to be working so far!&amp;#160; I just install the game into that folder, and all
the files go to the USB Key.&amp;#160; Of course, its not quite the same as a &lt;a href="http://portableapps.com/" target="_blank"&gt;portable
app&lt;/a&gt;, since it will only run on the machine it was installed on, but it takes some
of the burden off of my hard drive.&amp;#160; If my laptop supported SDHC, I’d probably
use a 16GB SD card and just leave it plugged in to my laptop, but unfortunately, that’s
not an option.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=097ca941-0cda-4b30-906d-eb100045537c" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,097ca941-0cda-4b30-906d-eb100045537c.aspx</comments>
      <category>CMPT 376</category>
      <category>Tips</category>
    </item>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=532731bb-a7d2-4c93-8045-ea628315cdb7</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,532731bb-a7d2-4c93-8045-ea628315cdb7.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,532731bb-a7d2-4c93-8045-ea628315cdb7.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=532731bb-a7d2-4c93-8045-ea628315cdb7</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
There’s been a lot of buzz around the Internet about Quake Live.  I decided to
succumb to the hype and try it out and I must say it is pretty cool.  However,
a lot of people have heralded this as a unique new way of distributing games, and
I have to disagree with that.  Quake Live is no different than any other downloadable
game, it just happens to use the browser as a host.  When you go to <a href="http://www.quakelive.com">http://www.quakelive.com</a> for
the first time, you log in and wait in a queue.  When you reach the front of
the queue, you are prompted to download a plugin (in the form of a Windows Installer
MSI file) for your browser.  If the queuing thing sounds very <a href="http://www.fileplanet.com/" target="_blank">FilePlanet</a>-esque
to you, it certainly does to me.  Then you download the <strike>game</strike> plugin
installer and run it (as an Admin).  When it finishes, you have to restart your
browser and go back to the website.  After waiting in the queue some more, the
game loads up and runs in the browser.
</p>
        <p>
How is this process different from installing a regular desktop game?  You download
the installer, run it as Admin, and then start the game.  The only different
here is that the game code is running in-process (AFAIK) with the web browser. 
It really isn’t that different!  Developing a game like this using an existing
plugin like Flash or Silverlight (especially since <a href="http://weblogs.asp.net/scottgu/archive/2008/11/16/update-on-silverlight-2-and-a-glimpse-of-silverlight-3.aspx" target="_blank">Silverlight
3 is supposed to include 3D Acceleration support</a>) would be, IMHO, much more innovative.
</p>
        <p>
About the only thing in Quake Live that differs from a regular desktop game is the
use of a streaming installer, which downloads a (relatively) small bootstrapper and
then downloads the rest as you play a 10minute training level.  Even that isn’t
really unique, as <a href="http://www.hanselman.com" target="_blank">Scott Hanselman</a><a href="http://www.hanselman.com/blog/QuakeLiveReviewAndRantWhyIsThisInteresting.aspx" target="_blank">points
out</a>, Guild Wars has included that feature for a while.
</p>
        <img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=532731bb-a7d2-4c93-8045-ea628315cdb7" />
      </body>
      <title>Quake Live &amp;ndash; Fun? Sure. Interesting? Meh.</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,532731bb-a7d2-4c93-8045-ea628315cdb7.aspx</guid>
      <link>http://blog.andrewnurse.net/2009/03/02/QuakeLiveNdashFunSureInterestingMeh.aspx</link>
      <pubDate>Mon, 02 Mar 2009 22:14:24 GMT</pubDate>
      <description>&lt;p&gt;
There’s been a lot of buzz around the Internet about Quake Live.&amp;#160; I decided to
succumb to the hype and try it out and I must say it is pretty cool.&amp;#160; However,
a lot of people have heralded this as a unique new way of distributing games, and
I have to disagree with that.&amp;#160; Quake Live is no different than any other downloadable
game, it just happens to use the browser as a host.&amp;#160; When you go to &lt;a href="http://www.quakelive.com"&gt;http://www.quakelive.com&lt;/a&gt; for
the first time, you log in and wait in a queue.&amp;#160; When you reach the front of
the queue, you are prompted to download a plugin (in the form of a Windows Installer
MSI file) for your browser.&amp;#160; If the queuing thing sounds very &lt;a href="http://www.fileplanet.com/" target="_blank"&gt;FilePlanet&lt;/a&gt;-esque
to you, it certainly does to me.&amp;#160; Then you download the &lt;strike&gt;game&lt;/strike&gt; plugin
installer and run it (as an Admin).&amp;#160; When it finishes, you have to restart your
browser and go back to the website.&amp;#160; After waiting in the queue some more, the
game loads up and runs in the browser.
&lt;/p&gt;
&lt;p&gt;
How is this process different from installing a regular desktop game?&amp;#160; You download
the installer, run it as Admin, and then start the game.&amp;#160; The only different
here is that the game code is running in-process (AFAIK) with the web browser.&amp;#160;
It really isn’t that different!&amp;#160; Developing a game like this using an existing
plugin like Flash or Silverlight (especially since &lt;a href="http://weblogs.asp.net/scottgu/archive/2008/11/16/update-on-silverlight-2-and-a-glimpse-of-silverlight-3.aspx" target="_blank"&gt;Silverlight
3 is supposed to include 3D Acceleration support&lt;/a&gt;) would be, IMHO, much more innovative.
&lt;/p&gt;
&lt;p&gt;
About the only thing in Quake Live that differs from a regular desktop game is the
use of a streaming installer, which downloads a (relatively) small bootstrapper and
then downloads the rest as you play a 10minute training level.&amp;#160; Even that isn’t
really unique, as &lt;a href="http://www.hanselman.com" target="_blank"&gt;Scott Hanselman&lt;/a&gt; &lt;a href="http://www.hanselman.com/blog/QuakeLiveReviewAndRantWhyIsThisInteresting.aspx" target="_blank"&gt;points
out&lt;/a&gt;, Guild Wars has included that feature for a while.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=532731bb-a7d2-4c93-8045-ea628315cdb7" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,532731bb-a7d2-4c93-8045-ea628315cdb7.aspx</comments>
      <category>CMPT 376</category>
      <category>Rants</category>
    </item>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=06c83f91-d881-4eca-afce-c190af10e9cc</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,06c83f91-d881-4eca-afce-c190af10e9cc.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,06c83f91-d881-4eca-afce-c190af10e9cc.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=06c83f91-d881-4eca-afce-c190af10e9cc</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
11:00AM – I look in my backpack to check that the Project Proposal that is due at
my PHYS 192 class at 11:30 is still in there
</p>
        <p>
11:01AM – I realize it isn’t there, I left it at home
</p>
        <p>
11:02AM – I decide to just reprint it on campus, and relax
</p>
        <p>
11:05AM – I fire up Word and open up the Print Dialog
</p>
        <p>
11:06AM – I discover that the campus print server isn’t in my printers list
</p>
        <p>
11:08AM – I locate the campus printing instructions and start setting up the printer
</p>
        <p>
11:10AM – I discover that the printer driver I need isn’t included in Windows
</p>
        <p>
11:12AM – I locate the printer driver online and start downloading it
</p>
        <p>
11:15AM – Printer driver installed, I configure the campus printer
</p>
        <p>
11:17AM – Still reasonably calm, I fire up Word again and send my document to the
print queue.
</p>
        <p>
11:20AM – After packing up my machine, I walk over to the printing station in the
Laptop Lab
</p>
        <p>
11:21AM – I discover a “Out of Order – Sorry for the inconvenience” sign :(
</p>
        <p>
11:25AM – I walk to the other side of the building to another lab and put my printer
card in the reader
</p>
        <p>
11:26AM – Spending the last $0.11 on my card, I print my document
</p>
        <p>
11:27AM – Calmly, I grab the printed document and see the following text:
</p>
        <pre>Error: PCL Protocol Error</pre>
        <p>
11:28AM – Scramble to a PC in the computer lab and log in to the machine
</p>
        <p>
11:30AM – Machine finally logs in, and I fire up Internet Explorer, navigating to
my Live Mesh Desktop
</p>
        <p>
11:31AM – Open up the document from Live Mesh and print it
</p>
        <p>
11:33AM – Go back to the printer station, and discover that my printer card is empty!
</p>
        <p>
11:34AM – Walk to the nearby printer card top-up machine and see: “Out of Order –
Sorry for the inconvenience”
</p>
        <p>
11:35AM – After discovering I had no cash, walk to the nearby ATM and withdraw some
</p>
        <p>
11:37AM – Head to the nearest cafeteria and buy a bottle of water, getting a twoonie
($2 coin, for my non-Canadian readers) in change :)
</p>
        <p>
11:37AM – Head off to the library on the other side of campus (where the only other
printer card top-up machine is… AFAIK)
</p>
        <p>
11:40AM – Reach the library and stick my card in the machine, pop my twoonie in the
slot and top-up my card
</p>
        <p>
11:41AM – Go over to the library printer and release the printer job
</p>
        <p>
11:42AM – Pick up the paper and dash over to the lecture hall with my printed proposal
in hand
</p>
        <p>
11:45AM – Arrive, late, and take the only remaining seat… at the front of the class,
right next to the pile of proposals from the other students
</p>
        <p>
11:46AM – Drop my proposal on the pile and sigh in relief
</p>
        <p>
Seriously… need a way better campus printing system.  Only two top-up machines
on campus?  Why can’t I just add funds to my student account online and submit
PDFs and DOCs to be printed if I don’t want the hassle of configuring the print server?
</p>
        <p>
Arg…
</p>
        <img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=06c83f91-d881-4eca-afce-c190af10e9cc" />
      </body>
      <title>Campus Printing: A Tale of Panic and Frustration</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,06c83f91-d881-4eca-afce-c190af10e9cc.aspx</guid>
      <link>http://blog.andrewnurse.net/2009/02/27/CampusPrintingATaleOfPanicAndFrustration.aspx</link>
      <pubDate>Fri, 27 Feb 2009 22:44:47 GMT</pubDate>
      <description>&lt;p&gt;
11:00AM – I look in my backpack to check that the Project Proposal that is due at
my PHYS 192 class at 11:30 is still in there
&lt;/p&gt;
&lt;p&gt;
11:01AM – I realize it isn’t there, I left it at home
&lt;/p&gt;
&lt;p&gt;
11:02AM – I decide to just reprint it on campus, and relax
&lt;/p&gt;
&lt;p&gt;
11:05AM – I fire up Word and open up the Print Dialog
&lt;/p&gt;
&lt;p&gt;
11:06AM – I discover that the campus print server isn’t in my printers list
&lt;/p&gt;
&lt;p&gt;
11:08AM – I locate the campus printing instructions and start setting up the printer
&lt;/p&gt;
&lt;p&gt;
11:10AM – I discover that the printer driver I need isn’t included in Windows
&lt;/p&gt;
&lt;p&gt;
11:12AM – I locate the printer driver online and start downloading it
&lt;/p&gt;
&lt;p&gt;
11:15AM – Printer driver installed, I configure the campus printer
&lt;/p&gt;
&lt;p&gt;
11:17AM – Still reasonably calm, I fire up Word again and send my document to the
print queue.
&lt;/p&gt;
&lt;p&gt;
11:20AM – After packing up my machine, I walk over to the printing station in the
Laptop Lab
&lt;/p&gt;
&lt;p&gt;
11:21AM – I discover a “Out of Order – Sorry for the inconvenience” sign :(
&lt;/p&gt;
&lt;p&gt;
11:25AM – I walk to the other side of the building to another lab and put my printer
card in the reader
&lt;/p&gt;
&lt;p&gt;
11:26AM – Spending the last $0.11 on my card, I print my document
&lt;/p&gt;
&lt;p&gt;
11:27AM – Calmly, I grab the printed document and see the following text:
&lt;/p&gt;
&lt;pre&gt;Error: PCL Protocol Error&lt;/pre&gt;
&lt;p&gt;
11:28AM – Scramble to a PC in the computer lab and log in to the machine
&lt;/p&gt;
&lt;p&gt;
11:30AM – Machine finally logs in, and I fire up Internet Explorer, navigating to
my Live Mesh Desktop
&lt;/p&gt;
&lt;p&gt;
11:31AM – Open up the document from Live Mesh and print it
&lt;/p&gt;
&lt;p&gt;
11:33AM – Go back to the printer station, and discover that my printer card is empty!
&lt;/p&gt;
&lt;p&gt;
11:34AM – Walk to the nearby printer card top-up machine and see: “Out of Order –
Sorry for the inconvenience”
&lt;/p&gt;
&lt;p&gt;
11:35AM – After discovering I had no cash, walk to the nearby ATM and withdraw some
&lt;/p&gt;
&lt;p&gt;
11:37AM – Head to the nearest cafeteria and buy a bottle of water, getting a twoonie
($2 coin, for my non-Canadian readers) in change :)
&lt;/p&gt;
&lt;p&gt;
11:37AM – Head off to the library on the other side of campus (where the only other
printer card top-up machine is… AFAIK)
&lt;/p&gt;
&lt;p&gt;
11:40AM – Reach the library and stick my card in the machine, pop my twoonie in the
slot and top-up my card
&lt;/p&gt;
&lt;p&gt;
11:41AM – Go over to the library printer and release the printer job
&lt;/p&gt;
&lt;p&gt;
11:42AM – Pick up the paper and dash over to the lecture hall with my printed proposal
in hand
&lt;/p&gt;
&lt;p&gt;
11:45AM – Arrive, late, and take the only remaining seat… at the front of the class,
right next to the pile of proposals from the other students
&lt;/p&gt;
&lt;p&gt;
11:46AM – Drop my proposal on the pile and sigh in relief
&lt;/p&gt;
&lt;p&gt;
Seriously… need a way better campus printing system.&amp;#160; Only two top-up machines
on campus?&amp;#160; Why can’t I just add funds to my student account online and submit
PDFs and DOCs to be printed if I don’t want the hassle of configuring the print server?
&lt;/p&gt;
&lt;p&gt;
Arg…
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=06c83f91-d881-4eca-afce-c190af10e9cc" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,06c83f91-d881-4eca-afce-c190af10e9cc.aspx</comments>
      <category>CMPT 376</category>
      <category>School</category>
    </item>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=8cc65c27-995e-421e-910d-2bdd36c208c7</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,8cc65c27-995e-421e-910d-2bdd36c208c7.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,8cc65c27-995e-421e-910d-2bdd36c208c7.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=8cc65c27-995e-421e-910d-2bdd36c208c7</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Here’s part 4 of my infinite part series on developing a compiler from scratch. 
See all the posts <a href="http://blog.andrewnurse.net/ct.ashx?id=cbb29a9a-f33f-45e9-8836-47c73a0fd1a0&amp;url=http%3a%2f%2fblog.andrewnurse.net%2fCategoryView%2ccategory%2cCompiler%252BProject.aspx">here</a>.
</p>
        <p>
I’ve decided to change things up a bit on the compiler project.  Instead of writing
the tokenizer and parser from scratch, I’m going to check out a new language that’s
part of Microsoft’s <a href="http://msdn.microsoft.com/en-us/library/cc709420.aspx" target="_blank">“Oslo”</a> Project. 
Oslo includes a language called M, which is primarily designed for developing data
models.  M is actually three languages, MGraph, MSchema and MGrammar.  MGraph
is a language for defining abstract graphs, for example:
</p>
        <pre class="m" name="code">Universities {
    Canada {
        BritishColumbia {
            SFU { 
                Name { "Simon Fraser University" }, 
                Location { "Burnaby, BC" } 
            },
            UBC { 
                Name { "University of British Columbia" }, 
                Location { "Vancouver, BC" } 
            }
        }
    }
}</pre>
        <p>
MSchema is a language for defining the schema for these graphs, for example
</p>
        <pre class="m" name="code">module Universities {
    type University {
        Name : Text#100,
        Location : Text#100
    }
}</pre>
        <p>
Finally, MGrammar is a language for defining custom Domain-Specific Languages (DSLs)
which map to MGraph graphs. This is the language that is most useful to this project.
After all, a general-purpose programming language is just a DSL where the "Domain"
is very broad :). So, I've spent a few hours this week whipping up an MGrammar grammar
for Duh, and the results are promising.  I’ll be posting some details on that
in the next post, but first we need to explore a key concept in compilers, Abstract
Syntax Trees.
</p>
        <p>
The end goal of the tokenization and parsing phases of a compiler is to produce an
Abstract Syntax Tree (or AST) representing the source code.  This is probably
best illustrated by an example, so consider this expression:
</p>
        <pre>5+6</pre>
        <p>
This is an addition operation, using 5 and 6 as the arguments, which we represent
in an AST like this (using the MGraph syntax above):
</p>
        <pre>Add { 5, 6 }</pre>
        <p>
Similarly, more complex expressions can be translated to trees:
</p>
        <pre>5+6*(3+4)</pre>
        <p>
Becomes:
</p>
        <pre>Add { 5, Multiply { 6, Add { 3, 4 } } }</pre>
        <p>
Which represents the following instructions:
</p>
        <ul>
          <li>
Add 3 and 4 
</li>
          <li>
Multiply that result by 6 
</li>
          <li>
Add 5 to that result 
</li>
        </ul>
        <p>
Essentially, we are building up the expression from the bottom of the tree up. 
This makes it much easier to convert the expression into code.
</p>
        <p>
I’ll post the MGrammar file for the language when I finish it up in a day or so, then
its on to writing the code to do the parsing.
</p>
        <img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=8cc65c27-995e-421e-910d-2bdd36c208c7" />
      </body>
      <title>Compiler Project &amp;ndash; Part 4: ASTs and switching to MGrammar</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,8cc65c27-995e-421e-910d-2bdd36c208c7.aspx</guid>
      <link>http://blog.andrewnurse.net/2009/02/18/CompilerProjectNdashPart4ASTsAndSwitchingToMGrammar.aspx</link>
      <pubDate>Wed, 18 Feb 2009 23:07:00 GMT</pubDate>
      <description>&lt;p&gt;
Here’s part 4 of my infinite part series on developing a compiler from scratch.&amp;#160;
See all the posts &lt;a href="http://blog.andrewnurse.net/ct.ashx?id=cbb29a9a-f33f-45e9-8836-47c73a0fd1a0&amp;amp;url=http%3a%2f%2fblog.andrewnurse.net%2fCategoryView%2ccategory%2cCompiler%252BProject.aspx"&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
I’ve decided to change things up a bit on the compiler project.&amp;#160; Instead of writing
the tokenizer and parser from scratch, I’m going to check out a new language that’s
part of Microsoft’s &lt;a href="http://msdn.microsoft.com/en-us/library/cc709420.aspx" target="_blank"&gt;“Oslo”&lt;/a&gt; Project.&amp;#160;
Oslo includes a language called M, which is primarily designed for developing data
models.&amp;#160; M is actually three languages, MGraph, MSchema and MGrammar.&amp;#160; MGraph
is a language for defining abstract graphs, for example:
&lt;/p&gt;
&lt;pre class="m" name="code"&gt;Universities {
    Canada {
        BritishColumbia {
            SFU { 
                Name { &amp;quot;Simon Fraser University&amp;quot; }, 
                Location { &amp;quot;Burnaby, BC&amp;quot; } 
            },
            UBC { 
                Name { &amp;quot;University of British Columbia&amp;quot; }, 
                Location { &amp;quot;Vancouver, BC&amp;quot; } 
            }
        }
    }
}&lt;/pre&gt;
&lt;p&gt;
MSchema is a language for defining the schema for these graphs, for example
&lt;/p&gt;
&lt;pre class="m" name="code"&gt;module Universities {
    type University {
        Name : Text#100,
        Location : Text#100
    }
}&lt;/pre&gt;
&lt;p&gt;
Finally, MGrammar is a language for defining custom Domain-Specific Languages (DSLs)
which map to MGraph graphs. This is the language that is most useful to this project.
After all, a general-purpose programming language is just a DSL where the &amp;quot;Domain&amp;quot;
is very broad :). So, I've spent a few hours this week whipping up an MGrammar grammar
for Duh, and the results are promising.&amp;#160; I’ll be posting some details on that
in the next post, but first we need to explore a key concept in compilers, Abstract
Syntax Trees.
&lt;/p&gt;
&lt;p&gt;
The end goal of the tokenization and parsing phases of a compiler is to produce an
Abstract Syntax Tree (or AST) representing the source code.&amp;#160; This is probably
best illustrated by an example, so consider this expression:
&lt;/p&gt;
&lt;pre&gt;5+6&lt;/pre&gt;
&lt;p&gt;
This is an addition operation, using 5 and 6 as the arguments, which we represent
in an AST like this (using the MGraph syntax above):
&lt;/p&gt;
&lt;pre&gt;Add { 5, 6 }&lt;/pre&gt;
&lt;p&gt;
Similarly, more complex expressions can be translated to trees:
&lt;/p&gt;
&lt;pre&gt;5+6*(3+4)&lt;/pre&gt;
&lt;p&gt;
Becomes:
&lt;/p&gt;
&lt;pre&gt;Add { 5, Multiply { 6, Add { 3, 4 } } }&lt;/pre&gt;
&lt;p&gt;
Which represents the following instructions:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Add 3 and 4 
&lt;/li&gt;
&lt;li&gt;
Multiply that result by 6 
&lt;/li&gt;
&lt;li&gt;
Add 5 to that result 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Essentially, we are building up the expression from the bottom of the tree up.&amp;#160;
This makes it much easier to convert the expression into code.
&lt;/p&gt;
&lt;p&gt;
I’ll post the MGrammar file for the language when I finish it up in a day or so, then
its on to writing the code to do the parsing.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=8cc65c27-995e-421e-910d-2bdd36c208c7" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,8cc65c27-995e-421e-910d-2bdd36c208c7.aspx</comments>
      <category>CMPT 376</category>
      <category>Compiler Project</category>
    </item>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=ebff3ae0-84fe-4a4e-9dd8-531c9c469dee</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,ebff3ae0-84fe-4a4e-9dd8-531c9c469dee.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,ebff3ae0-84fe-4a4e-9dd8-531c9c469dee.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=ebff3ae0-84fe-4a4e-9dd8-531c9c469dee</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <strong>UPDATE 2: PowerKits requires PowerShell 2.0.  If you’re seeing errors
regarding the “try-catch” keywords, its because those keywords were added in PowerShell
2.0 and I use them in PowerKits.  Sorry!</strong>
        </p>
        <p>
          <strong>UPDATE: It turns out PowerShell 2.0 already contains a feature like this:
“Modules.”  See </strong>
          <a href="http://huddledmasses.org/powershell-modules/" target="_blank">
            <strong>here</strong>
          </a>
          <strong> for
more info.  Since it seems to be far superior to PowerKit (which I just hacked
together for my own needs), I guess that just leaves this as an interesting exercise
:).</strong>
        </p>
        <p>
I’ve been a huge fan of Windows PowerShell since it first came out as “Monad” (aka
“MSH”).  Now that its entering version 2.0, which will be built-in to Windows
7 and Windows Server 2008, I’m getting even more into it.  I’ve written a Podcast
Receiver (PowerCast) and an automated process for converting videos for use on my
Xbox 360 (PowerCode).
</p>
        <p>
[The following paragraph is a short intro to PowerShell, feel free to skip it if you’re
familiar with PoSH]
</p>
        <p>
What is PowerShell?  PowerShell is an object-oriented shell which, IMHO, kicks
the pants off of BASH and Perl.  PowerShell is a dynamically-typed scripting
language written on the .Net Framework, which gives you full access to every class,
method, and property in the framework.  You could write a GUI, Server, heck even
a 3D Game in PowerShell (it just might not perform as well as another language). 
PowerShell is also an interactive “Read-Eval-Print” loop application which gives you
a prompt into which you type commands which are then evaluated and their results printed
to the screen (i.e. a standard “Shell” similar to cmd.exe or BASH).  Finally,
PowerShell is an embeddable scripting environment which lets any .Net-based application
embed the PowerShell scripting language.  However, most people (myself included)
are referring to the Shell itself when they talk about PowerShell
</p>
        <p>
Anyway, on to the main purpose of this post.  I started to get frustrated with
trying to manage all my scripts and keep them organized.  I was also downloading
a lot of useful scripts off of the web, but had to manually place them somewhere in
my file-system (let alone managing all the dependencies).  Other scripting environments,
such as Ruby, have packaging systems, such as RubyGems, to manage libraries of functionality
and publish them for others to download.  So, I thought, why doesn’t PowerShell
have something like this?
</p>
        <p>
Thus, PowerKits were born.  The concept is simple.  A PowerKit is a directory
on your file-system which contains a manifest file “Kit.xml”.  This file specifies
some information such as the paths to various script files, aliases to create, .Net
assemblies to load and (in a future version) PowerShell “snap-ins” to load. 
After installing a kit (by placing it in one of many, configurable, pre-defined folders),
it can simply be enabled using a single PowerShell Command.  For example, to
enable the “MyCompany.MyKit” PowerKit:
</p>
        <pre class="code">Enable-Kit MyCompany.MyKit</pre>
        <p>
Enabling a kit loads all the assemblies, script files, etc. into your PowerShell environment,
making them available for use.  A Kit can then be disabled similarly using the
”Disable-Kit” command.  Disabling the kit removes all the script files, etc.
from the environment (NOTE: .Net assemblies cannot be unloaded without restarting
PowerShell, due to a limitation of the .Net Framework).
</p>
        <p>
PowerKit also supports packaging kits into a ZIP-like format, specifically the <a href="http://en.wikipedia.org/wiki/Open_Packaging_Convention" target="_blank">Open
Packaging Convention</a> developed by Microsoft for Office 2007 (since the .Net framework
has built-in support for that format). These “Kit Archives” can be downloaded and
installed using a single command.  Eventually, I plan to add support for installing
a kit directly from the web, so you could use a command like this:
</p>
        <pre class="code">Install-Kit <a href="http://www.mycompany.com/MyCompany.MyKit.kit">http://www.mycompany.com/MyCompany.MyKit.kit</a></pre>
        <p>
Or even this:
</p>
        <pre class="code">Install-Kit MyCompany.MyKit</pre>
        <p>
And the framework would go out and download the kit and install it, giving PowerShell
a true “gems-esque” packaging system.
</p>
        <p>
To install PowerKit, download the Install-PowerKit.ps1 script from the <a href="http://www.codeplex.com/powerkits" target="_blank">CodePlex
site</a>, more installation details are in the release notes on that page.
</p>
        <img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=ebff3ae0-84fe-4a4e-9dd8-531c9c469dee" />
      </body>
      <title>Get-PowerKit: A PowerShell Packaging System</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,ebff3ae0-84fe-4a4e-9dd8-531c9c469dee.aspx</guid>
      <link>http://blog.andrewnurse.net/2009/02/09/GetPowerKitAPowerShellPackagingSystem.aspx</link>
      <pubDate>Mon, 09 Feb 2009 22:15:01 GMT</pubDate>
      <description>&lt;p&gt;
&lt;strong&gt;UPDATE 2: PowerKits requires PowerShell 2.0.&amp;#160; If you’re seeing errors
regarding the “try-catch” keywords, its because those keywords were added in PowerShell
2.0 and I use them in PowerKits.&amp;#160; Sorry!&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;UPDATE: It turns out PowerShell 2.0 already contains a feature like this:
“Modules.”&amp;#160; See &lt;/strong&gt;&lt;a href="http://huddledmasses.org/powershell-modules/" target="_blank"&gt;&lt;strong&gt;here&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; for
more info.&amp;#160; Since it seems to be far superior to PowerKit (which I just hacked
together for my own needs), I guess that just leaves this as an interesting exercise
:).&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
I’ve been a huge fan of Windows PowerShell since it first came out as “Monad” (aka
“MSH”).&amp;#160; Now that its entering version 2.0, which will be built-in to Windows
7 and Windows Server 2008, I’m getting even more into it.&amp;#160; I’ve written a Podcast
Receiver (PowerCast) and an automated process for converting videos for use on my
Xbox 360 (PowerCode).
&lt;/p&gt;
&lt;p&gt;
[The following paragraph is a short intro to PowerShell, feel free to skip it if you’re
familiar with PoSH]
&lt;/p&gt;
&lt;p&gt;
What is PowerShell?&amp;#160; PowerShell is an object-oriented shell which, IMHO, kicks
the pants off of BASH and Perl.&amp;#160; PowerShell is a dynamically-typed scripting
language written on the .Net Framework, which gives you full access to every class,
method, and property in the framework.&amp;#160; You could write a GUI, Server, heck even
a 3D Game in PowerShell (it just might not perform as well as another language).&amp;#160;
PowerShell is also an interactive “Read-Eval-Print” loop application which gives you
a prompt into which you type commands which are then evaluated and their results printed
to the screen (i.e. a standard “Shell” similar to cmd.exe or BASH).&amp;#160; Finally,
PowerShell is an embeddable scripting environment which lets any .Net-based application
embed the PowerShell scripting language.&amp;#160; However, most people (myself included)
are referring to the Shell itself when they talk about PowerShell
&lt;/p&gt;
&lt;p&gt;
Anyway, on to the main purpose of this post.&amp;#160; I started to get frustrated with
trying to manage all my scripts and keep them organized.&amp;#160; I was also downloading
a lot of useful scripts off of the web, but had to manually place them somewhere in
my file-system (let alone managing all the dependencies).&amp;#160; Other scripting environments,
such as Ruby, have packaging systems, such as RubyGems, to manage libraries of functionality
and publish them for others to download.&amp;#160; So, I thought, why doesn’t PowerShell
have something like this?
&lt;/p&gt;
&lt;p&gt;
Thus, PowerKits were born.&amp;#160; The concept is simple.&amp;#160; A PowerKit is a directory
on your file-system which contains a manifest file “Kit.xml”.&amp;#160; This file specifies
some information such as the paths to various script files, aliases to create, .Net
assemblies to load and (in a future version) PowerShell “snap-ins” to load.&amp;#160;
After installing a kit (by placing it in one of many, configurable, pre-defined folders),
it can simply be enabled using a single PowerShell Command.&amp;#160; For example, to
enable the “MyCompany.MyKit” PowerKit:
&lt;/p&gt;
&lt;pre class="code"&gt;Enable-Kit MyCompany.MyKit&lt;/pre&gt;
&lt;p&gt;
Enabling a kit loads all the assemblies, script files, etc. into your PowerShell environment,
making them available for use.&amp;#160; A Kit can then be disabled similarly using the
”Disable-Kit” command.&amp;#160; Disabling the kit removes all the script files, etc.
from the environment (NOTE: .Net assemblies cannot be unloaded without restarting
PowerShell, due to a limitation of the .Net Framework).
&lt;/p&gt;
&lt;p&gt;
PowerKit also supports packaging kits into a ZIP-like format, specifically the &lt;a href="http://en.wikipedia.org/wiki/Open_Packaging_Convention" target="_blank"&gt;Open
Packaging Convention&lt;/a&gt; developed by Microsoft for Office 2007 (since the .Net framework
has built-in support for that format). These “Kit Archives” can be downloaded and
installed using a single command.&amp;#160; Eventually, I plan to add support for installing
a kit directly from the web, so you could use a command like this:
&lt;/p&gt;
&lt;pre class="code"&gt;Install-Kit &lt;a href="http://www.mycompany.com/MyCompany.MyKit.kit"&gt;http://www.mycompany.com/MyCompany.MyKit.kit&lt;/a&gt;&lt;/pre&gt;
&lt;p&gt;
Or even this:
&lt;/p&gt;
&lt;pre class="code"&gt;Install-Kit MyCompany.MyKit&lt;/pre&gt;
&lt;p&gt;
And the framework would go out and download the kit and install it, giving PowerShell
a true “gems-esque” packaging system.
&lt;/p&gt;
&lt;p&gt;
To install PowerKit, download the Install-PowerKit.ps1 script from the &lt;a href="http://www.codeplex.com/powerkits" target="_blank"&gt;CodePlex
site&lt;/a&gt;, more installation details are in the release notes on that page.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=ebff3ae0-84fe-4a4e-9dd8-531c9c469dee" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,ebff3ae0-84fe-4a4e-9dd8-531c9c469dee.aspx</comments>
      <category>CMPT 376</category>
      <category>PowerKit</category>
      <category>PowerShell</category>
    </item>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=3de21807-e19b-4541-a7d7-aadef6944140</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,3de21807-e19b-4541-a7d7-aadef6944140.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,3de21807-e19b-4541-a7d7-aadef6944140.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=3de21807-e19b-4541-a7d7-aadef6944140</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I recently used the ‘yield’ keyword in a C# method and ran into a strange issue when
trying to verify arguments.  I always try to verify the arguments provided to
my methods so that I can throw <code>ArgumentException</code> or <code>ArgumentNullException</code> as
necessary.  However, when you use the ‘yield’ keyword to create an enumerator
in C#, you can run into issues
</p>
        <p>
The ‘yield’ keyword lets you easily create a method which returns an enumerator (which
can then be used in a <code>foreach</code> loop).  For example, if I wanted to
make a method that took a <code>DirectoryInfo</code> (representing a directory on
disk) and returned file names of all the .txt files in it, I would write this:
</p>
        <pre class="csharp" name="code">public IEnumerable&lt;string&gt; GetTextFiles(DirectoryInfo dir) {
    if (dir == null) {
        throw new ArgumentNullException("dir");
    }
    foreach (FileInfo file in dir.GetFiles("*.txt")) {
        yield return file.Name;
    }
}</pre>
        <p>
However, the C# compiler will do something tricky with this method, because of the
'yield' keyword.  It will create a custom implementation of <code>IEnumerable&lt;string&gt;</code> class
that uses "magic" (I'm not going to go into detail as to how it works :P)
to jump in and out of the code you wrote. Then, it compiles our method to the following
(as decompiled with <a href="http://www.red-gate.com/products/reflector/" target="_blank">RedGate's
.Net Reflector</a>, a free tool every .Net developer <strong>must</strong> have :D):
</p>
        <pre class="csharp" name="code">public IEnumerable&lt;string&gt; GetTextFiles(DirectoryInfo dir)
{
    &lt;GetTextFiles&gt;d__0 d__ = new &lt;GetTextFiles&lt;d__0(-2);
    d__.&lt;&gt;4__this = this;
    d__.&lt;&gt;3__dir = dir;
    return d__;
}</pre>
        <p>
Wait a sec, where'd our code go?  It looks like it’s gone into this <code>&lt;GetTextFiles&gt;d__0</code> class. 
If you think that name sounds compiler-generated, you’re right!  It’s the custom
implementation of <code>IEnumerable&lt;string&gt;</code> that was created by the compiler. 
Cool, eh?  However, there’s a side effect here.  Where did our argument
checking code go?  Unless there’s something in the <code>&lt;GetTextFiles&gt;d__0</code> constructor,
the user could pass <code>null</code> in for the <code>dir</code> parameter and no
exception would be thrown!  So, let’s take a look at the <code>&lt;GetTextFiles&gt;d__0</code> constructor
(using Reflector again):
</p>
        <pre class="csharp" name="code">[DebuggerHidden]
public &lt;GetTextFiles&gt;d__0(int &lt;&gt;1__state)
{
    this.&lt;&gt;1__state = &lt;&gt;1__state;
    this.&lt;&gt;l__initialThreadId = Thread.CurrentThread.ManagedThreadId;
}</pre>
        <p>
Nope, nothing there.  If you keep checking around the <code>&lt;GetTextFiles&gt;d__0</code> class,
you’ll find it in the <code>MoveNext</code> method on that class.  That means
that instead of checking the argument when you call the method, the argument won’t
be checked until the first time <code>MoveNext</code> is called (i.e. the first iteration
of a foreach loop).  If, instead, we wrap the actual “yield” code in it’s own
method, and call it from our original method (after argument checks), we’ll get the
desired result:
</p>
        <pre>public IEnumerable&lt;string&gt; GetTextFiles(DirectoryInfo dir) {
    if (dir == null) {
        throw new ArgumentNullException("dir");
    }
    return InternalGetTextFiles(dir);
}
private IEnumerable&lt;string&gt; InternalGetTextFiles(DirectoryInfor dir) {
    foreach (FileInfo file in dir.GetFiles("*.txt")) {
        yield return file.Name;
    }
}</pre>
        <p>
Now, the "magic" is occurring in <code>InternalGetTextFiles</code> and <code>GetTextFiles</code> is
compiled without modification and our argument checking works just fine.
</p>
        <img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=3de21807-e19b-4541-a7d7-aadef6944140" />
      </body>
      <title>Argument check gotcha with &amp;lsquo;yield&amp;rsquo; keyword in C#</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,3de21807-e19b-4541-a7d7-aadef6944140.aspx</guid>
      <link>http://blog.andrewnurse.net/2009/02/02/ArgumentCheckGotchaWithLsquoyieldrsquoKeywordInC.aspx</link>
      <pubDate>Mon, 02 Feb 2009 22:46:13 GMT</pubDate>
      <description>&lt;p&gt;
I recently used the ‘yield’ keyword in a C# method and ran into a strange issue when
trying to verify arguments.&amp;#160; I always try to verify the arguments provided to
my methods so that I can throw &lt;code&gt;ArgumentException&lt;/code&gt; or &lt;code&gt;ArgumentNullException&lt;/code&gt; as
necessary.&amp;#160; However, when you use the ‘yield’ keyword to create an enumerator
in C#, you can run into issues
&lt;/p&gt;
&lt;p&gt;
The ‘yield’ keyword lets you easily create a method which returns an enumerator (which
can then be used in a &lt;code&gt;foreach&lt;/code&gt; loop).&amp;#160; For example, if I wanted to
make a method that took a &lt;code&gt;DirectoryInfo&lt;/code&gt; (representing a directory on
disk) and returned file names of all the .txt files in it, I would write this:
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;public IEnumerable&amp;lt;string&amp;gt; GetTextFiles(DirectoryInfo dir) {
    if (dir == null) {
        throw new ArgumentNullException(&amp;quot;dir&amp;quot;);
    }
    foreach (FileInfo file in dir.GetFiles(&amp;quot;*.txt&amp;quot;)) {
        yield return file.Name;
    }
}&lt;/pre&gt;
&lt;p&gt;
However, the C# compiler will do something tricky with this method, because of the
'yield' keyword.&amp;#160; It will create a custom implementation of &lt;code&gt;IEnumerable&amp;lt;string&amp;gt;&lt;/code&gt; class
that uses &amp;quot;magic&amp;quot; (I'm not going to go into detail as to how it works :P)
to jump in and out of the code you wrote. Then, it compiles our method to the following
(as decompiled with &lt;a href="http://www.red-gate.com/products/reflector/" target="_blank"&gt;RedGate's
.Net Reflector&lt;/a&gt;, a free tool every .Net developer &lt;strong&gt;must&lt;/strong&gt; have :D):
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;public IEnumerable&amp;lt;string&amp;gt; GetTextFiles(DirectoryInfo dir)
{
    &amp;lt;GetTextFiles&amp;gt;d__0 d__ = new &amp;lt;GetTextFiles&amp;lt;d__0(-2);
    d__.&amp;lt;&amp;gt;4__this = this;
    d__.&amp;lt;&amp;gt;3__dir = dir;
    return d__;
}&lt;/pre&gt;
&lt;p&gt;
Wait a sec, where'd our code go?&amp;#160; It looks like it’s gone into this &lt;code&gt;&amp;lt;GetTextFiles&amp;gt;d__0&lt;/code&gt; class.&amp;#160;
If you think that name sounds compiler-generated, you’re right!&amp;#160; It’s the custom
implementation of &lt;code&gt;IEnumerable&amp;lt;string&amp;gt;&lt;/code&gt; that was created by the compiler.&amp;#160;
Cool, eh?&amp;#160; However, there’s a side effect here.&amp;#160; Where did our argument
checking code go?&amp;#160; Unless there’s something in the &lt;code&gt;&amp;lt;GetTextFiles&amp;gt;d__0&lt;/code&gt; constructor,
the user could pass &lt;code&gt;null&lt;/code&gt; in for the &lt;code&gt;dir&lt;/code&gt; parameter and no
exception would be thrown!&amp;#160; So, let’s take a look at the &lt;code&gt;&amp;lt;GetTextFiles&amp;gt;d__0&lt;/code&gt; constructor
(using Reflector again):
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;[DebuggerHidden]
public &amp;lt;GetTextFiles&amp;gt;d__0(int &amp;lt;&amp;gt;1__state)
{
    this.&amp;lt;&amp;gt;1__state = &amp;lt;&amp;gt;1__state;
    this.&amp;lt;&amp;gt;l__initialThreadId = Thread.CurrentThread.ManagedThreadId;
}&lt;/pre&gt;
&lt;p&gt;
Nope, nothing there.&amp;#160; If you keep checking around the &lt;code&gt;&amp;lt;GetTextFiles&amp;gt;d__0&lt;/code&gt; class,
you’ll find it in the &lt;code&gt;MoveNext&lt;/code&gt; method on that class.&amp;#160; That means
that instead of checking the argument when you call the method, the argument won’t
be checked until the first time &lt;code&gt;MoveNext&lt;/code&gt; is called (i.e. the first iteration
of a foreach loop).&amp;#160; If, instead, we wrap the actual “yield” code in it’s own
method, and call it from our original method (after argument checks), we’ll get the
desired result:
&lt;/p&gt;
&lt;pre&gt;public IEnumerable&amp;lt;string&amp;gt; GetTextFiles(DirectoryInfo dir) {
    if (dir == null) {
        throw new ArgumentNullException(&amp;quot;dir&amp;quot;);
    }
    return InternalGetTextFiles(dir);
}
private IEnumerable&amp;lt;string&amp;gt; InternalGetTextFiles(DirectoryInfor dir) {
    foreach (FileInfo file in dir.GetFiles(&amp;quot;*.txt&amp;quot;)) {
        yield return file.Name;
    }
}&lt;/pre&gt;
&lt;p&gt;
Now, the &amp;quot;magic&amp;quot; is occurring in &lt;code&gt;InternalGetTextFiles&lt;/code&gt; and &lt;code&gt;GetTextFiles&lt;/code&gt; is
compiled without modification and our argument checking works just fine.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=3de21807-e19b-4541-a7d7-aadef6944140" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,3de21807-e19b-4541-a7d7-aadef6944140.aspx</comments>
      <category>CMPT 376</category>
      <category>Code Oddities</category>
      <category>Tips</category>
    </item>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=c585caa9-c80a-48db-af4c-78ba85e07132</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,c585caa9-c80a-48db-af4c-78ba85e07132.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,c585caa9-c80a-48db-af4c-78ba85e07132.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=c585caa9-c80a-48db-af4c-78ba85e07132</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
One of the most common checks I do is a simple null check on arguments being passed
in to the methods I write.  I usually create a static class called “Arg” with
the following methods (to help out):
</p>
        <pre class="csharp" name="code">public static class Arg {
    public static void NotNull(object value, string paramName) {
        if (value == null) {
            throw new ArgumentNullException(paramName);
        }
    }
    public static void NotNullOrEmpty(string value, string paramName) {
        if (String.IsNullOrEmpty(value)) {
            // ED: Error_StringArgumentNullOrEmpty is a key in my Visual Studio
            //  project's default string resources file (Properties/Resources.resx)
            throw new ArgumentException(
                String.Format(CultureInfo.CurrentCulture, 
                              Resources.Error_StringArgumentNullOrEmpty, 
                              paramName), 
                paramName);
        }
    }
}</pre>
        <p>
Then, I can use it like this
</p>
        <pre class="csharp" name="code">public void Foo(string arg, object reallyLongArgumentName) {
    Arg.NotNullOrEmpty(arg, "arg");
    Arg.NotNull(reallyLongArgumentName, "reallyLongArgumentName");
}</pre>
        <p>
I was recently playing with <a href="http://msdn.microsoft.com/en-us/library/bb397687.aspx" target="_blank">lambda
expressions</a> in C# and thought of a way to make this a little cooler.  The
result is, I can rewrite the lines above like this:
</p>
        <pre class="csharp" name="code">public void Foo(string arg, object reallyLongArgumentName) {
    Arg.NotNullOrEmpty(() =&gt; arg);
    Arg.NotNull(() =&gt; reallyLongArgumentName);
}</pre>
        <p>
The first obvious advantage is that for longer argument names, its more concise. 
The second, is that I no longer have to worry about updating the strings representing
the parameter names when I rename arguments, the Visual Studio Refactoring engine
will take care of it for me.
</p>
        <p>
Obviously, this is slower than the previous method since I’m diving into the lambda
expression at runtime, but its cool.  But if I need the performance, I have a
little Regular Expression I can run in Visual Studio to convert the lambda calls back
to the string versions (and vice-versa)
</p>
        <p>
How does it work? Well, the core of the code is a static helper in the <code>Arg</code> class
</p>
        <pre class="csharp" name="code">private static string GetParameterName&lt;T&gt;(Expression&lt;Func&lt;T&gt;&gt; paramExpr) {
    LambdaExpression lambda = paramExpr as LambdaExpression;
    Debug.Assert(lambda != null);
    MemberExpression paramRef = lambda.Body as MemberExpression;
    Debug.Assert(paramRef != null);

    // Get the parameter name
    string paramName = paramRef.Member.Name;
    return paramName;
}</pre>
        <p>
Lines 2-5 dive through the Expression tree to find the <code>MemberExpression</code> that
represents the parameter (i.e. "foo" in <code>() =&gt; foo</code>). Then, we pull
out the <code>MemberInfo</code> for the parameter and check the name. With that method,
the actual checker is easy:
</p>
        <pre class="csharp" name="code">public static void NotNull(Expression&lt;Func&lt;object&gt;&gt; paramExpr) {
    string paramName = GetParameterName(paramExpr);

    // Compile the lambda (to get the value)
    Func&lt;object&gt; compiledLambda = paramExpr.Compile();
    
    // Run the contract check
    NotNull(compiledLambda(), paramName);
}</pre>
        <p>
Line 2 extracts the parameter name. Line 5 compiles the lambda into an actual function
that will return the value of the parameter. Finally, Line 8 uses the value and the
parameter name to call my original <code>object/string</code> version. The code for <code>NotNullOrEmpty</code> is
nearly identical.
</p>
        <p>
Anyway, if you're concerned about performance, stick to the overloads which take the
parameter name directly. I’ve attached the code as a TXT file, just rename to C#,
change the namespace as appropriate and enjoy
</p>
        <a href="http://blog.andrewnurse.net/content/binary/Arg.txt">Arg.txt (3.93 KB)</a>
        <img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=c585caa9-c80a-48db-af4c-78ba85e07132" />
      </body>
      <title>Wild Ideas &amp;ndash; Using lambdas to check arguments in C#</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,c585caa9-c80a-48db-af4c-78ba85e07132.aspx</guid>
      <link>http://blog.andrewnurse.net/2009/01/30/WildIdeasNdashUsingLambdasToCheckArgumentsInC.aspx</link>
      <pubDate>Fri, 30 Jan 2009 07:45:51 GMT</pubDate>
      <description>&lt;p&gt;
One of the most common checks I do is a simple null check on arguments being passed
in to the methods I write.&amp;nbsp; I usually create a static class called “Arg” with
the following methods (to help out):
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;public static class Arg {
    public static void NotNull(object value, string paramName) {
        if (value == null) {
            throw new ArgumentNullException(paramName);
        }
    }
    public static void NotNullOrEmpty(string value, string paramName) {
        if (String.IsNullOrEmpty(value)) {
            // ED: Error_StringArgumentNullOrEmpty is a key in my Visual Studio
            //  project's default string resources file (Properties/Resources.resx)
            throw new ArgumentException(
                String.Format(CultureInfo.CurrentCulture, 
                              Resources.Error_StringArgumentNullOrEmpty, 
                              paramName), 
                paramName);
        }
    }
}&lt;/pre&gt;
&lt;p&gt;
Then, I can use it like this
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;public void Foo(string arg, object reallyLongArgumentName) {
    Arg.NotNullOrEmpty(arg, "arg");
    Arg.NotNull(reallyLongArgumentName, "reallyLongArgumentName");
}&lt;/pre&gt;
&lt;p&gt;
I was recently playing with &lt;a href="http://msdn.microsoft.com/en-us/library/bb397687.aspx" target="_blank"&gt;lambda
expressions&lt;/a&gt; in C# and thought of a way to make this a little cooler.&amp;nbsp; The
result is, I can rewrite the lines above like this:
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;public void Foo(string arg, object reallyLongArgumentName) {
    Arg.NotNullOrEmpty(() =&amp;gt; arg);
    Arg.NotNull(() =&amp;gt; reallyLongArgumentName);
}&lt;/pre&gt;
&lt;p&gt;
The first obvious advantage is that for longer argument names, its more concise.&amp;nbsp;
The second, is that I no longer have to worry about updating the strings representing
the parameter names when I rename arguments, the Visual Studio Refactoring engine
will take care of it for me.
&lt;/p&gt;
&lt;p&gt;
Obviously, this is slower than the previous method since I’m diving into the lambda
expression at runtime, but its cool.&amp;nbsp; But if I need the performance, I have a
little Regular Expression I can run in Visual Studio to convert the lambda calls back
to the string versions (and vice-versa)
&lt;/p&gt;
&lt;p&gt;
How does it work? Well, the core of the code is a static helper in the &lt;code&gt;Arg&lt;/code&gt; class
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;private static string GetParameterName&amp;lt;T&amp;gt;(Expression&amp;lt;Func&amp;lt;T&amp;gt;&amp;gt; paramExpr) {
    LambdaExpression lambda = paramExpr as LambdaExpression;
    Debug.Assert(lambda != null);
    MemberExpression paramRef = lambda.Body as MemberExpression;
    Debug.Assert(paramRef != null);

    // Get the parameter name
    string paramName = paramRef.Member.Name;
    return paramName;
}&lt;/pre&gt;
&lt;p&gt;
Lines 2-5 dive through the Expression tree to find the &lt;code&gt;MemberExpression&lt;/code&gt; that
represents the parameter (i.e. "foo" in &lt;code&gt;() =&amp;gt; foo&lt;/code&gt;). Then, we pull
out the &lt;code&gt;MemberInfo&lt;/code&gt; for the parameter and check the name. With that method,
the actual checker is easy:
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;public static void NotNull(Expression&amp;lt;Func&amp;lt;object&amp;gt;&amp;gt; paramExpr) {
    string paramName = GetParameterName(paramExpr);

    // Compile the lambda (to get the value)
    Func&amp;lt;object&amp;gt; compiledLambda = paramExpr.Compile();
    
    // Run the contract check
    NotNull(compiledLambda(), paramName);
}&lt;/pre&gt;
&lt;p&gt;
Line 2 extracts the parameter name. Line 5 compiles the lambda into an actual function
that will return the value of the parameter. Finally, Line 8 uses the value and the
parameter name to call my original &lt;code&gt;object/string&lt;/code&gt; version. The code for &lt;code&gt;NotNullOrEmpty&lt;/code&gt; is
nearly identical.
&lt;/p&gt;
&lt;p&gt;
Anyway, if you're concerned about performance, stick to the overloads which take the
parameter name directly. I’ve attached the code as a TXT file, just rename to C#,
change the namespace as appropriate and enjoy
&lt;/p&gt;
&lt;a href="http://blog.andrewnurse.net/content/binary/Arg.txt"&gt;Arg.txt (3.93 KB)&lt;/a&gt;&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=c585caa9-c80a-48db-af4c-78ba85e07132" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,c585caa9-c80a-48db-af4c-78ba85e07132.aspx</comments>
      <category>CMPT 376</category>
      <category>Random Stuff</category>
      <category>Tips</category>
      <category>Wild Ideas</category>
    </item>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=cbb29a9a-f33f-45e9-8836-47c73a0fd1a0</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,cbb29a9a-f33f-45e9-8836-47c73a0fd1a0.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,cbb29a9a-f33f-45e9-8836-47c73a0fd1a0.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=cbb29a9a-f33f-45e9-8836-47c73a0fd1a0</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Here comes part 3 of my infinite part series on developing a compiler from scratch. 
See all the posts <a href="http://blog.andrewnurse.net/CategoryView,category,Compiler%2BProject.aspx" target="_blank">here</a>.
</p>
        <p>
The first phase of compilation is called Tokenization.  Tokenization is the process
of taking individual characters in the source code file and grouping them into more
conceptual “Tokens.”  We’re not parsing the language, or checking syntax, we’re
just grouping related characters together.  Why do we do this?  If we skipped
this step, we’d be passing characters directly to our parser.  The parser doesn’t
care that the text contains the characters ‘f’ ‘o’ ‘o’, it cares that the source file
contains an Identifier called “foo”.  There’s also a separation of concerns issue. 
In theory, if you wanted to allow accented Unicode characters like è, ê, ã, à, etc.
(you may see blocks or ‘?’ characters instead of the real characters, if so just pretend
they’re there :D) as valid characters in identifiers, you should only have to change
the Tokenizer (to accept those characters and use them, along with the regular alphanumeric
characters, to build identifier tokens).  The formal name for Tokenization is
actually “Lexical Analysis,” and sometimes the Tokens are called “Atoms.”
</p>
        <p>
So, how do we Tokenize text?  There are lots of tools out there, most of which
let you define your tokens using Regular Expressions (so an identifier would be: “[_A-Za-z][_0-9A-Za-z]*”,
one letter or underscore followed by zero or more letters, numbers or underscores). 
These tools build state machines (aka “<a href="http://en.wikipedia.org/wiki/Finite_state_machine" target="_blank">Finite
Automata</a>”) that basically walk through all the Regular Expressions until exactly
one of them matches the current text buffer.  Tools like “<a href="http://en.wikipedia.org/wiki/Lex_programming_tool" target="_blank">lex</a>”
basically allow you to build a full-featured, efficient, Tokenizer by simply writing
Regular Expressions.
</p>
        <p>
However, that would be too easy for this series :).  Instead, I’m using a very
simple, hand-coded, Tokenizer which walks through the characters, using “if” and “switch”
statements to decide what tokens to output.  However, we can’t just simply iterate
through the characters.  Consider the ”-&gt;” operator in Duh (see <a href="http://blog.andrewnurse.net/2009/01/19/WritingACompilerFromScratchNdashPart1.aspx" target="_blank">Part
1</a>).  Duh supports the simple arithmetic operators, specifically “-“, and
I plan to support inequality operators (i.e “&lt;”, “&gt;”, etc.), so in theory, the
“-&gt;” operator could be outputted as a pair of tokens: MINUS and GREATERTHAN (I’ll
use ALLCAPS to denote the names of tokens).  However, this would be putting a
larger burden on the parser to detect the MINUS GREATERTHAN pattern.  Instead,
we can take advantage of “lookahead”
</p>
        <p>
The Tokenizer uses the .Net TextReader class, which lets us walk, one character at
a time, through the characters in a body of text.  However, once we’ve called
the <code>Read</code> method, the TextReader moves on to the next character and the
next time we call it, we’ll get the next character.  So, in order to properly
parse the “-&gt;” operator, we need a way to look at the next character, without moving
the reader.  Fortunately, the TextReader also has the <code>Peek</code> method,
which does exactly that.
</p>
        <p>
So now, when we encounter a “-“ symbol, we look at the next character.  If it
is a “&gt;”, we output an ARROW token, and move to the next character.  Otherwise,
we output a MINUS token and leave the reader at the “&gt;” character.  Then,
in the next iteration, we read the “&gt;” and output a GREATERTHAN token.
</p>
        <p>
Phew, that was a bit long, and more theoretical than I like, but I’ll post some code
in the next part.  Next time, we’ll look at the actual code for the Tokenizer.
</p>
        <img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=cbb29a9a-f33f-45e9-8836-47c73a0fd1a0" />
      </body>
      <title>Compiler from Scratch &amp;ndash; Part 3: Tokenization Overview</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,cbb29a9a-f33f-45e9-8836-47c73a0fd1a0.aspx</guid>
      <link>http://blog.andrewnurse.net/2009/01/28/CompilerFromScratchNdashPart3TokenizationOverview.aspx</link>
      <pubDate>Wed, 28 Jan 2009 19:13:12 GMT</pubDate>
      <description>&lt;p&gt;
Here comes part 3 of my infinite part series on developing a compiler from scratch.&amp;#160;
See all the posts &lt;a href="http://blog.andrewnurse.net/CategoryView,category,Compiler%2BProject.aspx" target="_blank"&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
The first phase of compilation is called Tokenization.&amp;#160; Tokenization is the process
of taking individual characters in the source code file and grouping them into more
conceptual “Tokens.”&amp;#160; We’re not parsing the language, or checking syntax, we’re
just grouping related characters together.&amp;#160; Why do we do this?&amp;#160; If we skipped
this step, we’d be passing characters directly to our parser.&amp;#160; The parser doesn’t
care that the text contains the characters ‘f’ ‘o’ ‘o’, it cares that the source file
contains an Identifier called “foo”.&amp;#160; There’s also a separation of concerns issue.&amp;#160;
In theory, if you wanted to allow accented Unicode characters like è, ê, ã, à, etc.
(you may see blocks or ‘?’ characters instead of the real characters, if so just pretend
they’re there :D) as valid characters in identifiers, you should only have to change
the Tokenizer (to accept those characters and use them, along with the regular alphanumeric
characters, to build identifier tokens).&amp;#160; The formal name for Tokenization is
actually “Lexical Analysis,” and sometimes the Tokens are called “Atoms.”
&lt;/p&gt;
&lt;p&gt;
So, how do we Tokenize text?&amp;#160; There are lots of tools out there, most of which
let you define your tokens using Regular Expressions (so an identifier would be: “[_A-Za-z][_0-9A-Za-z]*”,
one letter or underscore followed by zero or more letters, numbers or underscores).&amp;#160;
These tools build state machines (aka “&lt;a href="http://en.wikipedia.org/wiki/Finite_state_machine" target="_blank"&gt;Finite
Automata&lt;/a&gt;”) that basically walk through all the Regular Expressions until exactly
one of them matches the current text buffer.&amp;#160; Tools like “&lt;a href="http://en.wikipedia.org/wiki/Lex_programming_tool" target="_blank"&gt;lex&lt;/a&gt;”
basically allow you to build a full-featured, efficient, Tokenizer by simply writing
Regular Expressions.
&lt;/p&gt;
&lt;p&gt;
However, that would be too easy for this series :).&amp;#160; Instead, I’m using a very
simple, hand-coded, Tokenizer which walks through the characters, using “if” and “switch”
statements to decide what tokens to output.&amp;#160; However, we can’t just simply iterate
through the characters.&amp;#160; Consider the ”-&amp;gt;” operator in Duh (see &lt;a href="http://blog.andrewnurse.net/2009/01/19/WritingACompilerFromScratchNdashPart1.aspx" target="_blank"&gt;Part
1&lt;/a&gt;).&amp;#160; Duh supports the simple arithmetic operators, specifically “-“, and
I plan to support inequality operators (i.e “&amp;lt;”, “&amp;gt;”, etc.), so in theory, the
“-&amp;gt;” operator could be outputted as a pair of tokens: MINUS and GREATERTHAN (I’ll
use ALLCAPS to denote the names of tokens).&amp;#160; However, this would be putting a
larger burden on the parser to detect the MINUS GREATERTHAN pattern.&amp;#160; Instead,
we can take advantage of “lookahead”
&lt;/p&gt;
&lt;p&gt;
The Tokenizer uses the .Net TextReader class, which lets us walk, one character at
a time, through the characters in a body of text.&amp;#160; However, once we’ve called
the &lt;code&gt;Read&lt;/code&gt; method, the TextReader moves on to the next character and the
next time we call it, we’ll get the next character.&amp;#160; So, in order to properly
parse the “-&amp;gt;” operator, we need a way to look at the next character, without moving
the reader.&amp;#160; Fortunately, the TextReader also has the &lt;code&gt;Peek&lt;/code&gt; method,
which does exactly that.
&lt;/p&gt;
&lt;p&gt;
So now, when we encounter a “-“ symbol, we look at the next character.&amp;#160; If it
is a “&amp;gt;”, we output an ARROW token, and move to the next character.&amp;#160; Otherwise,
we output a MINUS token and leave the reader at the “&amp;gt;” character.&amp;#160; Then,
in the next iteration, we read the “&amp;gt;” and output a GREATERTHAN token.
&lt;/p&gt;
&lt;p&gt;
Phew, that was a bit long, and more theoretical than I like, but I’ll post some code
in the next part.&amp;#160; Next time, we’ll look at the actual code for the Tokenizer.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=cbb29a9a-f33f-45e9-8836-47c73a0fd1a0" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,cbb29a9a-f33f-45e9-8836-47c73a0fd1a0.aspx</comments>
      <category>CMPT 376</category>
      <category>Compiler Project</category>
    </item>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=6f7e4e4f-0d46-444f-b8df-91f2fa27a31d</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,6f7e4e4f-0d46-444f-b8df-91f2fa27a31d.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,6f7e4e4f-0d46-444f-b8df-91f2fa27a31d.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=6f7e4e4f-0d46-444f-b8df-91f2fa27a31d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.haacked.com" target="_blank">Phil Haack</a> (program manager on
the ASP.Net MVC team) just posted a <a href="http://haacked.com/archive/2009/01/27/aspnetmvc-release-candidate.aspx" target="_blank">blog
post</a> about the new Release Candidate of the MVC framework.  Since I got a
chance to work on the MVC framework team as an intern this summer (and I’m going back
full-time this summer), I’m pretty excited about the news.  When this goes RTM,
it’ll be the first time code that I wrote will be part of a full shipping Microsoft
product!  
</p>
        <p>
So download the binaries from <a href="http://www.asp.net/mvc/" target="_blank">ASP.Net</a> or
check out the source code on <a href="http://www.codeplex.com/aspnet/Wiki/View.aspx?title=MVC&amp;referringTitle=Home" target="_blank">CodePlex</a> and
have some fun!
</p>
        <p>
Also, check out <a href="http://weblogs.asp.net/scottgu/archive/2009/01/27/asp-net-mvc-1-0-release-candidate-now-available.aspx" target="_blank">Scott
Guthrie’s post on the new features</a>.  He shows off one of the features that,
I think, makes ASP.Net MVC more compelling than Ruby on Rails: Powerful first-party
tooling support.
</p>
        <img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=6f7e4e4f-0d46-444f-b8df-91f2fa27a31d" />
      </body>
      <title>ASP.Net MVC 1.0 Release Candidate released</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,6f7e4e4f-0d46-444f-b8df-91f2fa27a31d.aspx</guid>
      <link>http://blog.andrewnurse.net/2009/01/28/ASPNetMVC10ReleaseCandidateReleased.aspx</link>
      <pubDate>Wed, 28 Jan 2009 01:15:44 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://www.haacked.com" target="_blank"&gt;Phil Haack&lt;/a&gt; (program manager on
the ASP.Net MVC team) just posted a &lt;a href="http://haacked.com/archive/2009/01/27/aspnetmvc-release-candidate.aspx" target="_blank"&gt;blog
post&lt;/a&gt; about the new Release Candidate of the MVC framework.&amp;#160; Since I got a
chance to work on the MVC framework team as an intern this summer (and I’m going back
full-time this summer), I’m pretty excited about the news.&amp;#160; When this goes RTM,
it’ll be the first time code that I wrote will be part of a full shipping Microsoft
product!&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
So download the binaries from &lt;a href="http://www.asp.net/mvc/" target="_blank"&gt;ASP.Net&lt;/a&gt; or
check out the source code on &lt;a href="http://www.codeplex.com/aspnet/Wiki/View.aspx?title=MVC&amp;amp;referringTitle=Home" target="_blank"&gt;CodePlex&lt;/a&gt; and
have some fun!
&lt;/p&gt;
&lt;p&gt;
Also, check out &lt;a href="http://weblogs.asp.net/scottgu/archive/2009/01/27/asp-net-mvc-1-0-release-candidate-now-available.aspx" target="_blank"&gt;Scott
Guthrie’s post on the new features&lt;/a&gt;.&amp;#160; He shows off one of the features that,
I think, makes ASP.Net MVC more compelling than Ruby on Rails: Powerful first-party
tooling support.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=6f7e4e4f-0d46-444f-b8df-91f2fa27a31d" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,6f7e4e4f-0d46-444f-b8df-91f2fa27a31d.aspx</comments>
      <category>CMPT 376</category>
      <category>Microsoft Internship</category>
      <category>MVC</category>
    </item>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=fa257811-a414-419a-8ffd-57f889a3daa1</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,fa257811-a414-419a-8ffd-57f889a3daa1.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,fa257811-a414-419a-8ffd-57f889a3daa1.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=fa257811-a414-419a-8ffd-57f889a3daa1</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Well, this is a good sign, I’m posting part 2 :).  As I said in <a href="http://blog.andrewnurse.net/2009/01/19/WritingACompilerFromScratchNdashPart1.aspx" target="_blank">Part
1</a>, there are no promises here.  This series may not go anywhere, I may have
to drop it due to my other commitments (school, work, etc.).
</p>
        <p>
In the next few posts, I’m going to talk about the Tokenization phase of the compiler. 
Before I go into too much detail on that though, I want to talk about newlines.
</p>
        <p>
In Windows, a new line in a text file is indicated by a pair of characters: A Carriage
Return (commonly referred to as “\r'”, as that is the C/C++ string escape sequence
for it) followed by a Line Feed (”\n”).  However, in Unix-based operating systems,
a new line is often indicated by a Line Feed character alone.  To add even more
confusion, the Mac OS uses a Carriage Return character alone.  
</p>
        <p>
A compiler needs to track line numbers accurately, in order to report errors, so we
need be extra careful around newlines.  We could simply use the current operating
system’s default newline characters, but that makes it difficult for multi-platform
development.  Instead, we’ll normalize the newlines so that all three different
types are properly understood by our compiler.
</p>
        <p>
To do this, I’ve written a “Decorator” class which inherits from the abstract <code>TextReader</code> class
provided in the .Net framework.  This “Newline Normalizing” decorator wraps an
existing <code>TextReader</code> and does all the work of normalizing new line characters 
TextReader provides two methods that need to be implemented, <code>Read</code> and <code>Peek</code>.  <code>Read</code> returns
the current character from the text and moves the reader one character forwards (so
that the next call to Read will return the next character).  <code>Peek</code> also
returns the current character from the text but <strong>does not</strong> move the
reader forward.  The “Newline Normalizing” reader implements these two methods
using the following code
</p>
        <pre class="csharp" name="code">public override int Peek() {
    // Get the next character
    int i = Adaptee.Peek();
    
    // If the character is a '\r' newline, just return '\n'.  
    // Unlike Read, we aren't going to read ahead to check for \r\n
    // because that will happen when the user calls Read()
    if (i == (int)'\r') {
        i =  (int)'\n';
    }

    return i;
}

public override int Read() {
    // Get the next character
    int i = Adaptee.Read();

    // If the character is a '\r' newline, we're going to normalize it to '\n'
    // However, if the newline is '\r\n', we need to return it as one character, so
    // we check ahead for that
    if (i == (int)'\r') {
        if (Adaptee.Peek() == (int)'\n') {
            Adaptee.Read(); // Skip the '\n'
        }
        i = (int)'\n';
    }

    return i;
}</pre>
        <p>
Essentially, if the character we read from the source (the “Adaptee” as I call it)
is a ‘\n’, we just pass it along.  If the character is a ‘\r’, we are going to
return ‘\n’, but first we first check to see if it is immediately followed by a ‘\n’. 
If it is, we skip the extra character.  The result is that no matter which newline
sequence is used, this <code>TextReader</code> will return it as a single ‘\n’ character.
</p>
        <p>
Next post, I’ll start talking about the Tokenization process.
</p>
        <img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=fa257811-a414-419a-8ffd-57f889a3daa1" />
      </body>
      <title>Compiler from Scratch &amp;ndash; Part 2: Normalizing Newlines</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,fa257811-a414-419a-8ffd-57f889a3daa1.aspx</guid>
      <link>http://blog.andrewnurse.net/2009/01/25/CompilerFromScratchNdashPart2NormalizingNewlines.aspx</link>
      <pubDate>Sun, 25 Jan 2009 22:47:00 GMT</pubDate>
      <description>&lt;p&gt;
Well, this is a good sign, I’m posting part 2 :).&amp;#160; As I said in &lt;a href="http://blog.andrewnurse.net/2009/01/19/WritingACompilerFromScratchNdashPart1.aspx" target="_blank"&gt;Part
1&lt;/a&gt;, there are no promises here.&amp;#160; This series may not go anywhere, I may have
to drop it due to my other commitments (school, work, etc.).
&lt;/p&gt;
&lt;p&gt;
In the next few posts, I’m going to talk about the Tokenization phase of the compiler.&amp;#160;
Before I go into too much detail on that though, I want to talk about newlines.
&lt;/p&gt;
&lt;p&gt;
In Windows, a new line in a text file is indicated by a pair of characters: A Carriage
Return (commonly referred to as “\r'”, as that is the C/C++ string escape sequence
for it) followed by a Line Feed (”\n”).&amp;#160; However, in Unix-based operating systems,
a new line is often indicated by a Line Feed character alone.&amp;#160; To add even more
confusion, the Mac OS uses a Carriage Return character alone.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
A compiler needs to track line numbers accurately, in order to report errors, so we
need be extra careful around newlines.&amp;#160; We could simply use the current operating
system’s default newline characters, but that makes it difficult for multi-platform
development.&amp;#160; Instead, we’ll normalize the newlines so that all three different
types are properly understood by our compiler.
&lt;/p&gt;
&lt;p&gt;
To do this, I’ve written a “Decorator” class which inherits from the abstract &lt;code&gt;TextReader&lt;/code&gt; class
provided in the .Net framework.&amp;#160; This “Newline Normalizing” decorator wraps an
existing &lt;code&gt;TextReader&lt;/code&gt; and does all the work of normalizing new line characters&amp;#160;
TextReader provides two methods that need to be implemented, &lt;code&gt;Read&lt;/code&gt; and &lt;code&gt;Peek&lt;/code&gt;.&amp;#160; &lt;code&gt;Read&lt;/code&gt; returns
the current character from the text and moves the reader one character forwards (so
that the next call to Read will return the next character).&amp;#160; &lt;code&gt;Peek&lt;/code&gt; also
returns the current character from the text but &lt;strong&gt;does not&lt;/strong&gt; move the
reader forward.&amp;#160; The “Newline Normalizing” reader implements these two methods
using the following code
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;public override int Peek() {
    // Get the next character
    int i = Adaptee.Peek();
    
    // If the character is a '\r' newline, just return '\n'.  
    // Unlike Read, we aren't going to read ahead to check for \r\n
    // because that will happen when the user calls Read()
    if (i == (int)'\r') {
        i =  (int)'\n';
    }

    return i;
}

public override int Read() {
    // Get the next character
    int i = Adaptee.Read();

    // If the character is a '\r' newline, we're going to normalize it to '\n'
    // However, if the newline is '\r\n', we need to return it as one character, so
    // we check ahead for that
    if (i == (int)'\r') {
        if (Adaptee.Peek() == (int)'\n') {
            Adaptee.Read(); // Skip the '\n'
        }
        i = (int)'\n';
    }

    return i;
}&lt;/pre&gt;
&lt;p&gt;
Essentially, if the character we read from the source (the “Adaptee” as I call it)
is a ‘\n’, we just pass it along.&amp;#160; If the character is a ‘\r’, we are going to
return ‘\n’, but first we first check to see if it is immediately followed by a ‘\n’.&amp;#160;
If it is, we skip the extra character.&amp;#160; The result is that no matter which newline
sequence is used, this &lt;code&gt;TextReader&lt;/code&gt; will return it as a single ‘\n’ character.
&lt;/p&gt;
&lt;p&gt;
Next post, I’ll start talking about the Tokenization process.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=fa257811-a414-419a-8ffd-57f889a3daa1" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,fa257811-a414-419a-8ffd-57f889a3daa1.aspx</comments>
      <category>CMPT 376</category>
      <category>Compiler Project</category>
    </item>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=1b470301-0cfd-4e5c-ac71-6fefa51e8d3f</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,1b470301-0cfd-4e5c-ac71-6fefa51e8d3f.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,1b470301-0cfd-4e5c-ac71-6fefa51e8d3f.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=1b470301-0cfd-4e5c-ac71-6fefa51e8d3f</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
EDIT: Whoops, wrote the wrong course number (CMPT 376), corrected below.  I’m
taking CMPT 376, Writing for Computer Scientists, this semester, must have gotten
myself mixed up :)
</p>
        <p>
Ok, I’m going to try something here, and I don’t know if I’ll manage to finish it. 
My all-time favorite class in my school career (so far) has been CMPT 379 – Compiler
Design.  The class basically consisted of me writing a compiler in Visual C++,
with weekly lectures and code reviews from the professor (it was a small class). 
Since then, I’ve been trying to think of a reason to write a compiler (i.e. a language
that can be ported to .Net, or a useful domain-specific language, etc.).  Then,
this morning, as I walked back to the Computing Science common room from the Gym (after
my morning workout), I found a reason.  I think compilers are some of the most
interesting pieces of software, and I thought that if I wrote a series of blog posts
in which I developed a compiler, maybe I could share that passion with others.  
</p>
        <p>
So, here’s the plan:  I’ve designed an, extremely simple, language that I’m going
to walk through writing a compiler for.  The initial version will target .Net
IL code (since it’s a stack machine system, which is much easier to generate code
for).  Once I’ve implemented the simple language, I think it’d be awesome if
my readers could jump in and propose some ideas for new language features, and I’ll
try to blog about implementing them.
</p>
        <p>
To be honest, this project may well fall flat on its face.  Writing a compiler
is not a simple task, no matter how simple the language.  However, I do think
it will be fun (while it lasts), so let’s give it a try!
</p>
        <p>
So, step one is: Define your language!  The most essential part of compiler design
is having a very clear idea of the purpose of your language.  The language I’m
going to design is called “Duh”, because it’s probably about as simple as it gets
(maybe a little more complex than <a href="http://en.wikipedia.org/wiki/Brainf**k" target="_blank">Brainf**k</a> (NOTE:
link target does include a few four-letter words :D)).  Here’s a sample Duh program
</p>
        <pre class="csharp" name="code">print "Enter your age: ";
ageInput : string;
age : int;
ageInput = readline;
age = ageInput -&gt; int;
print "In 10 years you will be " + (age + 10) -&gt; string + ". Wow, that's old"</pre>
        <p>
Pretty simple, eh?  Line 1 is a simple print statement, which accepts a string
and write it to the console.  Lines 2 and 3 declare variables of string and 32-bit
integer types (decided to use a more Pascal-esque variable declaration format, just
for fun).  Lines 4 and 5 assign values to those variables.  Line 4 uses
another built-in function, readline, which reads a line of text from the console. 
Note that we don’t even support initializing variables in the declaration!  That’s
ok though, this is just a toy language, we can add initializations later.  Line
5 introduces the “-&gt;” conversion operator, which takes the value on the left and
converts it to the type on the right.  It’s not quite the same as a cast, because
it will try to convert the value, if it can.  Finally, we add 10 to the value
the user entered and convert it to a string, then we place that string into a large
message and print it to the console.
</p>
        <p>
Well, here goes nothing!  Feel free to post your initial comments.  I hope
you’ll follow along!  I’ll be posting full source code with every post
</p>
        <img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=1b470301-0cfd-4e5c-ac71-6fefa51e8d3f" />
      </body>
      <title>Writing a Compiler from Scratch &amp;ndash; Part 1</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,1b470301-0cfd-4e5c-ac71-6fefa51e8d3f.aspx</guid>
      <link>http://blog.andrewnurse.net/2009/01/19/WritingACompilerFromScratchNdashPart1.aspx</link>
      <pubDate>Mon, 19 Jan 2009 17:02:52 GMT</pubDate>
      <description>&lt;p&gt;
EDIT: Whoops, wrote the wrong course number (CMPT 376), corrected below.&amp;#160; I’m
taking CMPT 376, Writing for Computer Scientists, this semester, must have gotten
myself mixed up :)
&lt;/p&gt;
&lt;p&gt;
Ok, I’m going to try something here, and I don’t know if I’ll manage to finish it.&amp;#160;
My all-time favorite class in my school career (so far) has been CMPT 379 – Compiler
Design.&amp;#160; The class basically consisted of me writing a compiler in Visual C++,
with weekly lectures and code reviews from the professor (it was a small class).&amp;#160;
Since then, I’ve been trying to think of a reason to write a compiler (i.e. a language
that can be ported to .Net, or a useful domain-specific language, etc.).&amp;#160; Then,
this morning, as I walked back to the Computing Science common room from the Gym (after
my morning workout), I found a reason.&amp;#160; I think compilers are some of the most
interesting pieces of software, and I thought that if I wrote a series of blog posts
in which I developed a compiler, maybe I could share that passion with others.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
So, here’s the plan:&amp;#160; I’ve designed an, extremely simple, language that I’m going
to walk through writing a compiler for.&amp;#160; The initial version will target .Net
IL code (since it’s a stack machine system, which is much easier to generate code
for).&amp;#160; Once I’ve implemented the simple language, I think it’d be awesome if
my readers could jump in and propose some ideas for new language features, and I’ll
try to blog about implementing them.
&lt;/p&gt;
&lt;p&gt;
To be honest, this project may well fall flat on its face.&amp;#160; Writing a compiler
is not a simple task, no matter how simple the language.&amp;#160; However, I do think
it will be fun (while it lasts), so let’s give it a try!
&lt;/p&gt;
&lt;p&gt;
So, step one is: Define your language!&amp;#160; The most essential part of compiler design
is having a very clear idea of the purpose of your language.&amp;#160; The language I’m
going to design is called “Duh”, because it’s probably about as simple as it gets
(maybe a little more complex than &lt;a href="http://en.wikipedia.org/wiki/Brainf**k" target="_blank"&gt;Brainf**k&lt;/a&gt; (NOTE:
link target does include a few four-letter words :D)).&amp;#160; Here’s a sample Duh program
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;print &amp;quot;Enter your age: &amp;quot;;
ageInput : string;
age : int;
ageInput = readline;
age = ageInput -&amp;gt; int;
print &amp;quot;In 10 years you will be &amp;quot; + (age + 10) -&amp;gt; string + &amp;quot;. Wow, that's old&amp;quot;&lt;/pre&gt;
&lt;p&gt;
Pretty simple, eh?&amp;#160; Line 1 is a simple print statement, which accepts a string
and write it to the console.&amp;#160; Lines 2 and 3 declare variables of string and 32-bit
integer types (decided to use a more Pascal-esque variable declaration format, just
for fun).&amp;#160; Lines 4 and 5 assign values to those variables.&amp;#160; Line 4 uses
another built-in function, readline, which reads a line of text from the console.&amp;#160;
Note that we don’t even support initializing variables in the declaration!&amp;#160; That’s
ok though, this is just a toy language, we can add initializations later.&amp;#160; Line
5 introduces the “-&amp;gt;” conversion operator, which takes the value on the left and
converts it to the type on the right.&amp;#160; It’s not quite the same as a cast, because
it will try to convert the value, if it can.&amp;#160; Finally, we add 10 to the value
the user entered and convert it to a string, then we place that string into a large
message and print it to the console.
&lt;/p&gt;
&lt;p&gt;
Well, here goes nothing!&amp;#160; Feel free to post your initial comments.&amp;#160; I hope
you’ll follow along!&amp;#160; I’ll be posting full source code with every post
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=1b470301-0cfd-4e5c-ac71-6fefa51e8d3f" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,1b470301-0cfd-4e5c-ac71-6fefa51e8d3f.aspx</comments>
      <category>CMPT 376</category>
      <category>Compiler Project</category>
    </item>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=47d854de-b78f-48fc-bcbb-9d52535fb762</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,47d854de-b78f-48fc-bcbb-9d52535fb762.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,47d854de-b78f-48fc-bcbb-9d52535fb762.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=47d854de-b78f-48fc-bcbb-9d52535fb762</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I just had my first Windows 7 Blue Screen of Death :(.  However, it was my own
fault for trying to use an unsupported driver :P.  I had just listened to an
episode of <a href="http://twit.tv/sn" target="_blank">Security Now</a> on a tool
called <a href="http://www.sandboxie.com" target="_blank">Sandboxie</a>.  Sandboxie
is a tool which intercepts Windows API calls made by programs to read/write files
and registry keys.  Once intercepted, Sandboxie redirects them to files and registry
keys in a special “Sandbox”, so that changes made by programs are isolated from each
other.  It’s a cool security solution, and very similar in spirit to Microsoft’s <a href="http://www.microsoft.com/systemcenter/appv/default.mspx" target="_blank">App-V</a> platform
(only cheaper, and aimed at consumers rather than enterprises :D).
</p>
        <p>
In order to intercept the Windows API calls, however, Sandboxie has to install a kernel-mode
driver and patch the kernel.  In 64-bit versions of Windows, a system called
PatchGuard prevents this from happening, thus Sandboxie is not compatible with those
operating systems.  However, my laptop is running a 32-bit version of Windows
7, so I decided to try it out.
</p>
        <p>
At first, I got a compatibility message from the Sandboxie installer, telling me that
my OS is not supported.  That should have been my first clue :).  I decided
to take a gamble and try it out anyway, so I tweaked the compatibility settings for
the installer so that it ran in “Windows Vista” compatibility mode.  The installer
ran fine, and installed the software.  However, when I tried to run it, BAM,
BSOD :(.  
</p>
        <p>
Resigning myself to the fact that it just wasn’t ready for Windows 7, I booted up
in Safe Mode.  However, I was unable to run the installer again to remove it. 
I tried “Add/Remove Programs” and running the installer I downloaded again (in Vista
compatibility mode).  Still nothing.  Fortunately, I was just about to restart
for Windows Update when I installed Sandboxie, and Windows Update automatically creates
a System Restore point before installing updates.  I fired up System Restore,
picked the Windows Update restore point and let it do its thing.  The machine
rebooted, and I was back in action, with Sandboxie (and my BSODs) gone.  I had
lost the updates that WU installed, but that’s a minor inconvenience.
</p>
        <p>
Anyway, all is well now, and I was able to boot up again (in order to write this post
in fact :D).  So, two lessons here:
</p>
        <ol>
          <li>
Use System Restore!  Just remember to make restore points before installing software
that you are concerned about.  (Though that will NOT protect you from malicious
software, just incompatible software)</li>
          <li>
Check out Sandboxie, just not on Windows 7 :(.  My theory is that the PatchGuard
technology from the 64-bit OS may have been brought into the 32-bit OS.</li>
        </ol>
        <img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=47d854de-b78f-48fc-bcbb-9d52535fb762" />
      </body>
      <title>My First Windows 7 Blue-Screen &amp;ndash; But it was my fault :P</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,47d854de-b78f-48fc-bcbb-9d52535fb762.aspx</guid>
      <link>http://blog.andrewnurse.net/2009/01/15/MyFirstWindows7BlueScreenNdashButItWasMyFaultP.aspx</link>
      <pubDate>Thu, 15 Jan 2009 20:10:58 GMT</pubDate>
      <description>&lt;p&gt;
I just had my first Windows 7 Blue Screen of Death :(.&amp;#160; However, it was my own
fault for trying to use an unsupported driver :P.&amp;#160; I had just listened to an
episode of &lt;a href="http://twit.tv/sn" target="_blank"&gt;Security Now&lt;/a&gt; on a tool
called &lt;a href="http://www.sandboxie.com" target="_blank"&gt;Sandboxie&lt;/a&gt;.&amp;#160; Sandboxie
is a tool which intercepts Windows API calls made by programs to read/write files
and registry keys.&amp;#160; Once intercepted, Sandboxie redirects them to files and registry
keys in a special “Sandbox”, so that changes made by programs are isolated from each
other.&amp;#160; It’s a cool security solution, and very similar in spirit to Microsoft’s &lt;a href="http://www.microsoft.com/systemcenter/appv/default.mspx" target="_blank"&gt;App-V&lt;/a&gt; platform
(only cheaper, and aimed at consumers rather than enterprises :D).
&lt;/p&gt;
&lt;p&gt;
In order to intercept the Windows API calls, however, Sandboxie has to install a kernel-mode
driver and patch the kernel.&amp;#160; In 64-bit versions of Windows, a system called
PatchGuard prevents this from happening, thus Sandboxie is not compatible with those
operating systems.&amp;#160; However, my laptop is running a 32-bit version of Windows
7, so I decided to try it out.
&lt;/p&gt;
&lt;p&gt;
At first, I got a compatibility message from the Sandboxie installer, telling me that
my OS is not supported.&amp;#160; That should have been my first clue :).&amp;#160; I decided
to take a gamble and try it out anyway, so I tweaked the compatibility settings for
the installer so that it ran in “Windows Vista” compatibility mode.&amp;#160; The installer
ran fine, and installed the software.&amp;#160; However, when I tried to run it, BAM,
BSOD :(.&amp;#160; 
&lt;/p&gt;
&lt;p&gt;
Resigning myself to the fact that it just wasn’t ready for Windows 7, I booted up
in Safe Mode.&amp;#160; However, I was unable to run the installer again to remove it.&amp;#160;
I tried “Add/Remove Programs” and running the installer I downloaded again (in Vista
compatibility mode).&amp;#160; Still nothing.&amp;#160; Fortunately, I was just about to restart
for Windows Update when I installed Sandboxie, and Windows Update automatically creates
a System Restore point before installing updates.&amp;#160; I fired up System Restore,
picked the Windows Update restore point and let it do its thing.&amp;#160; The machine
rebooted, and I was back in action, with Sandboxie (and my BSODs) gone.&amp;#160; I had
lost the updates that WU installed, but that’s a minor inconvenience.
&lt;/p&gt;
&lt;p&gt;
Anyway, all is well now, and I was able to boot up again (in order to write this post
in fact :D).&amp;#160; So, two lessons here:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Use System Restore!&amp;#160; Just remember to make restore points before installing software
that you are concerned about.&amp;#160; (Though that will NOT protect you from malicious
software, just incompatible software)&lt;/li&gt;
&lt;li&gt;
Check out Sandboxie, just not on Windows 7 :(.&amp;#160; My theory is that the PatchGuard
technology from the 64-bit OS may have been brought into the 32-bit OS.&lt;/li&gt;
&lt;/ol&gt;
&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=47d854de-b78f-48fc-bcbb-9d52535fb762" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,47d854de-b78f-48fc-bcbb-9d52535fb762.aspx</comments>
      <category>CMPT 376</category>
      <category>Windows 7</category>
    </item>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=a97379a1-ad74-4a0a-9a2f-e5784a03b891</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,a97379a1-ad74-4a0a-9a2f-e5784a03b891.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,a97379a1-ad74-4a0a-9a2f-e5784a03b891.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=a97379a1-ad74-4a0a-9a2f-e5784a03b891</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
So, as an MSDN subscriber (no, I’m not made of money, Microsoft Interns get a free
year-long subscription to MSDN for personal use :P), I had access to the Windows 7
public beta a day early.  I decided to go crazy, since I’ve been hearing its
really stable, and put the latest OS on both my laptop <strong>and </strong>my desktop. 
(Well, I actually put Windows 7 Server, aka Windows Server 2008 R2 on my desktop). 
So, I figured I’d post my first impressions.
</p>
        <h2>Installation
</h2>
        <p>
There’s not much to say here, Installation is exactly like Windows Vista, only a little
faster.  The only new feature is that Windows 7 Setup prompts you to create a
HomeGroup, if you want.  HomeGroups are the new networking construct introduced
in Windows 7 designed to make it easier to share files and devices between networked
computers.  I haven’t had a change to check that out yet, so I’ll come back to
it later.
</p>
        <h2>Initial Impression
</h2>
        <p>
Besides a stylish new boot screen, in which four coloured dots dance around before
combining to form the Windows logo, the boot process is also identical to Windows
Vista.  I did find that it booted up much faster than Vista (though I can’t make
an accurate comparison, since my laptop was getting a bit overloaded).  The new
taskbar is very cool, and while it is a bit of a knock-off of the OSX Dock, I think
Microsoft has (in typical Microsoft fashion) gone above and beyond the OSX experience. 
For example, by hovering the mouse over an icon, a list of all the windows belonging
to that application appears.  Even better, applications which directly support
Windows 7 can add their own “windows” to this list.  For example, even though
I only have one IE8 window open, each tab in that window appears as a separate item
in the windows list.
</p>
        <p>
          <a href="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/Windows7FirstImpressions_CD0A/image_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Taskbar Windows List" border="0" alt="Taskbar Windows List" src="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/Windows7FirstImpressions_CD0A/image_thumb.png" width="716" height="264" />
          </a>
        </p>
        <p>
By hovering over each thumbnail, that window is brought to focus on the screen, and
the rest of the windows become “glass”.
</p>
        <p>
          <a href="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/Windows7FirstImpressions_CD0A/image_4.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Peeking at a Window" border="0" alt="Peeking at a Window" src="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/Windows7FirstImpressions_CD0A/image_thumb_1.png" width="644" height="337" />
          </a>
        </p>
        <p>
(And yes, I did blank out my Windows Messenger buddies list :P).
</p>
        <p>
Jump lists are another cool feature, but I haven’t had a chance to explore it much. 
Essentially, when you right click, or click and drag up on one of these taskbar icons,
a jump list appears.
</p>
        <p>
          <a href="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/Windows7FirstImpressions_CD0A/image_6.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="IE8 Jumplist" border="0" alt="IE8 Jumplist" src="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/Windows7FirstImpressions_CD0A/image_thumb_2.png" width="287" height="599" />
          </a>
        </p>
        <p>
In this case (Internet Explorer 8), my history is displayed.  Applications designed
for Windows 7, get a lot of control over this list, but applications which are not
designed to support it (PowerShell 2.0 for example) just get a simple default list
</p>
        <p>
          <a href="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/Windows7FirstImpressions_CD0A/image_8.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="PowerShell 2.0 Jumplist" border="0" alt="PowerShell 2.0 Jumplist" src="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/Windows7FirstImpressions_CD0A/image_thumb_3.png" width="298" height="131" />
          </a>
        </p>
        <h2>
        </h2>
        <p>
        </p>
        <p>
I haven’t had much of a chance to explore the rest of the new stuff, so I’ll post
more later, but my initial impression is that Windows 7 is just plain awesome :).
</p>
        <img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=a97379a1-ad74-4a0a-9a2f-e5784a03b891" />
      </body>
      <title>Windows 7 First Impressions</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,a97379a1-ad74-4a0a-9a2f-e5784a03b891.aspx</guid>
      <link>http://blog.andrewnurse.net/2009/01/13/Windows7FirstImpressions.aspx</link>
      <pubDate>Tue, 13 Jan 2009 22:35:29 GMT</pubDate>
      <description>&lt;p&gt;
So, as an MSDN subscriber (no, I’m not made of money, Microsoft Interns get a free
year-long subscription to MSDN for personal use :P), I had access to the Windows 7
public beta a day early.&amp;#160; I decided to go crazy, since I’ve been hearing its
really stable, and put the latest OS on both my laptop &lt;strong&gt;and &lt;/strong&gt;my desktop.&amp;#160;
(Well, I actually put Windows 7 Server, aka Windows Server 2008 R2 on my desktop).&amp;#160;
So, I figured I’d post my first impressions.
&lt;/p&gt;
&lt;h2&gt;Installation
&lt;/h2&gt;
&lt;p&gt;
There’s not much to say here, Installation is exactly like Windows Vista, only a little
faster.&amp;#160; The only new feature is that Windows 7 Setup prompts you to create a
HomeGroup, if you want.&amp;#160; HomeGroups are the new networking construct introduced
in Windows 7 designed to make it easier to share files and devices between networked
computers.&amp;#160; I haven’t had a change to check that out yet, so I’ll come back to
it later.
&lt;/p&gt;
&lt;h2&gt;Initial Impression
&lt;/h2&gt;
&lt;p&gt;
Besides a stylish new boot screen, in which four coloured dots dance around before
combining to form the Windows logo, the boot process is also identical to Windows
Vista.&amp;#160; I did find that it booted up much faster than Vista (though I can’t make
an accurate comparison, since my laptop was getting a bit overloaded).&amp;#160; The new
taskbar is very cool, and while it is a bit of a knock-off of the OSX Dock, I think
Microsoft has (in typical Microsoft fashion) gone above and beyond the OSX experience.&amp;#160;
For example, by hovering the mouse over an icon, a list of all the windows belonging
to that application appears.&amp;#160; Even better, applications which directly support
Windows 7 can add their own “windows” to this list.&amp;#160; For example, even though
I only have one IE8 window open, each tab in that window appears as a separate item
in the windows list.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/Windows7FirstImpressions_CD0A/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Taskbar Windows List" border="0" alt="Taskbar Windows List" src="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/Windows7FirstImpressions_CD0A/image_thumb.png" width="716" height="264" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
By hovering over each thumbnail, that window is brought to focus on the screen, and
the rest of the windows become “glass”.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/Windows7FirstImpressions_CD0A/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Peeking at a Window" border="0" alt="Peeking at a Window" src="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/Windows7FirstImpressions_CD0A/image_thumb_1.png" width="644" height="337" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
(And yes, I did blank out my Windows Messenger buddies list :P).
&lt;/p&gt;
&lt;p&gt;
Jump lists are another cool feature, but I haven’t had a chance to explore it much.&amp;#160;
Essentially, when you right click, or click and drag up on one of these taskbar icons,
a jump list appears.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/Windows7FirstImpressions_CD0A/image_6.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="IE8 Jumplist" border="0" alt="IE8 Jumplist" src="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/Windows7FirstImpressions_CD0A/image_thumb_2.png" width="287" height="599" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
In this case (Internet Explorer 8), my history is displayed.&amp;#160; Applications designed
for Windows 7, get a lot of control over this list, but applications which are not
designed to support it (PowerShell 2.0 for example) just get a simple default list
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/Windows7FirstImpressions_CD0A/image_8.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="PowerShell 2.0 Jumplist" border="0" alt="PowerShell 2.0 Jumplist" src="http://blog.andrewnurse.net/content/binary/WindowsLiveWriter/Windows7FirstImpressions_CD0A/image_thumb_3.png" width="298" height="131" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;h2&gt;
&lt;/h2&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
I haven’t had much of a chance to explore the rest of the new stuff, so I’ll post
more later, but my initial impression is that Windows 7 is just plain awesome :).
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=a97379a1-ad74-4a0a-9a2f-e5784a03b891" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,a97379a1-ad74-4a0a-9a2f-e5784a03b891.aspx</comments>
      <category>CMPT 376</category>
      <category>Cool Software</category>
      <category>Windows 7</category>
    </item>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=1969792d-8472-47ec-921e-72a202396ab0</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,1969792d-8472-47ec-921e-72a202396ab0.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,1969792d-8472-47ec-921e-72a202396ab0.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=1969792d-8472-47ec-921e-72a202396ab0</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
One of the courses I took last semester (Fall 2008), was “Software Engineering II”. 
In this class, we were required to work in groups to implement a project that the
professor specified.  We had to go through the whole process, design, implementation,
testing (though we could choose any software process model we wanted: Waterfall, XP,
Agile, etc.).  Our group’s project was an application called “Mappr” that would
allow users to browse a map.  Well, it was a little more than that, but that’s
all the background required by this post, I’ll post more background in future posts.
</p>
        <p>
One of the necessary components in mapping software is called a “Projection”. 
The Earth is round, and Latitude and Longitude co-ordinates are spherical measurements
representing points on the Earth.  In order to convert those co-ordinates to
(x, y) co-ordinates for displaying on a (flat) computer screen, you must <em>project</em> the
geographical co-ordinates into screen co-ordinates.  One well-known technique
for doing this is called the <a href="http://en.wikipedia.org/wiki/Mercator_projection">Mercator
Projection</a>.
</p>
        <p>
A quick aside: The Mercator Projection is widely known (in geography circles) for
being highly inaccurate.  However, it is the projection used by most road maps,
atlases, etc., both physical and digital.
</p>
        <p>
In Mappr, projection is handled by a component called a “Projection Strategy”. 
A Projection Strategy is a C# class (Mappr was written in C#) with two methods: GeoToScreen
and ScreenToGeo.   Here are the signatures of those methods:
</p>
        <pre class="csharp" name="code">public interface IProjectionStrategy {
    Point GeoToScreen(Point geographicalPoint, int zoomLevel, int tileSize);
    Point ScreenToGeo(Point screenPoint, int zoomLevel, int tileSize);
}</pre>
        <p>
The purpose of each method is straight forward: To take in either Geographical (Latitude,
Longitude) co-ordinates or Screen (X, Y) co-ordinates, and convert them to the other. 
In order to do this, we must know the Zoom Level, which is an integer <em>N</em> indicating
that there are <em>2<sup>N</sup></em> tiles on the screen.  We also need the
size, in pixels, of each map tile image.  This means that the size of the map,
in pixels, is given by: <em>2<sup>zoomLevel</sup> * tileSize</em>.
</p>
        <p>
The code to <em>project</em> a geographical point on to the screen is shown below:
</p>
        <pre class="csharp" name="code">public Point GeoToScreen(Point geographicalPoint, int zoomLevel, int tileSize) {
    // Convert to normalized mercator
    double lon = geographicalPoint.X;
    double lat = geographicalPoint.Y;

    if (lon &gt; 180) {
        lon -= 360;
    }

    lon /= 360;
    lon += 0.5;

    lat = 0.5 - ((Math.Log(Math.Tan((Math.PI / 4) + 
                 ((0.5 * Math.PI * lat) / 180))) / Math.PI) / 2.0);

    double scale = (1 &lt;&lt; zoomLevel) * tileSize;
    return new Point(lon * scale, lat * scale);
}</pre>
        <p>
This code first normalizes the longitude (X direction) so that it is in the range
0.0 to 1.0 (where 0.0 is the left of the map and 1.0 is the right).  Then it
does what I like to call “mathy stuff” (the calculations are taken from <a href="http://mapki.com/wiki/Tile_utility_code_in_Java">similar
code written in Java</a>) with the latitude to put it in the same range (0.0 is the
top, 1.0 is the bottom).  Finally, we calculate the scale of the map (height/width
in pixels, since the map is technically a square) and then we can use the normalized
longitude and latitude as ratios of that scale.
</p>
        <p>
The ScreenToGeo method is similar, the code is below.  I won’t describe this,
but just provide it for reference.
</p>
        <pre class="csharp" name="code">public Point ScreenToGeo(Point screenPoint, int zoomLevel, int tileSize) {
    int pixelSpan = (1 &lt;&lt; zoomLevel) * tileSize;
    double lngWidth = 360.0 / pixelSpan; // width in degrees longitude
    double lng = -180 + (screenPoint.X * lngWidth); // left edge in degrees longitude

    double latHeightMerc = 1.0 / pixelSpan; // height in "normalized" mercator 0,0 top left
    double latMerc = screenPoint.Y * latHeightMerc; // top edge in "normalized" mercator 0,0 top left
    
    // convert top and bottom lat in mercator to degrees
    // note that in fact the coordinates go from about -85 to +85 not -90 to 90!
    double lat = (180 / Math.PI) * ((2 * Math.Atan(Math.Exp(Math.PI * (1 - (2 * latMerc)))))
                       - (Math.PI / 2));

    return new Point(lng, lat);
}</pre>
        <p>
By the way, feel free to use any of the code in this post in your own application.
Consider it "Public Domain". However, I would appreciate (but not require)
if you would place a comment near it indicating that this blog is the source of the
original code.
</p>
        <p>
Hopefully this helps those of you writing mapping applications in C#!  Please
post any questions or comments in the comments section!
</p>
        <img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=1969792d-8472-47ec-921e-72a202396ab0" />
      </body>
      <title>Mappr: Projecting Geographical Points on the Screen</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,1969792d-8472-47ec-921e-72a202396ab0.aspx</guid>
      <link>http://blog.andrewnurse.net/2009/01/09/MapprProjectingGeographicalPointsOnTheScreen.aspx</link>
      <pubDate>Fri, 09 Jan 2009 18:07:54 GMT</pubDate>
      <description>&lt;p&gt;
One of the courses I took last semester (Fall 2008), was “Software Engineering II”.&amp;#160;
In this class, we were required to work in groups to implement a project that the
professor specified.&amp;#160; We had to go through the whole process, design, implementation,
testing (though we could choose any software process model we wanted: Waterfall, XP,
Agile, etc.).&amp;#160; Our group’s project was an application called “Mappr” that would
allow users to browse a map.&amp;#160; Well, it was a little more than that, but that’s
all the background required by this post, I’ll post more background in future posts.
&lt;/p&gt;
&lt;p&gt;
One of the necessary components in mapping software is called a “Projection”.&amp;#160;
The Earth is round, and Latitude and Longitude co-ordinates are spherical measurements
representing points on the Earth.&amp;#160; In order to convert those co-ordinates to
(x, y) co-ordinates for displaying on a (flat) computer screen, you must &lt;em&gt;project&lt;/em&gt; the
geographical co-ordinates into screen co-ordinates.&amp;#160; One well-known technique
for doing this is called the &lt;a href="http://en.wikipedia.org/wiki/Mercator_projection"&gt;Mercator
Projection&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
A quick aside: The Mercator Projection is widely known (in geography circles) for
being highly inaccurate.&amp;#160; However, it is the projection used by most road maps,
atlases, etc., both physical and digital.
&lt;/p&gt;
&lt;p&gt;
In Mappr, projection is handled by a component called a “Projection Strategy”.&amp;#160;
A Projection Strategy is a C# class (Mappr was written in C#) with two methods: GeoToScreen
and ScreenToGeo.&amp;#160;&amp;#160; Here are the signatures of those methods:
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;public interface IProjectionStrategy {
    Point GeoToScreen(Point geographicalPoint, int zoomLevel, int tileSize);
    Point ScreenToGeo(Point screenPoint, int zoomLevel, int tileSize);
}&lt;/pre&gt;
&lt;p&gt;
The purpose of each method is straight forward: To take in either Geographical (Latitude,
Longitude) co-ordinates or Screen (X, Y) co-ordinates, and convert them to the other.&amp;#160;
In order to do this, we must know the Zoom Level, which is an integer &lt;em&gt;N&lt;/em&gt; indicating
that there are &lt;em&gt;2&lt;sup&gt;N&lt;/sup&gt;&lt;/em&gt; tiles on the screen.&amp;#160; We also need the
size, in pixels, of each map tile image.&amp;#160; This means that the size of the map,
in pixels, is given by: &lt;em&gt;2&lt;sup&gt;zoomLevel&lt;/sup&gt; * tileSize&lt;/em&gt;.
&lt;/p&gt;
&lt;p&gt;
The code to &lt;em&gt;project&lt;/em&gt; a geographical point on to the screen is shown below:
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;public Point GeoToScreen(Point geographicalPoint, int zoomLevel, int tileSize) {
    // Convert to normalized mercator
    double lon = geographicalPoint.X;
    double lat = geographicalPoint.Y;

    if (lon &amp;gt; 180) {
        lon -= 360;
    }

    lon /= 360;
    lon += 0.5;

    lat = 0.5 - ((Math.Log(Math.Tan((Math.PI / 4) + 
                 ((0.5 * Math.PI * lat) / 180))) / Math.PI) / 2.0);

    double scale = (1 &amp;lt;&amp;lt; zoomLevel) * tileSize;
    return new Point(lon * scale, lat * scale);
}&lt;/pre&gt;
&lt;p&gt;
This code first normalizes the longitude (X direction) so that it is in the range
0.0 to 1.0 (where 0.0 is the left of the map and 1.0 is the right).&amp;#160; Then it
does what I like to call “mathy stuff” (the calculations are taken from &lt;a href="http://mapki.com/wiki/Tile_utility_code_in_Java"&gt;similar
code written in Java&lt;/a&gt;) with the latitude to put it in the same range (0.0 is the
top, 1.0 is the bottom).&amp;#160; Finally, we calculate the scale of the map (height/width
in pixels, since the map is technically a square) and then we can use the normalized
longitude and latitude as ratios of that scale.
&lt;/p&gt;
&lt;p&gt;
The ScreenToGeo method is similar, the code is below.&amp;#160; I won’t describe this,
but just provide it for reference.
&lt;/p&gt;
&lt;pre class="csharp" name="code"&gt;public Point ScreenToGeo(Point screenPoint, int zoomLevel, int tileSize) {
    int pixelSpan = (1 &amp;lt;&amp;lt; zoomLevel) * tileSize;
    double lngWidth = 360.0 / pixelSpan; // width in degrees longitude
    double lng = -180 + (screenPoint.X * lngWidth); // left edge in degrees longitude

    double latHeightMerc = 1.0 / pixelSpan; // height in &amp;quot;normalized&amp;quot; mercator 0,0 top left
    double latMerc = screenPoint.Y * latHeightMerc; // top edge in &amp;quot;normalized&amp;quot; mercator 0,0 top left
    
    // convert top and bottom lat in mercator to degrees
    // note that in fact the coordinates go from about -85 to +85 not -90 to 90!
    double lat = (180 / Math.PI) * ((2 * Math.Atan(Math.Exp(Math.PI * (1 - (2 * latMerc)))))
                       - (Math.PI / 2));

    return new Point(lng, lat);
}&lt;/pre&gt;
&lt;p&gt;
By the way, feel free to use any of the code in this post in your own application.
Consider it &amp;quot;Public Domain&amp;quot;. However, I would appreciate (but not require)
if you would place a comment near it indicating that this blog is the source of the
original code.
&lt;/p&gt;
&lt;p&gt;
Hopefully this helps those of you writing mapping applications in C#!&amp;#160; Please
post any questions or comments in the comments section!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=1969792d-8472-47ec-921e-72a202396ab0" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,1969792d-8472-47ec-921e-72a202396ab0.aspx</comments>
      <category>CMPT 376</category>
      <category>Cool Software</category>
      <category>School</category>
    </item>
    <item>
      <trackback:ping>http://blog.andrewnurse.net/Trackback.aspx?guid=08516539-8184-4044-a1ac-0b569ac2c6bc</trackback:ping>
      <pingback:server>http://blog.andrewnurse.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.andrewnurse.net/PermaLink,guid,08516539-8184-4044-a1ac-0b569ac2c6bc.aspx</pingback:target>
      <dc:creator>Andrew Nurse</dc:creator>
      <wfw:comment>http://blog.andrewnurse.net/CommentView,guid,08516539-8184-4044-a1ac-0b569ac2c6bc.aspx</wfw:comment>
      <wfw:commentRss>http://blog.andrewnurse.net/SyndicationService.asmx/GetEntryCommentsRss?guid=08516539-8184-4044-a1ac-0b569ac2c6bc</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The Spring semester at SFU is off to a running start (after a day lost to the snow),
and I’ve already got some homework to do!  One of the classes I’m taking is a
course titled “Writing for Computer Scientists”. The goal is to develop writing skills
through practice. Lots and lots of practice :).
</p>
        <p>
Each class (3 times a week), we’re required to submit some “writing”.  I use
quotes simply to emphasize the freedom of this assignment.  All I <strong>have</strong> to
do is write a single word, and turn it in each week.  Of course, that’s not really
the point of the assignment ;).  One option, provided by the professor, is simply
to start a blog (if you don’t already have one) and post 2-3 entries per week. 
Given that I already have a blog which I have had trouble maintaining, I figure this
is a good kick in the behind to get myself blogging again.  
</p>
        <p>
So, I’ll hopefully be blogging more often (at least while my grades depend on it :D). 
I’ll probably stick to the current subject of the blog: observations from an open-source
developer on the Microsoft ASP.Net platform.  Just in case I start to wander
to different topics, I’ll make sure to tag appropriately, so my normal readers can
subscribe just to the posts they’re interested in.
</p>
        <p>
It’s time to start blogging for fun and <strike>profit</strike> grades!
</p>
        <img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=08516539-8184-4044-a1ac-0b569ac2c6bc" />
      </body>
      <title>Writing a blog for fun and profit&amp;hellip; I mean grades</title>
      <guid isPermaLink="false">http://blog.andrewnurse.net/PermaLink,guid,08516539-8184-4044-a1ac-0b569ac2c6bc.aspx</guid>
      <link>http://blog.andrewnurse.net/2009/01/08/WritingABlogForFunAndProfithellipIMeanGrades.aspx</link>
      <pubDate>Thu, 08 Jan 2009 13:21:00 GMT</pubDate>
      <description>&lt;p&gt;
The Spring semester at SFU is off to a running start (after a day lost to the snow),
and I’ve already got some homework to do!&amp;nbsp; One of the classes I’m taking is a
course titled “Writing for Computer Scientists”. The goal is to develop writing skills
through practice. Lots and lots of practice :).
&lt;/p&gt;
&lt;p&gt;
Each class (3 times a week), we’re required to submit some “writing”.&amp;nbsp; I use
quotes simply to emphasize the freedom of this assignment.&amp;nbsp; All I &lt;strong&gt;have&lt;/strong&gt; to
do is write a single word, and turn it in each week.&amp;nbsp; Of course, that’s not really
the point of the assignment ;).&amp;nbsp; One option, provided by the professor, is simply
to start a blog (if you don’t already have one) and post 2-3 entries per week.&amp;nbsp;
Given that I already have a blog which I have had trouble maintaining, I figure this
is a good kick in the behind to get myself blogging again.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
So, I’ll hopefully be blogging more often (at least while my grades depend on it :D).&amp;nbsp;
I’ll probably stick to the current subject of the blog: observations from an open-source
developer on the Microsoft ASP.Net platform.&amp;nbsp; Just in case I start to wander
to different topics, I’ll make sure to tag appropriately, so my normal readers can
subscribe just to the posts they’re interested in.
&lt;/p&gt;
&lt;p&gt;
It’s time to start blogging for fun and &lt;strike&gt;profit&lt;/strike&gt; grades!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.andrewnurse.net/aggbug.ashx?id=08516539-8184-4044-a1ac-0b569ac2c6bc" /&gt;</description>
      <comments>http://blog.andrewnurse.net/CommentView,guid,08516539-8184-4044-a1ac-0b569ac2c6bc.aspx</comments>
      <category>CMPT 376</category>
      <category>School</category>
    </item>
  </channel>
</rss>