<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Inside F#</title>
	<atom:link href="http://lorgonblog.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://lorgonblog.wordpress.com</link>
	<description>Brian&#039;s thoughts on F# and .NET</description>
	<lastBuildDate>Sun, 08 May 2011 04:52:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='lorgonblog.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Inside F#</title>
		<link>http://lorgonblog.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://lorgonblog.wordpress.com/osd.xml" title="Inside F#" />
	<atom:link rel='hub' href='http://lorgonblog.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Gotcha explained</title>
		<link>http://lorgonblog.wordpress.com/2011/01/28/gotcha-explained/</link>
		<comments>http://lorgonblog.wordpress.com/2011/01/28/gotcha-explained/#comments</comments>
		<pubDate>Fri, 28 Jan 2011 18:54:57 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://lorgonblog.wordpress.com/2011/01/28/gotcha-explained/</guid>
		<description><![CDATA[Last time I posted a “gotcha” snippet, asking what this F# code prints: &#160;&#160;&#160; type MyVector(x:int, y:int, z:int) = &#160;&#160;&#160;&#160;&#160;&#160;&#160; // expose the values as an array &#160;&#160;&#160;&#160;&#160;&#160;&#160; member this.Values = [&#124; x; y; z &#124;] &#160;&#160;&#160; let v =&#160;new MyVector(1,2,3) &#160;&#160;&#160; v.Values.[0] &#60;- 42 &#160;&#160;&#160; printfn "%d" v.Values.[0] It prints “1”.&#160; To see why, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lorgonblog.wordpress.com&amp;blog=16474804&amp;post=238&amp;subd=lorgonblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://lorgonblog.wordpress.com/2011/01/26/come-work-on-f/">Last time</a> I posted a “gotcha” snippet, asking what this F# code prints:</p>
<pre style="font-family:consolas;">&nbsp;&nbsp;&nbsp; <span style="color:blue;">type</span> MyVector(x<span style="color:purple;">:</span>int, y<span style="color:purple;">:</span>int, z<span style="color:purple;">:</span>int) <span style="color:purple;">=</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green;">// expose the values as an array</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">member</span> this<span style="color:purple;">.</span>Values <span style="color:purple;">=</span> [| x; y; z |]

&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> v <span style="color:purple;">=</span>&nbsp;<span style="color:blue;">new</span> MyVector(1,2,3)
&nbsp;&nbsp;&nbsp; v<span style="color:purple;">.</span>Values<span style="color:purple;">.</span>[0] <span style="color:purple;">&lt;-</span> 42
&nbsp;&nbsp;&nbsp; printfn <span style="color:maroon;">"%d"</span> v<span style="color:purple;">.</span>Values<span style="color:purple;">.</span>[0]
</pre>
<p>It prints “1”.&nbsp; To see why, let’s look at the corresponding C# code, in all its verbosity:</p>
<pre style="font-family:consolas;">&nbsp;&nbsp;&nbsp; <span style="color:blue;">class</span>&nbsp;<span style="color:teal;">MyVector</span>
&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">int</span> x, y, z;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">public</span> MyVector(<span style="color:blue;">int</span> x, <span style="color:blue;">int</span> y, <span style="color:blue;">int</span> z)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">this</span><span style="color:purple;">.</span>x <span style="color:purple;">=</span> x;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">this</span><span style="color:purple;">.</span>y <span style="color:purple;">=</span> y;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">this</span><span style="color:purple;">.</span>z <span style="color:purple;">=</span> z;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green;">// expose the values as an array</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">public</span>&nbsp;<span style="color:blue;">int</span>[] Values
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">get</span> { <span style="color:blue;">return</span>&nbsp;<span style="color:blue;">new</span>[] { x, y, z }; }
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; <span style="color:blue;">class</span>&nbsp;<span style="color:teal;">Program</span>
&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">static</span>&nbsp;<span style="color:blue;">void</span> Main(<span style="color:blue;">string</span>[] args)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">var</span> v <span style="color:purple;">=</span>&nbsp;<span style="color:blue;">new</span>&nbsp;<span style="color:teal;">MyVector</span>(1, 2, 3);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v<span style="color:purple;">.</span>Values[0] <span style="color:purple;">=</span> 42;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System<span style="color:purple;">.</span><span style="color:teal;">Console</span><span style="color:purple;">.</span>WriteLine(v<span style="color:purple;">.</span>Values[0]);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; }
</pre>
<p>The C# code, being more explicit, makes things a little more obvious.&nbsp; “Values” is a getter property, whose body creates a new array, and so every time you refer to “.Values”, a fresh array is created that contains the 3 integers that were passed into the constructor.&nbsp; So the line that assigns the value 42 assigns it into a fresh array that is then immediately dropped on the floor.</p>
<p>This probably isn’t what is desired.&nbsp; If we want “Values” to expose a single instance of a mutable array, then we can easily do so, by creating that array instance in the class constructor and returning that same instance each time people refer to the property.&nbsp; In C#:</p>
<pre style="font-family:consolas;">&nbsp;&nbsp;&nbsp; <span style="color:blue;">class</span>&nbsp;<span style="color:teal;">MyVector</span>
&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">int</span>[] a;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">public</span> MyVector(<span style="color:blue;">int</span> x, <span style="color:blue;">int</span> y, <span style="color:blue;">int</span> z)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">this</span><span style="color:purple;">.</span>a <span style="color:purple;">=</span>&nbsp;<span style="color:blue;">new</span>[] { x, y, z };
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green;">// expose the values as an array</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">public</span>&nbsp;<span style="color:blue;">int</span>[] Values
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">get</span> { <span style="color:blue;">return</span> a; }
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; <span style="color:blue;">class</span>&nbsp;<span style="color:teal;">Program</span>
&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">static</span>&nbsp;<span style="color:blue;">void</span> Main(<span style="color:blue;">string</span>[] args)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">var</span> v <span style="color:purple;">=</span>&nbsp;<span style="color:blue;">new</span>&nbsp;<span style="color:teal;">MyVector</span>(1, 2, 3);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; v<span style="color:purple;">.</span>Values[0] <span style="color:purple;">=</span> 42;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System<span style="color:purple;">.</span><span style="color:teal;">Console</span><span style="color:purple;">.</span>WriteLine(v<span style="color:purple;">.</span>Values[0]);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; }</pre>
<p>and in F#:</p>
<pre style="font-family:consolas;">&nbsp;&nbsp;&nbsp; <span style="color:blue;">type</span> MyVector(x<span style="color:purple;">:</span>int, y<span style="color:purple;">:</span>int, z<span style="color:purple;">:</span>int) <span style="color:purple;">=</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> a <span style="color:purple;">=</span> [| x; y; z |]
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green;">// expose the values as an array</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">member</span> this<span style="color:purple;">.</span>Values <span style="color:purple;">=</span> a

&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> v <span style="color:purple;">=</span>&nbsp;<span style="color:blue;">new</span> MyVector(1,2,3)
&nbsp;&nbsp;&nbsp; v<span style="color:purple;">.</span>Values<span style="color:purple;">.</span>[0] <span style="color:purple;">&lt;-</span> 42
&nbsp;&nbsp;&nbsp; printfn <span style="color:maroon;">"%d"</span> v<span style="color:purple;">.</span>Values<span style="color:purple;">.</span>[0]
</pre>
<p>I see people occasionally stumble on this in a variety of ways; the fact that F# property getter syntax (and overall syntax) is so succinct makes it easier to forget that the body of the member is code that will run each time the member is referenced.&nbsp; One-time initialization should be moved to the constructor (the let/do section prior to the members; see <a href="http://lorgonblog.wordpress.com/2009/02/13/the-basic-syntax-of-f-classes-interfaces-and-members/">this blog</a> for a primer on the F# class/interface syntax). </p>
<p>Every language has its own little gotchas; at work those on the C# team still fall into the trap described <a href="http://lorgonblog.wordpress.com/2008/11/12/on-lambdas-capture-and-mutability/">here</a>, and so it is fun to josh each other about the minor warts in our respective languages.&nbsp; :)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lorgonblog.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lorgonblog.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lorgonblog.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lorgonblog.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/lorgonblog.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/lorgonblog.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/lorgonblog.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/lorgonblog.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lorgonblog.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lorgonblog.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lorgonblog.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lorgonblog.wordpress.com/238/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lorgonblog.wordpress.com/238/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lorgonblog.wordpress.com/238/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lorgonblog.wordpress.com&amp;blog=16474804&amp;post=238&amp;subd=lorgonblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://lorgonblog.wordpress.com/2011/01/28/gotcha-explained/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad588a46e9e78dced5c6dbcf1355bd09?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brianmcn</media:title>
		</media:content>
	</item>
		<item>
		<title>Come work on F#!</title>
		<link>http://lorgonblog.wordpress.com/2011/01/26/come-work-on-f/</link>
		<comments>http://lorgonblog.wordpress.com/2011/01/26/come-work-on-f/#comments</comments>
		<pubDate>Wed, 26 Jan 2011 16:51:18 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://lorgonblog.wordpress.com/2011/01/26/come-work-on-f/</guid>
		<description><![CDATA[In case you haven’t heard, the F# team is hiring.&#160; Want to work in Redmond as an F# developer, or a program manager, or a different developer?&#160; (Or perhaps just search with keyword “F#”, for other F#-related jobs at Microsoft.)&#160; See also Don’s blogs for info on applying.&#160; There’s also a contract position in the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lorgonblog.wordpress.com&amp;blog=16474804&amp;post=234&amp;subd=lorgonblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In case you haven’t heard, the F# team is hiring.&nbsp; Want to work in Redmond as an <a href="https://careers.microsoft.com/JobDetails.aspx?ss=&amp;pg=0&amp;so=&amp;rw=2&amp;jid=30512&amp;jlang=EN">F# developer</a>, or a <a href="https://careers.microsoft.com/JobDetails.aspx?ss=&amp;pg=0&amp;so=&amp;rw=1&amp;jid=33994&amp;jlang=EN">program manager</a>, or a <a href="https://careers.microsoft.com/JobDetails.aspx?ss=&amp;pg=0&amp;so=&amp;rw=3&amp;jid=34078&amp;jlang=EN">different developer</a>?&nbsp; (Or perhaps just <a href="https://careers.microsoft.com/Search.aspx">search</a> with keyword “F#”, for other F#-related jobs at Microsoft.)&nbsp; See also <a href="http://blogs.msdn.com/b/dsyme/archive/2010/12/02/come-and-join-the-f-compiler-amp-tools-team.aspx">Don’s</a> <a href="http://blogs.msdn.com/b/dsyme/archive/2011/01/23/the-f-team-are-hiring-come-and-be-the-senior-program-manager-for-f.aspx">blogs</a> for info on applying.&nbsp; There’s also a <a href="http://blogs.msdn.com/b/dsyme/archive/2011/01/26/f-team-contract-position-in-cambridge-uk.aspx">contract position</a> in the UK for applied F#.</p>
<p>Since I dislike code-free blogs, I’ll leave you with a quick code snippet.&nbsp; Ask yourself, what does this code print?&nbsp; (Then try it.)</p>
<pre style="font-family:consolas;background:white;color:black;">&nbsp;&nbsp;&nbsp; <span style="color:blue;">type</span> MyVector(x:int, y:int, z:int) =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green;">// expose the values as an array</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">member</span> this.Values = [| x; y; z |]

&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> v = <span style="color:blue;">new</span> MyVector(1,2,3)
&nbsp;&nbsp;&nbsp; v.Values.[0] &lt;- 42
&nbsp;&nbsp;&nbsp; printfn <span style="color:maroon;">"%d"</span> v.Values.[0]</pre>
<p>A hint: it illustrates a “gotcha” people sometimes hit when first learning the syntax for writing F# property getters.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lorgonblog.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lorgonblog.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lorgonblog.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lorgonblog.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/lorgonblog.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/lorgonblog.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/lorgonblog.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/lorgonblog.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lorgonblog.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lorgonblog.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lorgonblog.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lorgonblog.wordpress.com/234/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lorgonblog.wordpress.com/234/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lorgonblog.wordpress.com/234/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lorgonblog.wordpress.com&amp;blog=16474804&amp;post=234&amp;subd=lorgonblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://lorgonblog.wordpress.com/2011/01/26/come-work-on-f/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad588a46e9e78dced5c6dbcf1355bd09?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brianmcn</media:title>
		</media:content>
	</item>
		<item>
		<title>Source code for F# XmlDoc extension</title>
		<link>http://lorgonblog.wordpress.com/2010/12/04/source-code-for-f-xmldoc-extension/</link>
		<comments>http://lorgonblog.wordpress.com/2010/12/04/source-code-for-f-xmldoc-extension/#comments</comments>
		<pubDate>Sun, 05 Dec 2010 07:26:25 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://lorgonblog.wordpress.com/2010/12/04/source-code-for-f-xmldoc-extension/</guid>
		<description><![CDATA[I’ve just published the code for another VSIX extension; this one auto creates xml documentation boilerplate when you type triple-slash.&#160; For example, if you have the code: type SomeType() = &#160;&#160;&#160;&#160; member this.Foo(x:int, s:string) =&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; printfn "%d: %s" x s and you type “///” anywhere on the blank line before “Foo”, then you get [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lorgonblog.wordpress.com&amp;blog=16474804&amp;post=216&amp;subd=lorgonblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I’ve just <a href="https://github.com/brianmcn/FSharpXmlDoc">published the code</a> for another VSIX extension; this one auto creates xml documentation boilerplate when you type triple-slash.&nbsp; For example, if you have the code:</p>
<pre style="font-family:consolas;"><span style="color:blue;">type</span> SomeType() <span style="color:purple;">=</span>

&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">member</span> this<span style="color:purple;">.</span>Foo(x<span style="color:purple;">:</span>int, s<span style="color:purple;">:</span>string) <span style="color:purple;">=</span>&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printfn <span style="color:maroon;">"%d: %s"</span> x s</pre>
<p>and you type “///” anywhere on the blank line before “Foo”, then you get</p>
<pre style="font-family:consolas;"><span style="color:blue;">type</span> SomeType() <span style="color:purple;">=</span>
&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green;">/// &lt;summary&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green;">/// </span>
&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green;">/// &lt;/summary&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green;">/// &lt;param name="x"&gt;&lt;/param&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:green;">/// &lt;param name="s"&gt;&lt;/param&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">member</span> this<span style="color:purple;">.</span>Foo(x<span style="color:purple;">:</span>int, s<span style="color:purple;">:</span>string) <span style="color:purple;">=</span>&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printfn <span style="color:maroon;">"%d: %s"</span> x s</pre>
<p>with your cursor sitting conveniently between the summary tags.&nbsp; And if instead you type “///” above the type declaration, you get</p>
<pre style="font-family:consolas;"><span style="color:green;">/// &lt;summary&gt;</span>
<span style="color:green;">/// </span>
<span style="color:green;">/// &lt;/summary&gt;</span>
<span style="color:blue;">type</span> SomeType() <span style="color:purple;">=</span>

&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">member</span> this<span style="color:purple;">.</span>Foo(x<span style="color:purple;">:</span>int, s<span style="color:purple;">:</span>string) <span style="color:purple;">=</span>&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printfn <span style="color:maroon;">"%d: %s"</span> x s</pre>
<p>Get the idea?&nbsp; Just type “///” on a blank line right before a member, type, or module-scoped let (before any attributes, if there are any), and you get a blank xmldoc template (if there wasn’t already an xmldoc there).</p>
<p>I don’t plan to put this one on the <a href="http://visualstudiogallery.msdn.microsoft.com/en-us">gallery</a>, as I’m not too interested in maintaining it.&nbsp; You can <a href="https://github.com/brianmcn/FSharpXmlDoc">grab the the source from github</a>, set the VSIX project as the startup project, and build it yourself.&nbsp; (If someone is interested in refining/publishing it, you can contact me directly.)&nbsp; </p>
<p>The source code is simple, and structured just like <a href="http://lorgonblog.wordpress.com/2010/11/21/source-code-for-f-depth-colorizer-extension/">my previous extension</a>.&nbsp; There are two projects. “MyFSParser” is (again) just the parser code ripped from the F# compiler, with about 130 new lines of code at the end of <a href="https://github.com/brianmcn/FSharpXmlDoc/blob/master/FSXmlDocVSIX/MyParser/MyParsing.fs">MyParsing.fs</a> that computes information about every xml-doc-able entity in a file.&nbsp; “FSXmlDocVSIX” is the editor extension that, in a mere 120 lines of code in <a href="https://github.com/brianmcn/FSharpXmlDoc/blob/master/FSXmlDocVSIX/VSIX/Program.fs">Program.fs</a>, intercepts keypresses and does some special logic when you press ‘/’ to see if you just typed “///” on a blank line above an xml-doc-able, and if so, dumps extra stuff into your editor buffer.&nbsp; It’s really simple; if you ever wanted to look at a straightforward extension to the Visual Studio editor, this is a good code sample.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lorgonblog.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lorgonblog.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lorgonblog.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lorgonblog.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/lorgonblog.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/lorgonblog.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/lorgonblog.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/lorgonblog.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lorgonblog.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lorgonblog.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lorgonblog.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lorgonblog.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lorgonblog.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lorgonblog.wordpress.com/216/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lorgonblog.wordpress.com&amp;blog=16474804&amp;post=216&amp;subd=lorgonblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://lorgonblog.wordpress.com/2010/12/04/source-code-for-f-xmldoc-extension/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad588a46e9e78dced5c6dbcf1355bd09?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brianmcn</media:title>
		</media:content>
	</item>
		<item>
		<title>Source code for F# Depth Colorizer extension</title>
		<link>http://lorgonblog.wordpress.com/2010/11/21/source-code-for-f-depth-colorizer-extension/</link>
		<comments>http://lorgonblog.wordpress.com/2010/11/21/source-code-for-f-depth-colorizer-extension/#comments</comments>
		<pubDate>Sun, 21 Nov 2010 21:39:20 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://lorgonblog.wordpress.com/2010/11/21/source-code-for-f-depth-colorizer-extension/</guid>
		<description><![CDATA[I’ve published the source code for the F# Depth Colorizer.&#160; You can get the code from github.&#160; The code is available under the Apache 2.0 License. Here’s a quick overview of what’s there.&#160; There is a Visual Studio 2010 solution with two projects.&#160; The “MyFSParser” project is a library that parses F# source code and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lorgonblog.wordpress.com&amp;blog=16474804&amp;post=213&amp;subd=lorgonblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I’ve published the source code for the <a href="http://lorgonblog.wordpress.com/2010/11/18/f-source-code-structural-colorizer-available/">F# Depth Colorizer</a>.&nbsp; You can get the code from <a href="https://github.com/brianmcn/FSharpDepthColorizer">github</a>.&nbsp; The code is available under the Apache 2.0 License.</p>
<p>Here’s a quick overview of what’s there.&nbsp; There is a Visual Studio 2010 solution with two projects.&nbsp; </p>
<ul>
<li>The “MyFSParser” project is a library that parses F# source code and yields “range” information about where source code constructs begin and end.&nbsp; It is basically a free-standing version of the front half of the F# compiler, followed by about 350 lines of my own code for munging and publishing range information from the abstract syntax tree (AST) produced by the F# compiler front end.</li>
<li>The “VSIXColorizer” project is a Visual Studio extension that plug into the editor, listens for changes in the test buffer, re-parses the source, gets the range information, tags editor ‘spans’ with the semantic depth information, and then draws adornments on the screen for the portions of the file in view.&nbsp; It’s also about 350 lines of code.</li>
</ul>
<p>Of course all the code is written in F#.&nbsp; This is a nice sample that demonstrates both the simple Visual Studio extensibility model that makes it easy to craft editor extensions, as well as the kinds of things you can do when you leverage the F# compiler source to do the “heavy lifting” to parse F# code for you.</p>
<p>In order to provide a little more guidance, I made a couple screencasts, about 10 minutes each, where I give a (rambling) walkthrough of each of the projects.&nbsp; You won’t learn all the fine details about how the compiler code or my code works, but you will get an overview of the structure and see some of the important methods/functions and how the pieces fit together.&nbsp; Here is the <a href="http://brianmcn.members.winisp.net/FSDCMyParser1.wmv">video about the parser</a> and here is the <a href="http://brianmcn.members.winisp.net/FSDCVSIX.wmv">video about the colorizer</a>.</p>
<p>I’ve already started working on another editor extension that reuses the parser library code, and so in another week or two hopefully I’ll share that too.&nbsp; I hope this is good “seed code” to help you leverage the F# compiler source and Visual Studio extensibility to do your own cool stuff!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lorgonblog.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lorgonblog.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lorgonblog.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lorgonblog.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/lorgonblog.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/lorgonblog.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/lorgonblog.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/lorgonblog.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lorgonblog.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lorgonblog.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lorgonblog.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lorgonblog.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lorgonblog.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lorgonblog.wordpress.com/213/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lorgonblog.wordpress.com&amp;blog=16474804&amp;post=213&amp;subd=lorgonblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://lorgonblog.wordpress.com/2010/11/21/source-code-for-f-depth-colorizer-extension/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
<enclosure url="http://brianmcn.members.winisp.net/FSDCMyParser1.wmv" length="73905817" type="video/asf" />
<enclosure url="http://brianmcn.members.winisp.net/FSDCVSIX.wmv" length="53769013" type="video/asf" />
	
		<media:content url="http://0.gravatar.com/avatar/ad588a46e9e78dced5c6dbcf1355bd09?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brianmcn</media:title>
		</media:content>
	</item>
		<item>
		<title>A quick standalone app to edit colors for the F# colorizer</title>
		<link>http://lorgonblog.wordpress.com/2010/11/20/a-quick-standalone-app-to-edit-colors-for-the-f-colorizer/</link>
		<comments>http://lorgonblog.wordpress.com/2010/11/20/a-quick-standalone-app-to-edit-colors-for-the-f-colorizer/#comments</comments>
		<pubDate>Sat, 20 Nov 2010 20:59:21 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://lorgonblog.wordpress.com/2010/11/20/a-quick-standalone-app-to-edit-colors-for-the-f-colorizer/</guid>
		<description><![CDATA[What kind of fool posts a cool extension for colorizing F# source code structure, but then only lets you configure the colors by editing the registry (and then having to restart Visual Studio to see if the new colors look ok)? Oh, that was me.&#160; :) Like I said in the previous blog, I don’t [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lorgonblog.wordpress.com&amp;blog=16474804&amp;post=209&amp;subd=lorgonblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>What kind of fool posts a <a href="http://lorgonblog.wordpress.com/2010/11/18/f-source-code-structural-colorizer-available/">cool extension for colorizing F# source code structure</a>, but then only lets you configure the colors by editing the registry (and then having to restart Visual Studio to see if the new colors look ok)?</p>
<p>Oh, that was me.&nbsp; :)</p>
<p>Like I said in the previous blog, I don’t have the skills to design a good GUI to edit the colors or figure out the most discoverable place in VS to edit them.&nbsp; But maybe you do!&nbsp; And so in the spirit of sharing source, here’s a crummy (but working) standalone app for experimenting with the colors.&nbsp; A screenshot is suggestive:</p>
<p><a href="http://lorgonblog.files.wordpress.com/2010/11/fscoloreditor.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="FSColorEditor" border="0" alt="FSColorEditor" src="http://lorgonblog.files.wordpress.com/2010/11/fscoloreditor_thumb.png?w=804&#038;h=488" width="804" height="488"></a></p>
<p>Basically, you can click on one of the rectangles, and then use the buttons to change the R/G/B values of the left-edge color or the main color.&nbsp; And once you have colors you like, you can click a different button which prints out a .reg file you can use to install those colors.&nbsp; (The app only reads the registry, it does not write it, so you have to copy-paste the text from the console window, save it to a .reg file, and run it if you want to install your updated colors.)</p>
<p>Anyway, the code is below.&nbsp; Just throw this in an F# Console Application, add references to the WPF assemblies (PresentationCore, PresentationFramework, System.Xaml, System.Xml, UIAutomationTypes, and WindowsBase), press Ctrl-F5 to build and run and you’re off to the races.&nbsp; Feel free to steal all this code to build your own better app/extension, or just to use to build your own attractive color schemes.&nbsp; The code is just a quick ugly hack, but hopefully you can work with it.</p>
<p>And yes, I’ll be releasing the code for the actual editor colorizer extension <a href="http://lorgonblog.wordpress.com/2010/11/21/source-code-for-f-depth-colorizer-extension/">soon</a>, I just want to finish tidying it up a little.&nbsp; (Thanks to those who have already left feedback and pointed out minor bugs!)</p>
<p>Quickie code for app to manage editing colors:</p>
<pre style="font-family:consolas;"><span style="color:blue;">open</span> System<span style="color:purple;">.</span>Windows
<span style="color:blue;">open</span> System<span style="color:purple;">.</span>Windows<span style="color:purple;">.</span>Controls
<span style="color:blue;">open</span> System<span style="color:purple;">.</span>Windows<span style="color:purple;">.</span>Data
<span style="color:blue;">open</span> System<span style="color:purple;">.</span>Windows<span style="color:purple;">.</span>Media
<span style="color:blue;">open</span> System<span style="color:purple;">.</span>Windows<span style="color:purple;">.</span>Shapes
<span style="color:blue;">open</span> Microsoft<span style="color:purple;">.</span>Win32 

<span style="color:blue;">type</span> IIndexable<span style="color:purple;">&lt;'</span>a<span style="color:purple;">&gt;</span>&nbsp;<span style="color:purple;">=</span>
&nbsp;&nbsp;&nbsp; <span style="color:blue;">abstract</span>&nbsp;<span style="color:blue;">member</span> Item <span style="color:purple;">:</span> int <span style="color:blue;">-&gt;</span>&nbsp;<span style="color:purple;">'</span>a

<span style="color:blue;">let</span> makeBinding(sourceObj<span style="color:purple;">:</span>obj, sourcePath<span style="color:purple;">:</span>string, converter<span style="color:purple;">:'</span>T<span style="color:blue;">-&gt;</span><span style="color:purple;">'</span>U,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; targetObj<span style="color:purple;">:</span>DependencyObject, targetDependencyProperty<span style="color:purple;">:</span>DependencyProperty) <span style="color:purple;">=</span>
&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> b <span style="color:purple;">=</span>&nbsp;<span style="color:blue;">new</span> System<span style="color:purple;">.</span>Windows<span style="color:purple;">.</span>Data<span style="color:purple;">.</span>Binding()
&nbsp;&nbsp;&nbsp; b<span style="color:purple;">.</span>Source <span style="color:purple;">&lt;-</span> sourceObj
&nbsp;&nbsp;&nbsp; b<span style="color:purple;">.</span>Path <span style="color:purple;">&lt;-</span>&nbsp;<span style="color:blue;">new</span> System<span style="color:purple;">.</span>Windows<span style="color:purple;">.</span>PropertyPath(sourcePath)
&nbsp;&nbsp;&nbsp; b<span style="color:purple;">.</span>Converter <span style="color:purple;">&lt;-</span>&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <span style="color:blue;">new</span> System<span style="color:purple;">.</span>Windows<span style="color:purple;">.</span>Data<span style="color:purple;">.</span>IValueConverter <span style="color:blue;">with</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">member</span> this<span style="color:purple;">.</span>Convert(v, targetType, param, culInfo) <span style="color:purple;">=</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; box(converter (unbox v))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">member</span> this<span style="color:purple;">.</span>ConvertBack(v, targetType, param, culInfo) <span style="color:purple;">=</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; raise <span style="color:purple;">&lt;|</span>&nbsp;<span style="color:blue;">new</span> System<span style="color:purple;">.</span>NotImplementedException() }
&nbsp;&nbsp;&nbsp; BindingOperations<span style="color:purple;">.</span>SetBinding(targetObj, targetDependencyProperty, b) <span style="color:purple;">|&gt;</span> ignore

<span style="color:blue;">type</span> MyWindow() <span style="color:blue;">as</span> this <span style="color:purple;">=</span>
&nbsp;&nbsp;&nbsp; <span style="color:blue;">inherit</span> Window()

&nbsp;&nbsp;&nbsp; <span style="color:blue;">static</span>&nbsp;<span style="color:blue;">let</span> selectedRectangleNumber <span style="color:purple;">=</span>&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DependencyProperty<span style="color:purple;">.</span>Register(<span style="color:maroon;">"SelectedRectangleNumber"</span>, typeof<span style="color:purple;">&lt;</span>int<span style="color:purple;">&gt;</span>, typeof<span style="color:purple;">&lt;</span>MyWindow<span style="color:purple;">&gt;</span>,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">new</span> FrameworkPropertyMetadata(0, FrameworkPropertyMetadataOptions<span style="color:purple;">.</span>AffectsRender,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">new</span> PropertyChangedCallback(<span style="color:blue;">fun</span> depObj ea <span style="color:blue;">-&gt;</span>&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">match</span> box depObj, box ea<span style="color:purple;">.</span>NewValue <span style="color:blue;">with</span>&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | (<span style="color:purple;">:?</span> MyWindow <span style="color:blue;">as</span> w), (<span style="color:purple;">:?</span> int <span style="color:blue;">as</span> x) <span style="color:blue;">-&gt;</span> w<span style="color:purple;">.</span>TriggerSelectedRectangleNumberChanged(x)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | _ <span style="color:blue;">-&gt;</span> ())))

&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> selectedChanged <span style="color:purple;">=</span>&nbsp;<span style="color:blue;">new</span> Event<span style="color:purple;">&lt;</span>Handler<span style="color:purple;">&lt;</span>int<span style="color:purple;">&gt;</span>,int<span style="color:purple;">&gt;</span>()
&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> getNum() <span style="color:purple;">=</span> this<span style="color:purple;">.</span>GetValue(MyWindow<span style="color:purple;">.</span>SelectedRectangleNumber) <span style="color:purple;">:?&gt;</span> int
&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> setNum(n) <span style="color:purple;">=</span> this<span style="color:purple;">.</span>SetValue(MyWindow<span style="color:purple;">.</span>SelectedRectangleNumber, n)

&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> colors <span style="color:purple;">=</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">try</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> key <span style="color:purple;">=</span> Registry<span style="color:purple;">.</span>CurrentUser<span style="color:purple;">.</span>OpenSubKey(
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:maroon;">@"Software\Microsoft\VisualStudio\10.0\Text Editor\FSharpDepthColorizer"</span>)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Array<span style="color:purple;">.</span>init 10 (<span style="color:blue;">fun</span> i <span style="color:blue;">-&gt;</span> key<span style="color:purple;">.</span>GetValue(sprintf <span style="color:maroon;">"Depth%d"</span> i) <span style="color:purple;">:?&gt;</span> string)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:purple;">|&gt;</span> Array<span style="color:purple;">.</span>map (<span style="color:blue;">fun</span> s <span style="color:blue;">-&gt;</span>&nbsp;<span style="color:blue;">let</span> [|r1;g1;b1;r2;g2;b2|] <span style="color:purple;">=</span> s<span style="color:purple;">.</span>Split[|<span style="color:maroon;">','</span>|] <span style="color:purple;">|&gt;</span> Array<span style="color:purple;">.</span>map byte
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; r1,g1,b1,r2,g2,b2)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">with</span> e <span style="color:blue;">-&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [|&nbsp; <span style="color:green;">// greyscale colors</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 190uy,190uy,190uy,230uy,230uy,230uy
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 170uy,170uy,170uy,210uy,210uy,210uy
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 184uy,184uy,184uy,224uy,224uy,224uy
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 164uy,164uy,164uy,204uy,204uy,204uy
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 178uy,178uy,178uy,218uy,218uy,218uy
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 158uy,158uy,158uy,198uy,198uy,198uy
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 172uy,172uy,172uy,212uy,212uy,212uy
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 152uy,152uy,152uy,192uy,192uy,192uy
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 166uy,166uy,166uy,206uy,206uy,206uy
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 146uy,146uy,146uy,186uy,186uy,186uy
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |]
&nbsp;&nbsp;&nbsp; <span style="color:green;">// why the SolidColorBrush below? </span>
&nbsp;&nbsp;&nbsp; <span style="color:green;">// to have a DependencyObject to data-bind... there is probably a cleaner way, but oh well</span>
&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> edgeColors <span style="color:purple;">=</span> colors <span style="color:purple;">|&gt;</span> Array<span style="color:purple;">.</span>map (<span style="color:blue;">fun</span> (r,g,b,_,_,_) <span style="color:blue;">-&gt;</span> SolidColorBrush(Color<span style="color:purple;">.</span>FromRgb(r,g,b)))
&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> mainColors <span style="color:purple;">=</span> colors <span style="color:purple;">|&gt;</span> Array<span style="color:purple;">.</span>map (<span style="color:blue;">fun</span> (_,_,_,r,g,b) <span style="color:blue;">-&gt;</span> SolidColorBrush(Color<span style="color:purple;">.</span>FromRgb(r,g,b)))
&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> brushes <span style="color:purple;">=</span>&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> makeGradientStop(b<span style="color:purple;">:</span>SolidColorBrush, pct) <span style="color:purple;">=</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> gs <span style="color:purple;">=</span>&nbsp;<span style="color:blue;">new</span> GradientStop(b<span style="color:purple;">.</span>Color, pct)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; makeBinding(b, <span style="color:maroon;">"Color"</span>, (<span style="color:blue;">fun</span> (c<span style="color:purple;">:</span>Color) <span style="color:blue;">-&gt;</span> c), gs, GradientStop<span style="color:purple;">.</span>ColorProperty)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gs
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <span style="color:blue;">new</span> IIndexable<span style="color:purple;">&lt;</span>Brush<span style="color:purple;">&gt;</span>&nbsp;<span style="color:blue;">with</span>&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">member</span> this<span style="color:purple;">.</span>Item depth <span style="color:purple;">=</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">upcast</span>&nbsp;<span style="color:blue;">new</span> LinearGradientBrush(
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">new</span> GradientStopCollection(
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [|
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; makeGradientStop(edgeColors<span style="color:purple;">.</span>[depth], 0.0)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; makeGradientStop(mainColors<span style="color:purple;">.</span>[depth], 0.01)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; makeGradientStop(mainColors<span style="color:purple;">.</span>[depth], 1.0)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |] ), <span style="color:blue;">new</span> Point(0.0, 0.5), <span style="color:blue;">new</span> Point(1.0, 0.5)) }

&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> printCurrentSettings() <span style="color:purple;">=</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printfn <span style="color:maroon;">"Windows Registry Editor Version 5.00"</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printfn <span style="color:maroon;">""</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printfn <span style="color:maroon;">"[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\Text Editor\FSharpDepthColorizer]"</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">for</span> i <span style="color:blue;">in</span> 0..9 <span style="color:blue;">do</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> ec <span style="color:purple;">=</span> edgeColors<span style="color:purple;">.</span>[i]<span style="color:purple;">.</span>Color
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> mc <span style="color:purple;">=</span> mainColors<span style="color:purple;">.</span>[i]<span style="color:purple;">.</span>Color
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printfn <span style="color:maroon;">"\"Depth%d\"=\"%d,%d,%d,%d,%d,%d\""</span> i ec<span style="color:purple;">.</span>R ec<span style="color:purple;">.</span>G ec<span style="color:purple;">.</span>B mc<span style="color:purple;">.</span>R mc<span style="color:purple;">.</span>G mc<span style="color:purple;">.</span>B 

&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> mkButton(colors<span style="color:purple;">:</span>SolidColorBrush[], text, dr, dg, db) <span style="color:purple;">=</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> b <span style="color:purple;">=</span>&nbsp;<span style="color:blue;">new</span> Button()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b<span style="color:purple;">.</span>Content <span style="color:purple;">&lt;-</span> text
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b<span style="color:purple;">.</span>Click<span style="color:purple;">.</span>Add(<span style="color:blue;">fun</span> _ <span style="color:blue;">-&gt;</span> colors<span style="color:purple;">.</span>[getNum()]<span style="color:purple;">.</span>Color <span style="color:purple;">&lt;-</span>&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Color<span style="color:purple;">.</span>FromRgb(colors<span style="color:purple;">.</span>[getNum()]<span style="color:purple;">.</span>Color<span style="color:purple;">.</span>R <span style="color:purple;">+</span> byte dr,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; colors<span style="color:purple;">.</span>[getNum()]<span style="color:purple;">.</span>Color<span style="color:purple;">.</span>G <span style="color:purple;">+</span> byte dg,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; colors<span style="color:purple;">.</span>[getNum()]<span style="color:purple;">.</span>Color<span style="color:purple;">.</span>B <span style="color:purple;">+</span> byte db))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b

&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> mkButtonPanel(colors<span style="color:purple;">:</span>SolidColorBrush[],text,dr,dg,db,f) <span style="color:purple;">=</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> panel <span style="color:purple;">=</span>&nbsp;<span style="color:blue;">new</span> StackPanel(Orientation <span style="color:purple;">=</span> Orientation<span style="color:purple;">.</span>Horizontal)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> tb <span style="color:purple;">=</span>&nbsp;<span style="color:blue;">new</span> TextBlock()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; selectedChanged<span style="color:purple;">.</span>Publish<span style="color:purple;">.</span>Add(<span style="color:blue;">fun</span> _ <span style="color:blue;">-&gt;</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; makeBinding(colors<span style="color:purple;">.</span>[getNum()], <span style="color:maroon;">"Color"</span>, (<span style="color:blue;">fun</span> (c<span style="color:purple;">:</span>Color) <span style="color:blue;">-&gt;</span> f(c)<span style="color:purple;">.</span>ToString()),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tb, System<span style="color:purple;">.</span>Windows<span style="color:purple;">.</span>Controls<span style="color:purple;">.</span>TextBlock<span style="color:purple;">.</span>TextProperty))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; panel<span style="color:purple;">.</span>Children<span style="color:purple;">.</span>Add(mkButton(colors, text<span style="color:purple;">+</span><span style="color:maroon;">" down"</span>,<span style="color:purple;">-</span>dr,<span style="color:purple;">-</span>dg,<span style="color:purple;">-</span>db)) <span style="color:purple;">|&gt;</span> ignore
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; panel<span style="color:purple;">.</span>Children<span style="color:purple;">.</span>Add(tb) <span style="color:purple;">|&gt;</span> ignore
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; panel<span style="color:purple;">.</span>Children<span style="color:purple;">.</span>Add(mkButton(colors, text<span style="color:purple;">+</span><span style="color:maroon;">" up"</span>,dr,dg,db)) <span style="color:purple;">|&gt;</span> ignore
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; panel

&nbsp;&nbsp;&nbsp; <span style="color:blue;">do</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> leftPanel <span style="color:purple;">=</span>&nbsp;<span style="color:blue;">new</span> StackPanel(Orientation <span style="color:purple;">=</span> Orientation<span style="color:purple;">.</span>Vertical)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; leftPanel<span style="color:purple;">.</span>Children<span style="color:purple;">.</span>Add(mkButtonPanel(edgeColors,<span style="color:maroon;">"edge R"</span>,2,0,0,(<span style="color:blue;">fun</span> c<span style="color:blue;">-&gt;</span>c<span style="color:purple;">.</span>R))) <span style="color:purple;">|&gt;</span> ignore
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; leftPanel<span style="color:purple;">.</span>Children<span style="color:purple;">.</span>Add(mkButtonPanel(edgeColors,<span style="color:maroon;">"edge G"</span>,0,2,0,(<span style="color:blue;">fun</span> c<span style="color:blue;">-&gt;</span>c<span style="color:purple;">.</span>G))) <span style="color:purple;">|&gt;</span> ignore
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; leftPanel<span style="color:purple;">.</span>Children<span style="color:purple;">.</span>Add(mkButtonPanel(edgeColors,<span style="color:maroon;">"edge B"</span>,0,0,2,(<span style="color:blue;">fun</span> c<span style="color:blue;">-&gt;</span>c<span style="color:purple;">.</span>B))) <span style="color:purple;">|&gt;</span> ignore
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; leftPanel<span style="color:purple;">.</span>Children<span style="color:purple;">.</span>Add(mkButtonPanel(mainColors,<span style="color:maroon;">"main R"</span>,2,0,0,(<span style="color:blue;">fun</span> c<span style="color:blue;">-&gt;</span>c<span style="color:purple;">.</span>R))) <span style="color:purple;">|&gt;</span> ignore
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; leftPanel<span style="color:purple;">.</span>Children<span style="color:purple;">.</span>Add(mkButtonPanel(mainColors,<span style="color:maroon;">"main G"</span>,0,2,0,(<span style="color:blue;">fun</span> c<span style="color:blue;">-&gt;</span>c<span style="color:purple;">.</span>G))) <span style="color:purple;">|&gt;</span> ignore
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; leftPanel<span style="color:purple;">.</span>Children<span style="color:purple;">.</span>Add(mkButtonPanel(mainColors,<span style="color:maroon;">"main B"</span>,0,0,2,(<span style="color:blue;">fun</span> c<span style="color:blue;">-&gt;</span>c<span style="color:purple;">.</span>B))) <span style="color:purple;">|&gt;</span> ignore
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> printButton <span style="color:purple;">=</span>&nbsp;<span style="color:blue;">new</span> Button(Content<span style="color:purple;">=</span><span style="color:maroon;">"Print current settings to console"</span>)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printButton<span style="color:purple;">.</span>Click<span style="color:purple;">.</span>Add(<span style="color:blue;">fun</span> _ <span style="color:blue;">-&gt;</span> printCurrentSettings())
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; leftPanel<span style="color:purple;">.</span>Children<span style="color:purple;">.</span>Add(printButton) <span style="color:purple;">|&gt;</span> ignore
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> mainPanel <span style="color:purple;">=</span>&nbsp;<span style="color:blue;">new</span> StackPanel(Orientation <span style="color:purple;">=</span> Orientation<span style="color:purple;">.</span>Horizontal)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mainPanel<span style="color:purple;">.</span>Children<span style="color:purple;">.</span>Add(leftPanel) <span style="color:purple;">|&gt;</span> ignore
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> canvas <span style="color:purple;">=</span>&nbsp;<span style="color:blue;">new</span> Canvas()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">for</span> i <span style="color:blue;">in</span> 0..mainColors<span style="color:purple;">.</span>Length<span style="color:purple;">-</span>1 <span style="color:blue;">do</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> rect <span style="color:purple;">=</span>&nbsp;<span style="color:blue;">new</span> Rectangle(Width<span style="color:purple;">=</span>600., Height<span style="color:purple;">=</span>500., Fill <span style="color:purple;">=</span> brushes<span style="color:purple;">.</span>[i])
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rect<span style="color:purple;">.</span>MouseDown<span style="color:purple;">.</span>Add(<span style="color:blue;">fun</span> _ <span style="color:blue;">-&gt;</span> setNum(i))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Canvas<span style="color:purple;">.</span>SetLeft(rect, (float i)<span style="color:purple;">*</span>30.)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Canvas<span style="color:purple;">.</span>SetTop(rect, (float i)<span style="color:purple;">*</span>30.)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Canvas<span style="color:purple;">.</span>SetZIndex(rect, i)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; canvas<span style="color:purple;">.</span>Children<span style="color:purple;">.</span>Add(rect) <span style="color:purple;">|&gt;</span> ignore
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">let</span> rect <span style="color:purple;">=</span>&nbsp;<span style="color:blue;">new</span> Rectangle(Width<span style="color:purple;">=</span>600., Height<span style="color:purple;">=</span>40.)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; selectedChanged<span style="color:purple;">.</span>Publish<span style="color:purple;">.</span>Add(<span style="color:blue;">fun</span> _ <span style="color:blue;">-&gt;</span> rect<span style="color:purple;">.</span>Fill <span style="color:purple;">&lt;-</span> brushes<span style="color:purple;">.</span>[getNum()])
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Canvas<span style="color:purple;">.</span>SetLeft(rect, 0.)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Canvas<span style="color:purple;">.</span>SetTop(rect, (float mainColors<span style="color:purple;">.</span>Length)<span style="color:purple;">*</span>30. <span style="color:purple;">+</span> 20.)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Canvas<span style="color:purple;">.</span>SetZIndex(rect, mainColors<span style="color:purple;">.</span>Length)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; canvas<span style="color:purple;">.</span>Children<span style="color:purple;">.</span>Add(rect) <span style="color:purple;">|&gt;</span> ignore
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mainPanel<span style="color:purple;">.</span>Children<span style="color:purple;">.</span>Add(canvas) <span style="color:purple;">|&gt;</span> ignore
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this<span style="color:purple;">.</span>Content <span style="color:purple;">&lt;-</span> mainPanel

&nbsp;&nbsp;&nbsp; <span style="color:blue;">member</span>&nbsp;<span style="color:blue;">private</span> this<span style="color:purple;">.</span>TriggerSelectedRectangleNumberChanged(x<span style="color:purple;">:</span>int) <span style="color:purple;">=</span> selectedChanged<span style="color:purple;">.</span>Trigger(this, x)
&nbsp;&nbsp;&nbsp; <span style="color:blue;">static</span>&nbsp;<span style="color:blue;">member</span> SelectedRectangleNumber <span style="color:purple;">=</span> selectedRectangleNumber 

[&lt;System<span style="color:purple;">.</span>STAThread&gt;]
<span style="color:blue;">do</span>
&nbsp;&nbsp;&nbsp; (<span style="color:blue;">new</span> Application())<span style="color:purple;">.</span>Run(MyWindow()) <span style="color:purple;">|&gt;</span> ignore
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lorgonblog.wordpress.com/209/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lorgonblog.wordpress.com/209/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lorgonblog.wordpress.com/209/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lorgonblog.wordpress.com/209/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/lorgonblog.wordpress.com/209/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/lorgonblog.wordpress.com/209/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/lorgonblog.wordpress.com/209/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/lorgonblog.wordpress.com/209/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lorgonblog.wordpress.com/209/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lorgonblog.wordpress.com/209/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lorgonblog.wordpress.com/209/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lorgonblog.wordpress.com/209/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lorgonblog.wordpress.com/209/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lorgonblog.wordpress.com/209/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lorgonblog.wordpress.com&amp;blog=16474804&amp;post=209&amp;subd=lorgonblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://lorgonblog.wordpress.com/2010/11/20/a-quick-standalone-app-to-edit-colors-for-the-f-colorizer/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad588a46e9e78dced5c6dbcf1355bd09?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brianmcn</media:title>
		</media:content>

		<media:content url="http://lorgonblog.files.wordpress.com/2010/11/fscoloreditor_thumb.png" medium="image">
			<media:title type="html">FSColorEditor</media:title>
		</media:content>
	</item>
		<item>
		<title>F# source code structural colorizer available</title>
		<link>http://lorgonblog.wordpress.com/2010/11/18/f-source-code-structural-colorizer-available/</link>
		<comments>http://lorgonblog.wordpress.com/2010/11/18/f-source-code-structural-colorizer-available/#comments</comments>
		<pubDate>Thu, 18 Nov 2010 14:05:34 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://lorgonblog.wordpress.com/2010/11/18/f-source-code-structural-colorizer-available/</guid>
		<description><![CDATA[Last week I mentioned the editor extension I am working on, and now it’s available for you to try out!&#160; You can obtain the F# Depth Colorizer from the Visual Studio Gallery.&#160; It’s a one-click install; once installed you’ll see it listed when you bring up the “Tools\Extension Manager” menu in Visual Studio: Once installed, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lorgonblog.wordpress.com&amp;blog=16474804&amp;post=204&amp;subd=lorgonblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://lorgonblog.wordpress.com/2010/11/12/the-f-compiler-source-release-making-it-easy-to-write-cool-visual-studio-extensions/">Last week</a> I mentioned the editor extension I am working on, and now it’s available for you to try out!&nbsp; You can obtain the <a href="http://visualstudiogallery.msdn.microsoft.com/en-us/0713522e-27e6-463f-830a-cb8f08e467c4">F# Depth Colorizer</a> from the <a href="http://visualstudiogallery.msdn.microsoft.com/">Visual Studio Gallery</a>.&nbsp; It’s a one-click install; once installed you’ll see it listed when you bring up the “Tools\Extension Manager” menu in Visual Studio:</p>
<p><a href="http://lorgonblog.files.wordpress.com/2010/11/fsdcem.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="FSDCEM" border="0" alt="FSDCEM" src="http://lorgonblog.files.wordpress.com/2010/11/fsdcem_thumb.png?w=858&#038;h=137" width="858" height="137"></a></p>
<p>Once installed, the structure of your code will be highlighted in the editor, like this</p>
<p><a href="http://lorgonblog.files.wordpress.com/2010/11/fsdcgreyscalescreenshot.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="FSDCGreyScaleScreenshot" border="0" alt="FSDCGreyScaleScreenshot" src="http://lorgonblog.files.wordpress.com/2010/11/fsdcgreyscalescreenshot_thumb.png?w=829&#038;h=473" width="829" height="473"></a></p>
<p>or like this</p>
<p><a href="http://lorgonblog.files.wordpress.com/2010/11/fsdcredbluescreenshot.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="FSDCRedBlueScreenshot" border="0" alt="FSDCRedBlueScreenshot" src="http://lorgonblog.files.wordpress.com/2010/11/fsdcredbluescreenshot_thumb.png?w=831&#038;h=472" width="831" height="472"></a></p>
<p>rather than plain old code like this</p>
<p><a href="http://lorgonblog.files.wordpress.com/2010/11/fsdcdisabledscreenshot.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="FSDCDisabledScreenshot" border="0" alt="FSDCDisabledScreenshot" src="http://lorgonblog.files.wordpress.com/2010/11/fsdcdisabledscreenshot_thumb.png?w=830&#038;h=473" width="830" height="473"></a></p>
<p>Get the idea?&nbsp; As suggested by the first two screenshots, the colors are configurable.&nbsp; A good UI for configuring the colors was beyond me, so the colors are configurable via a registry setting.&nbsp; (EDIT: see also <a href="http://lorgonblog.wordpress.com/2010/11/20/a-quick-standalone-app-to-edit-colors-for-the-f-colorizer/">here</a>) If you don’t have the registry entry, you get the “greyscale” colors from the first screenshot by default.&nbsp; Those greyscale colors could be represented via the following registry entry:</p>
<pre style="font-family:consolas;"><font size="2">Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\Text Editor\FSharpDepthColorizer]
"Depth0"="190,190,190,230,230,230"
"Depth1"="170,170,170,210,210,210"
"Depth2"="184,184,184,224,224,224"
"Depth3"="164,164,164,204,204,204"
"Depth4"="178,178,178,218,218,218"
"Depth5"="158,158,158,198,198,198"
"Depth6"="172,172,172,212,212,212"
"Depth7"="152,152,152,192,192,192"
"Depth8"="166,166,166,206,206,206"
"Depth9"="146,146,146,186,186,186"</font></pre>
<p>Alternatively, the red-blue colors from the second screenshot are:</p>
<pre style="font-family:consolas;"><font size="2">Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\Text Editor\FSharpDepthColorizer]
"Depth0"="240,180,180,240,220,220"
"Depth1"="180,180,240,220,220,240"
"Depth2"="240,172,172,240,216,212"
"Depth3"="172,172,240,212,216,240"
"Depth4"="240,164,164,240,212,204"
"Depth5"="164,164,240,204,212,240"
"Depth6"="240,156,156,240,208,196"
"Depth7"="156,156,240,196,208,240"
"Depth8"="240,148,148,240,204,188"
"Depth9"="148,148,240,188,204,240"</font></pre>
<p>and more generally, the extension will look for the those registry keys.&nbsp; (You can save these registry examples to a file “foo.reg” and then run the “foo.reg” file to install those keys, or use the “regedit” tool to inspect/change the values.&nbsp; Be careful when modifying your registry!)</p>
<p>The DepthN values are strings of six numbers, representing two sets of RGB values, e.g.</p>
<p>DepthN = R1, G1, B1, R2, G2, B2</p>
<p>where N is the depth of the nesting of the source code structure, the RGB1 values are the color of the left edge of the highlight (intention is to provide more visual contrast at the edge), and the RGB2 values are the main color for highlighting that nesting depth.&nbsp; There must be 10 depths, if you go deeper, the tool cycles around:</p>
<p><a href="http://lorgonblog.files.wordpress.com/2010/11/fsdcdeepnestingscreenshot.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="FSDCDeepNestingScreenshot" border="0" alt="FSDCDeepNestingScreenshot" src="http://lorgonblog.files.wordpress.com/2010/11/fsdcdeepnestingscreenshot_thumb.png?w=268&#038;h=226" width="268" height="226"></a></p>
<p>where the colors are getting darker until it’s gone 10 deep and cycles back around to using the lightest pink color from that color set.</p>
<p>I’ll publish the source code for this VSIX extension soon. (EDIT: It&#8217;s posted, see <a href="http://lorgonblog.wordpress.com/2010/11/21/source-code-for-f-depth-colorizer-extension/">here</a>.) &nbsp; For now, I’d encourage you to try it out; you can leave feedback on my blog or on the gallery.&nbsp; Enjoy!</p>
<p>(Much thanks to <a href="http://blogs.msdn.com/b/noahric/">Noah</a> who helped me write the editor portion of the extension.&nbsp; Thanks to many people who did beta testing and offered useful feedback.)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lorgonblog.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lorgonblog.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lorgonblog.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lorgonblog.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/lorgonblog.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/lorgonblog.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/lorgonblog.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/lorgonblog.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lorgonblog.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lorgonblog.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lorgonblog.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lorgonblog.wordpress.com/204/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lorgonblog.wordpress.com/204/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lorgonblog.wordpress.com/204/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lorgonblog.wordpress.com&amp;blog=16474804&amp;post=204&amp;subd=lorgonblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://lorgonblog.wordpress.com/2010/11/18/f-source-code-structural-colorizer-available/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad588a46e9e78dced5c6dbcf1355bd09?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brianmcn</media:title>
		</media:content>

		<media:content url="http://lorgonblog.files.wordpress.com/2010/11/fsdcem_thumb.png" medium="image">
			<media:title type="html">FSDCEM</media:title>
		</media:content>

		<media:content url="http://lorgonblog.files.wordpress.com/2010/11/fsdcgreyscalescreenshot_thumb.png" medium="image">
			<media:title type="html">FSDCGreyScaleScreenshot</media:title>
		</media:content>

		<media:content url="http://lorgonblog.files.wordpress.com/2010/11/fsdcredbluescreenshot_thumb.png" medium="image">
			<media:title type="html">FSDCRedBlueScreenshot</media:title>
		</media:content>

		<media:content url="http://lorgonblog.files.wordpress.com/2010/11/fsdcdisabledscreenshot_thumb.png" medium="image">
			<media:title type="html">FSDCDisabledScreenshot</media:title>
		</media:content>

		<media:content url="http://lorgonblog.files.wordpress.com/2010/11/fsdcdeepnestingscreenshot_thumb.png" medium="image">
			<media:title type="html">FSDCDeepNestingScreenshot</media:title>
		</media:content>
	</item>
		<item>
		<title>The F# compiler source release: making it easy to write cool Visual Studio extensions</title>
		<link>http://lorgonblog.wordpress.com/2010/11/12/the-f-compiler-source-release-making-it-easy-to-write-cool-visual-studio-extensions/</link>
		<comments>http://lorgonblog.wordpress.com/2010/11/12/the-f-compiler-source-release-making-it-easy-to-write-cool-visual-studio-extensions/#comments</comments>
		<pubDate>Fri, 12 Nov 2010 09:34:55 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://lorgonblog.wordpress.com/2010/11/12/the-f-compiler-source-release-making-it-easy-to-write-cool-visual-studio-extensions/</guid>
		<description><![CDATA[In case you’ve been hiding under a rock and haven’t heard, the F# compiler was recently released under the Apache 2.0 license; see Don’s blog for the details.&#160; This source code release gives you the freedom to use the F# compiler code how you like, and so of course as a developer who likes using [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lorgonblog.wordpress.com&amp;blog=16474804&amp;post=193&amp;subd=lorgonblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In case you’ve been hiding under a rock and haven’t heard, the F# compiler was recently released under the Apache 2.0 license; see <a href="http://blogs.msdn.com/b/dsyme/archive/2010/11/04/announcing-the-f-compiler-library-source-code-drop.aspx">Don’s blog</a> for the details.&nbsp; This source code release gives you the freedom to use the F# compiler code how you like, and so of course as a developer who likes using Visual Studio, I decided to take a crack at a Visual Studio extension that I’ve always wanted to write.</p>
<p>The basic idea is an editor extension that uses background colorization to show the “control flow depth” of F# code.&nbsp; A screenshot is a little suggestive:</p>
<p><a href="http://lorgonblog.files.wordpress.com/2010/11/fsparsedepthscreenshot.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="FSParseDepthScreenshot" border="0" alt="FSParseDepthScreenshot" src="http://lorgonblog.files.wordpress.com/2010/11/fsparsedepthscreenshot_thumb.png?w=282&#038;h=194" width="282" height="194"></a></p>
<p>but in order to really describe it, I made a video (about 6 minutes long), linked below.</p>
<p>The idea is simple; the F# compiler code already knows how to do all the heavy lifting of parsing source code and creating a parse tree (an abstract syntax tree, or “AST”), and the AST knows all the info about code structure and e.g. that this expression starts in this line/column and ends in this other line/column.&nbsp; So I just take the tree and turn it into some useful “depth and span” information, which I then use from a Visual Studio editor extension to add color adornments in the editor.</p>
<p>This is still under development, but I plan to publish the extension on the <a href="http://visualstudiogallery.msdn.microsoft.com/en-us/">Visual Studio Gallery</a>, and publish the source code when I’m done.</p>
<p>Anyway, check out the video <a href="http://brianmcn.members.winisp.net/FSharpParseDepthPreview.wmv">here</a>.&nbsp; I’m interested to hear what people think, and hope this inspires others to try their hand at leveraging the F# compiler code to write cool tools and extensions.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lorgonblog.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lorgonblog.wordpress.com/193/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lorgonblog.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lorgonblog.wordpress.com/193/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/lorgonblog.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/lorgonblog.wordpress.com/193/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/lorgonblog.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/lorgonblog.wordpress.com/193/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lorgonblog.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lorgonblog.wordpress.com/193/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lorgonblog.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lorgonblog.wordpress.com/193/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lorgonblog.wordpress.com/193/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lorgonblog.wordpress.com/193/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lorgonblog.wordpress.com&amp;blog=16474804&amp;post=193&amp;subd=lorgonblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://lorgonblog.wordpress.com/2010/11/12/the-f-compiler-source-release-making-it-easy-to-write-cool-visual-studio-extensions/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
<enclosure url="http://brianmcn.members.winisp.net/FSharpParseDepthPreview.wmv" length="33343795" type="video/asf" />
	
		<media:content url="http://0.gravatar.com/avatar/ad588a46e9e78dced5c6dbcf1355bd09?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brianmcn</media:title>
		</media:content>

		<media:content url="http://lorgonblog.files.wordpress.com/2010/11/fsparsedepthscreenshot_thumb.png" medium="image">
			<media:title type="html">FSParseDepthScreenshot</media:title>
		</media:content>
	</item>
		<item>
		<title>PDC is just around the corner&#8230;</title>
		<link>http://lorgonblog.wordpress.com/2010/10/26/pdc-is-just-around-the-corner/</link>
		<comments>http://lorgonblog.wordpress.com/2010/10/26/pdc-is-just-around-the-corner/#comments</comments>
		<pubDate>Wed, 27 Oct 2010 04:52:12 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://lorgonblog.wordpress.com/2010/10/26/pdc-is-just-around-the-corner/</guid>
		<description><![CDATA[For those of you attending Microsoft’s Professional Developers Conference, I hope you’ll stop by the F# “Ask the Experts” table at lunchtime on Thursday or Friday to say hello and ask some interesting questions about F#!&#160; For those of you who won’t be in Redmond this week, all of the PDC content can be watched [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lorgonblog.wordpress.com&amp;blog=16474804&amp;post=186&amp;subd=lorgonblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>For those of you attending Microsoft’s <a href="http://www.microsoftpdc.com/">Professional Developers Conference</a>, I hope you’ll stop by the F# “Ask the Experts” table at lunchtime on Thursday or Friday to say hello and ask some interesting questions about F#!&nbsp; For those of you who won’t be in Redmond this week, all of the PDC content can be watched live online (or recorded afterwards), so there’s no reason for you to miss out on all the great talks.</p>
<p>Don’s F# talk entitled “The Future of F#: Data and Services at your Finger Tips” is scheduled during the final timeslot on Friday afternoon, so of course readers of this blog will want to check that out.&nbsp; <a href="http://windowsteamblog.com/windows_phone/b/wpdev/archive/2010/10/26/make-sure-you-don-t-miss-windows-phone-sessions-during-pdc10.aspx">Windows Phone 7</a> will be another hot topic at PDC; I have been trying really hard to get my hands on a phone, so that I can show off some F# apps running on the phone at the Experts table, but so far I’ve only met dead ends.&nbsp; I’ve still got another 36 hours or so, and I haven’t given up on that yet.&nbsp; <img style="border-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://lorgonblog.files.wordpress.com/2010/10/wlemoticon-smile.png"></p>
<p>Regarding general F# news… I recently saw F# get some love on <a href="http://news.ycombinator.com/item?id=1826564">HackerNews</a>, and PDC will be sure to generate some more F# buzz this week.&nbsp; And I think perhaps there’s some more F# news in store soon after PDC as well.&nbsp; So now is a good time to have your finger on the pulse of the F# community; <a href="http://feeds.feedburner.com/planet_fsharp">Planet F#</a> or <a href="http://www.atalasoft.com/cs/blogs/rickm/default.aspx">Rick Minerich’s blog</a> are good ways to keep up with the F# highlights.&nbsp; On the other hand, if you’re relatively new to the world of F#, you might prefer reading <a href="http://stackoverflow.com/questions/734525/getting-started-with-f">Getting started with F#</a>.</p>
<p>In completely unrelated news, I recently posted an answer to <a href="http://stackoverflow.com/questions/3989264/best-explanation-for-languages-without-null">Best explanation for Languages without Null</a> on <a href="http://stackoverflow.com/">StackOverflow</a> that has easily become my highest-upvoted-answer ever.&nbsp; Undoubtedly the large <a href="http://stackoverflow.com/faq#bounty">bounty</a> on the question helped attract eyeballs… regardless of why, I’m pleased that my thoughts on this topic garnered so much attention.&nbsp; (It makes up at least a tiny bit for my lack of substantive blogging of late; this is my fifth post in a row that’s light on code or novel ideas.&nbsp; I hope to have some meatier/code-ful topics to blog about soon.)</p>
<p>Enough rambling for now – enjoy PDC this week!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lorgonblog.wordpress.com/186/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lorgonblog.wordpress.com/186/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lorgonblog.wordpress.com/186/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lorgonblog.wordpress.com/186/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/lorgonblog.wordpress.com/186/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/lorgonblog.wordpress.com/186/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/lorgonblog.wordpress.com/186/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/lorgonblog.wordpress.com/186/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lorgonblog.wordpress.com/186/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lorgonblog.wordpress.com/186/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lorgonblog.wordpress.com/186/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lorgonblog.wordpress.com/186/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lorgonblog.wordpress.com/186/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lorgonblog.wordpress.com/186/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lorgonblog.wordpress.com&amp;blog=16474804&amp;post=186&amp;subd=lorgonblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://lorgonblog.wordpress.com/2010/10/26/pdc-is-just-around-the-corner/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad588a46e9e78dced5c6dbcf1355bd09?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brianmcn</media:title>
		</media:content>

		<media:content url="http://lorgonblog.files.wordpress.com/2010/10/wlemoticon-smile.png" medium="image">
			<media:title type="html">Smile</media:title>
		</media:content>
	</item>
		<item>
		<title>F# web snippets, Mandelbrot, and great things to come&#8230;</title>
		<link>http://lorgonblog.wordpress.com/2010/10/17/f-web-snippets-mandelbrot-and-great-things-to-come/</link>
		<comments>http://lorgonblog.wordpress.com/2010/10/17/f-web-snippets-mandelbrot-and-great-things-to-come/#comments</comments>
		<pubDate>Mon, 18 Oct 2010 06:03:26 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://lorgonblog.wordpress.com/2010/10/17/f-web-snippets-mandelbrot-and-great-things-to-come/</guid>
		<description><![CDATA[Tomas recently posted a terrific new tool called F# Web Snippets.&#160; You can read a bit on his blog, but you can get an immediate feel by reading a clone of this blog entry I’ve hosted elsewhere (on a site where I can host Javascript code).&#160; So click the previous link and check it out.&#160; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lorgonblog.wordpress.com&amp;blog=16474804&amp;post=174&amp;subd=lorgonblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://tomasp.net/">Tomas</a> recently posted a terrific new tool called <a href="http://tomasp.net/projects/fswebsnippets.aspx">F# Web Snippets</a>.&nbsp; You can read a bit on his <a href="http://tomasp.net/articles/fswebsnippets-intro.aspx">blog</a>, but you can get an immediate feel by reading <a href="http://brianmcn.members.winisp.net/FSWebSnippetBlog.html">a clone of this blog entry I’ve hosted elsewhere</a> (on a site where I can host Javascript code).&nbsp; So click the previous link and check it out.&nbsp; Here is the code without the nice web-snippet adornments:</p>
<pre class="code"><span style="color:blue;">open </span>System
<span style="color:blue;">open </span>System<span style="color:purple;">.</span>Numerics

<span style="color:blue;">let </span>maxIteration <span style="color:purple;">= </span>100

<span style="color:blue;">let </span>modSquared (c <span style="color:purple;">: </span>Complex) <span style="color:purple;">= </span>c<span style="color:purple;">.</span>Real <span style="color:purple;">* </span>c<span style="color:purple;">.</span>Real <span style="color:purple;">+ </span>c<span style="color:purple;">.</span>Imaginary <span style="color:purple;">* </span>c<span style="color:purple;">.</span>Imaginary

<span style="color:blue;">type </span>MandelbrotResult <span style="color:purple;">=
    </span>| DidNotEscape
    | Escaped <span style="color:blue;">of </span>int

<span style="color:blue;">let </span>mandelbrot c <span style="color:purple;">=
    </span><span style="color:blue;">let rec </span>mandelbrotInner z iterations <span style="color:purple;">=
        </span><span style="color:blue;">if</span>(modSquared z <span style="color:purple;">&gt;= </span>4.0)
            <span style="color:blue;">then </span>Escaped iterations
        <span style="color:blue;">elif </span>iterations <span style="color:purple;">= </span>maxIteration
            <span style="color:blue;">then </span>DidNotEscape
        <span style="color:blue;">else </span>mandelbrotInner ((z <span style="color:purple;">* </span>z) <span style="color:purple;">+ </span>c) (iterations <span style="color:purple;">+ </span>1)
    mandelbrotInner c 0

<span style="color:blue;">let </span>chars <span style="color:purple;">= </span><span style="color:maroon;">" .:-;!/&gt;)|&amp;IH%*#"

</span><span style="color:blue;">for </span>y <span style="color:blue;">in </span>[<span style="color:purple;">-</span>1.2<span style="color:purple;">..</span>0.05<span style="color:purple;">..</span>1.2] <span style="color:blue;">do
    for </span>x <span style="color:blue;">in </span>[<span style="color:purple;">-</span>2.0<span style="color:purple;">..</span>0.025<span style="color:purple;">..</span>0.9] <span style="color:blue;">do
        match </span>mandelbrot(Complex(x, y)) <span style="color:blue;">with
        </span>| DidNotEscape <span style="color:blue;">-&gt; </span>Console<span style="color:purple;">.</span>Write <span style="color:maroon;">" "
        </span>| Escaped i <span style="color:blue;">-&gt; </span>Console<span style="color:purple;">.</span>Write chars<span style="color:purple;">.</span>[i <span style="color:purple;">&amp;&amp;&amp; </span>15]
    Console<span style="color:purple;">.</span>WriteLine() </pre>
<p>The <a href="http://brianmcn.members.winisp.net/FSWebSnippetBlog.html">Javascript-ful site</a>, in addition to just nicely colorizing the F# code as above, also provides hover tooltips in your browser, much like you’d get from Visual Studio.&nbsp; On the cloned blog entry you can hover over the identifier “maxIteration” and see that it is an “int”, for example.&nbsp; It’s very cool.</p>
<p>(By the way, yes, the Mandelbrot code I stole mercilessly from <a href="http://blogs.msdn.com/b/lukeh/">Luke</a>’s recent timely <a href="http://blogs.msdn.com/b/lukeh/archive/2010/10/16/benoit-mandelbrot.aspx">blog</a>.)</p>
<p>Anyway, Tomas’ tool is so cool I had to immediately try it out in a blog post before I went to sleep tonight.&nbsp; Here’s the output of the program, by the way:</p>
<p><a href="http://lorgonblog.files.wordpress.com/2010/10/textmandelbrot.png"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="TextMandelbrot" border="0" alt="TextMandelbrot" src="http://lorgonblog.files.wordpress.com/2010/10/textmandelbrot_thumb.png?w=644&#038;h=399" width="644" height="399"></a> </p>
<p>With <a href="http://www.microsoftpdc.com/">PDC</a> coming soon, one imagines there may be other exciting F#-related announcements coming soon as well!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lorgonblog.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lorgonblog.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lorgonblog.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lorgonblog.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/lorgonblog.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/lorgonblog.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/lorgonblog.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/lorgonblog.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lorgonblog.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lorgonblog.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lorgonblog.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lorgonblog.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lorgonblog.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lorgonblog.wordpress.com/174/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lorgonblog.wordpress.com&amp;blog=16474804&amp;post=174&amp;subd=lorgonblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://lorgonblog.wordpress.com/2010/10/17/f-web-snippets-mandelbrot-and-great-things-to-come/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad588a46e9e78dced5c6dbcf1355bd09?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brianmcn</media:title>
		</media:content>

		<media:content url="http://lorgonblog.files.wordpress.com/2010/10/textmandelbrot_thumb.png" medium="image">
			<media:title type="html">TextMandelbrot</media:title>
		</media:content>
	</item>
		<item>
		<title>Unit tests + debugger = code understanding</title>
		<link>http://lorgonblog.wordpress.com/2010/10/08/unit-tests-debugger-code-understanding/</link>
		<comments>http://lorgonblog.wordpress.com/2010/10/08/unit-tests-debugger-code-understanding/#comments</comments>
		<pubDate>Fri, 08 Oct 2010 13:40:07 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://lorgonblog.wordpress.com/2010/10/08/unit-tests-debugger-code-understanding/</guid>
		<description><![CDATA[(A quick reminder to update your feed readers to point at http://lorgonblog.wordpress.com/feed/ for my new blog home.) One of the best features of Visual Studio is Intellisense, the auto-completion that suggests legal completions when you “dot into” an object, and brings up a list of identifier completions when you press a keyboard shortcut like Ctrl-Space.&#160; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lorgonblog.wordpress.com&amp;blog=16474804&amp;post=161&amp;subd=lorgonblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>(A quick reminder to update your feed readers to point at <a href="http://lorgonblog.wordpress.com/feed/">http://lorgonblog.wordpress.com/feed/</a> for my new blog home.)</p>
<p>One of the best features of Visual Studio is <a href="http://en.wikipedia.org/wiki/Intellisense">Intellisense</a>, the auto-completion that suggests legal completions when you “dot into” an object, and brings up a list of identifier completions when you press a keyboard shortcut like Ctrl-Space.&nbsp; This kind of auto-completion is one of those most-addictive productivity features, where once you’ve used it, you can’t imagine how you ever lived without it.&nbsp; Nowadays I think most every IDE supports this feature in one way or another.</p>
<p>The Intellisense for F# that we shipped as part of VS2010 is pretty great; I use (read: “depend on”) it all the time.&nbsp; Nevertheless, there are a number of corner cases where the completion lists fall down, and pressing “dot” yields incomplete or incorrect information.&nbsp; On the F# product team, we refer to these cases as “bugs”.&nbsp; :)</p>
<h2>Red</h2>
<p>I’ve recently been spending time fixing these Intellisense bugs.&nbsp; The associated product code is the F# Language Service; a “language service” in Visual Studio is the code that provides all the logic for editor support of a given programming language: features like syntax coloring, Intellisense, “Go To Definition”, etc.</p>
<p>So I start looking at these bugs and spelunking through the language service, and guess what – most of it is code I have either (1) never looked at or (2) completely forgotten.&nbsp; Before I can fix anything, I’ll need to understand how it all works!</p>
<p>Fortunately, much of this code was originally authored by my esteemed colleague <a href="http://blogs.msdn.com/b/jomo_fisher/">Jomo Fisher</a>.&nbsp; Among Jomo’s many admirable developer qualities: he is a TDD-er and avid unit tester.&nbsp; I had started doing a little TDD and unit testing on my own before joining the F# team, but then I joined F# and saw the foundation Jomo had laid for unit-testing the F# language service, and I started to <em>really </em>learn about unit testing.&nbsp; The Visual Studio architecture is all about interfaces and services, which means you can <a href="http://en.wikipedia.org/wiki/Mock_object">mock</a> out all of your VS dependencies and create tests against your VS language service that don’t require Visual Studio to be running.&nbsp; And that’s what Jomo had already established when I first joined the team – a bunch of <a href="http://en.wikipedia.org/wiki/Nunit">NUnit</a> tests against the F# language service he was authoring.</p>
<p>Fast-forward two-and-a-half years, to earlier this week when I wanted to fix an Intellisense bug.&nbsp; Step one, of course, is to author the tests.&nbsp; I had a few repros in hand of places where Intellisense fails (uncovered by some reliability tests written by Jack (a tester on F#) and inspired by <a href="http://blogs.msdn.com/b/mulambda/">Dmitry</a> (another developer on F#)), so I authored a few small test cases to put the bugs under test.&nbsp;&nbsp; I’m now a one-third the way through the TDD mantra “red, green, refactor!”&nbsp; The next step it harder, though.</p>
<h2>Green</h2>
<p>Now I need to try to fix the bug.&nbsp; Only I haven’t the faintest idea where to start, since I don’t know or recall any of this code.&nbsp; So I fire up the Visual Studio debugger and start stepping through the code.&nbsp; The debugger is a good tool for code understanding – when coupled with good unit tests, it is <em>fantastic</em>.&nbsp; Stepping through the code, setting interesting breakpoints, and inspecting call-stacks helped me understand how the various components and functions related to one another.&nbsp; Debugging individual unit tests (where each test is effectively a specification of a tiny feature) helped me identify which pieces of code were attached to which individual features.&nbsp; I probably spent about 4 hours meandering through perhaps some 7000 lines of code, learning how it fit together and locating likely places I would need to eventually make some fixes.</p>
<p>So I finally start making changes and try to make one of my newly-created red tests turn green.&nbsp; Make a change, run that test.&nbsp; Hurrah, it turns green!&nbsp; Now, run the other 600 language service tests.&nbsp; :)&nbsp; And of course, I’ve broken like 50 of those.&nbsp; Great, my unit tests are fulfilling one of their purposes – preventing me from regressing existing functionality.&nbsp; Once again I pop open the debugger, and step through a test I just broke, to understand how what-I-just-changed interacted with this old test.&nbsp; Here, a good debugger really shines.&nbsp; I see it going past some code I just changed, and now because of the computations I just changed, I <em>think</em> it’s now going into this “else” branch, whereas previously I suspect it was going down the “if” branch.&nbsp; Well, I could back out my change, and re-compile, and re-debug, and see if it <em>does</em> take the other branch and if that’s the key difference between red and green for this test.&nbsp; But hey, I’m in the Visual Studio debugger, so I can poke at the live program state however I like.&nbsp; So once I reach the “else”, I drag the little yellow arrow (the ‘next statement’ icon in the margin) up into the “if” to “Set Next Statement” as though the if condition were true rather than false, and then press F5 to keep going.&nbsp; And sure enough, now the test is green again.&nbsp; So I’ve quickly verified my hypothesis about “what changed” inside the debugger, without having to recompile the program.&nbsp; Alternatively, I could poke new values into variables in the “locals” window as another way to test hypotheses about changes without having to actually change and recompile the program.&nbsp; It takes a few minutes to recompile these components and re-install the newly-compiled components, so it really is time-saving (as well as keeping you engaged/focused) to do this hypothesis-testing quickly inside the debugger without needing a recompile.</p>
<p>Ok, so now I think I grok how my change interacted with and broke existing tests, so I’m ready to try a different fix.&nbsp; I make a change, recompile, and while it’s compiling I speculate about which tests I expect to turn green and which I think will stay red.&nbsp; Re-run some tests and continue to hone my understanding.&nbsp; The test I’m looking at, incidentally, is when you type </p>
<pre style="font-family:consolas;">&nbsp;&nbsp;&nbsp; [1..System<span style="color:purple;">.</span></pre>
<p>you don’t get Intellisense, even though e.g.</p>
<pre style="font-family:consolas;">&nbsp;&nbsp;&nbsp; [1..System<span style="color:purple;">.</span>Int32<span style="color:purple;">.</span>MaxValue]</pre>
<p>is a legal eventual completion.&nbsp; Debugging… ok, I’ve definitely found a bug in a function called “QuickParse”, which parses the current line of text where you pressed dot and tries to find The.Qualified.Identifier that appears just to the left of the dot you’re pressing.&nbsp; It would typically return a list of dot-separated identifiers, like [“The”;”Qualified”;”Identifier”], but in the case above, it has something like [“1”;””;”System”].&nbsp; QuickParse doesn’t know about the range operator (..) and so it thinks all those bits are part of a qualified identifier, with e.g. the empty identifier “” as the “namespace between the two dots” of the range operator, rather than understanding “System” as being the start of the current identifier.&nbsp; Indeed, if you do</p>
<pre style="font-family:consolas;">&nbsp;&nbsp;&nbsp; [1 <span style="color:purple;">..</span> System<span style="color:purple;">.</span></pre>
<p>with a <em>space</em> after the range operator, then you do get Intellisense again, as QuickParse correctly handles that case.&nbsp; Ok, so I can fix this.&nbsp; Eventually after a number of iterations of this kind of work, I have my new tests turning green, and only 4 existing tests red, and all of those involve Intellisense of <a href="http://msdn.microsoft.com/en-us/library/system.obsoleteattribute.aspx">Obsolete</a> entities.&nbsp; I debug through those tests, and find the special logic for Obsolete-handling, and just above that code I discover a comment in the code that basically says “here we rely on the fact that we get an empty identifier in certain cases…” aha!&nbsp; The “bug” in QuickParse is actually a “feature” used by this other code.&nbsp; </p>
<p>Now maybe if I had found that code/comment sooner, it would have saved me a couple hours of debugging.&nbsp; But it would have cost me all the code understanding I gained during the debugging session.&nbsp; I have a number of Intellisense reliability issues to fix, as well as some new feature work in the area ahead of me, so it is very much worthwhile for me to get a deep understanding of how everything here works, so that I have this all “cached into my brain” for my next few weeks of work.</p>
<p>Anyway, that “feature” of QuickParse and the nearby code is a rather subtle and ugly to my eye, so now it’s time to…</p>
<h2>Refactor</h2>
<p>In the course of my investigation, I’ve already found a few cleanups that don’t break any tests, and so I can move the code in the general direction I want it to go, even if I’m not all done fixing things yet.&nbsp; Our suite of unit tests gives me the confidence to make changes to this “code I’d never seen prior to a couple days ago”.&nbsp; (My own manual testing inside Visual Studio, getting a code review approved, and having the QA group poking at the product, all also inspire more confidence that regressions will be discovered, but the unit tests provide the most <em>immediate </em>feedback that things are ok.)</p>
<p>I don’t yet have a tidy end to this fixing-an-Intellisense-bug story, as I’ve brought you up to date now (right now I understand the issue, but haven’t fixed the bug and got all the tests green yet).&nbsp; But that’s ok, because this particular narrative is just a means to an end, a way to describe how unit tests and debugging lead to understanding of code.&nbsp; So let me wrap up.</p>
<h2>Summary</h2>
<p>When you have good unit tests, everything is better; if you’re already a TDD-er, then&nbsp; saying that is just preaching to the choir.&nbsp; And when you have a good debugger, using that tool is a great way to learn about an unfamiliar code base (stepping through code, setting breakpoints, looking at stacks, changing values of locals or the next statement to see how things react).&nbsp; Put those two together, and the effect is even more powerful.&nbsp; Unit tests + debugger = code understanding!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/lorgonblog.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/lorgonblog.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/lorgonblog.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/lorgonblog.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/lorgonblog.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/lorgonblog.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/lorgonblog.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/lorgonblog.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/lorgonblog.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/lorgonblog.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/lorgonblog.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/lorgonblog.wordpress.com/161/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/lorgonblog.wordpress.com/161/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/lorgonblog.wordpress.com/161/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=lorgonblog.wordpress.com&amp;blog=16474804&amp;post=161&amp;subd=lorgonblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://lorgonblog.wordpress.com/2010/10/08/unit-tests-debugger-code-understanding/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad588a46e9e78dced5c6dbcf1355bd09?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">brianmcn</media:title>
		</media:content>
	</item>
	</channel>
</rss>
