<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>voyce &#187; Visual Studio</title>
	<atom:link href="http://www.voyce.com/index.php/tag/visual-studio/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.voyce.com</link>
	<description>Programming and debugging tidbits</description>
	<lastBuildDate>Sun, 15 Jan 2012 13:10:46 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Looking back at 2011</title>
		<link>http://www.voyce.com/index.php/2012/01/04/looking-back-at-2011/</link>
		<comments>http://www.voyce.com/index.php/2012/01/04/looking-back-at-2011/#comments</comments>
		<pubDate>Wed, 04 Jan 2012 23:07:47 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[F#]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[2011]]></category>
		<category><![CDATA[kinect]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[WinDbg]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=1408</guid>
		<description><![CDATA[A quick look back at some of the stuff I've been doing this year.]]></description>
			<content:encoded><![CDATA[<p>Well, we&#8217;re a few days into 2012 and no armageddon yet, so it&#8217;s probably safe to take a quick glance back over our shoulder at some of the technical stuff that&#8217;s flashed past in the preceding 12 months.<br />
<span id="more-1408"></span></p>
<h2>Work: Using F# in anger</h2>
<p>During working hours (and sometimes beyond) I&#8217;ve been developing a large project using lots of F#, a little bit of C# and a bit too much XAML. It&#8217;s quite an interesting mix, with technologies that have a vastly different outlook on life: F# with it&#8217;s strong, compile-time type checking and XAML with its, err, not-so-strong type checking. In fact, XAML and WPF play so fast and loose with types, that errors in the binding mechanism only happen at run-time and are almost always eaten silently. As you can imagine, this makes for some fun debugging. All I can say is thank goodness for <a href="http://snoopwpf.codeplex.com/">Snoop</a>.</p>
<p>We have a quite a substantial amount of ViewModel code in F# (tens of thousands of lines), much of it using <code>Async</code> to allow us to create responsive UIs without requiring tons of boilerplate code. Generally it works nicely, but I do have some concerns about the amount of thread hopping going on, and how that will affect performance. Especially as we break things down into pretty small pieces of functionality, sometimes just a few simple operations, and each is run on the thread pool. I don&#8217;t have any concrete figures to go on here, and I&#8217;m hoping we don&#8217;t end up in a situation where we sacrifice user productivity for developer productivity. Time (and perfmon) will tell.</p>
<h3>Debugging</h3>
<p>I&#8217;ve done less hardcore WinDbg stuff this year. In fact, a couple of times I&#8217;ve been guilty of jumping in with the debugger where it probably would&#8217;ve been more effective to take a high-level look first. A case of having a debugger-shaped hammer, and everything looking like a nail.</p>
<h3>Moving to 64bit</h3>
<p>A very positive thing that happend this year was the move to 64-bit Windows 7 for development at work, meaning that Visual Studio actually stays up without crashing for more than an hour. Previously I&#8217;d been having a terrible time: the combination of a couple of large-ish F# projects and 32-bit XP caused frequent VS out-of-memory errors, which was very frustrating. Luckily the move to Windows 7 has resolved it, and I can even run more than a handful of apps at the same time; what a luxury. </p>
<h2>Home: iOS</h2>
<p>After a long day at work, I finally get to go home, put the kids to bed and then my feet up, and break-out Xcode for a bit of iOS hacking. This year I&#8217;ve been feeling like I&#8217;m finally getting my head around some of the things that are fundamental in iOS development; from Objective-C concepts like release/retain semantics to iOS specifics, view controllers, table views etc. Previously I&#8217;ve been guilty of some copy-and-paste coding, mostly because it&#8217;s pretty slow going getting up to speed with new tech (and the myriad iOS APIs) when you&#8217;re only getting to do it for a few hours while knackered after work. Well, that&#8217;s my excuse anyway.</p>
<p>I&#8217;ve been trying to finish off some of the apps that I&#8217;ve started, but not shipped. I tend to procrastinate a bit (massive understatement), and of course things aren&#8217;t helped by the development &#8216;fat tail&#8217;, where the last 20% &#8211; polishing and getting things &#8216;just right&#8217; &#8211; takes at least 80% of the time. My 2010 post on <a href="http://www.voyce.com/index.php/2010/04/10/creating-an-ipad-flip-clock-with-core-animation/">Core Animation flip clocks</a> continues to get a lot of traffic, and I finally bit the bullet and posted a (free!) <a href="http://itunes.com/apps/flipclock">app</a> that uses it and it&#8217;s getting a lot of downloads, which is nice. I also had a look at iAd, which I&#8217;ll reserve judgement on for the time being, at the minute it&#8217;s not looking particularly lucrative&#8230;</p>
<p>As well as iOS stuff, I also took a look at OpenGL. I tend to do this every now and again, each time dipping in a little further and understanding a bit more. This time round it was looking at shaders (in OpenGL ES 2.0) and integrating with <a href="http://www.voyce.com/index.php/2011/11/18/creating-a-physics-based-opengl-ios-app/">Bullet physics</a>. My learning was certainly helped by this excellent <a href="http://arcsynthesis.org/gltut/">Learning Modern 3D Graphics Programming</a> tutorial.</p>
<h3>Kinect and F#</h3>
<p>Also while at home I finally got around to setting-up by my Kinect to do a bit of F# hacking. In the end I didn&#8217;t produce <a href="http://www.voyce.com/index.php/2011/09/05/kinect-sdk-with-f/">very much</a>, but it was pretty good fun anyway.</p>
<h2>Bring on 2012</h2>
<p>So, to sum it up: more of the same really, I guess. Although this year there&#8217;s definitely been a bit more of a focus on UI development, in both WPF and iOS, which I&#8217;ve been enjoying. It does tend to feel a bit schizophrenic, switching between technologies and platforms at the end of the working day. It can be interesting to identify the common themes and significant differences in the two approaches to GUI development. </p>
<p>This year I&#8217;m hoping to make my blogging a bit more regular, but who knows if I&#8217;ll be able to stick to it&#8230; If there&#8217;s anything you&#8217;d particularly like me to focus on, feel free to leave a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2012/01/04/looking-back-at-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++: The oldest new kid on the block</title>
		<link>http://www.voyce.com/index.php/2011/09/18/cpp-the-oldest-new-kid-on-the-block/</link>
		<comments>http://www.voyce.com/index.php/2011/09/18/cpp-the-oldest-new-kid-on-the-block/#comments</comments>
		<pubDate>Sat, 17 Sep 2011 23:06:09 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Rant]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[win32]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=1294</guid>
		<description><![CDATA[Is C++ coming back to a warm welcome from Microsoft?  ]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.voyce.com/wp-content/uploads/2011/09/ballmer_cpp.png"><img src="http://www.voyce.com/wp-content/uploads/2011/09/ballmer_cpp.png" alt="Tasty" title="Tasty" width="200" height="200" class="alignright size-full wp-image-1296" /></a>Nobody could have failed to notice the recent resurgence of interest in the C++ programming language. In particular, the recent <a href="http://www.buildwindows.com/">Build</a> conference was the most we’ve seen Microsoft talking about C++ for several years. Why has a language that’s been languishing in the “prehistoric irrelevance” category for so long suddenly come back into vogue?<br />
<span id="more-1294"></span></p>
<h3>Dark Days</h3>
<p>We should bear in mind that in some camps, C++ never went away. The financial, scientific and games programming communities have bravely kept the fires burning.</p>
<p>Why? Primarily performance. In these industries performance is a feature, it’s a key differentiator, and it will help you make money. Can you say the same for an enterprise app (there I go, using that term disparagingly again) that just displays a form interface over a relational database?</p>
<p>However, even in the C++ bastions, the language was getting a bad press. I can only speak for the finance industry, where I’ve been working for the past 10 years, but even here the focus briefly switched away from raw performance to complex (overly-complex, dangerously-complex, as hindsight tells us) trades where getting to market first with something new was key: developer productivity was key. Flexibility and generality was key.</p>
<p>In that case, you don’t want to be dealing with the vagaries of subtle errors, crashes and memory leaks that can easily creep in when you’re using a language as low-level as C++. You just want to be able to release quickly. You probably want to be using a managed language.</p>
<p>In fact, C++ was getting a bad press all over. The functional power that was provided in languages like Haskell and F# &#8211; and being hastily added to C# &#8211; was missing or awkwardly implemented in C++. The provision of things like the .NET thread pool provided programmers on the CLR an easy way to schedule asynchronous tasks, and it was being touted as the only way to survive in the highly-parallel near-future. Of course, it was possible to do this stuff in C++, it was just more difficult.   </p>
<p>Despite this, the programming community widely understood the power that C++ brings, but also that it has to be wielded carefully. Witness the oft-repeated jokes about the fact that when you shoot yourself in the foot with C++, you tend to blow your leg off. There were even tensions within Microsoft, with the pro-managed DevDiv vs the hardcore, native-favouring Windows division.</p>
<h3>The New Order</h3>
<p>So what’s changed? Herb Sutter’s recent <a href="http://channel9.msdn.com/posts/C-and-Beyond-2011-Herb-Sutter-Why-C">talk</a> covered many of the reasons why C++ is relevant again, and the most obvious reason is the emergence and importance of mobile devices and data centres. </p>
<p>They have a completely different set of requirements than the desktop: they focus on squeezing the best experience out of every available cycle (and corresponding minute of battery life), and the most performance out of every watt of data centre power per degree of cooling. We’re seeing the impact of the smartphone in your pocket and the data-centric web and social media reflecting back onto the languages we use to write software.  </p>
<p>Managed languages fall down in some important areas here. They sacrifice memory efficiency to the god of garbage collection and they offer fewer opportunities for aggressive compiler optimisations, including, in the case of .NET, making use of chip-provided performance features like SIMD instructions.</p>
<p>Nowadays in more and more of the computing industry, it’s the hardware that’s driving the development choices, not the other way around.</p>
<p>With resource-constricted platforms, you want to be doing more of the heavy lifting offline, at compile time, not at run-time with a JIT compiler.</p>
<h3>How the iPhone showed devs don&#8217;t care</h3>
<p>While (parts of) Microsoft were busy pushing the managed languages hard, Apple was quietly producing game-changing pieces of hardware that the device-carrying public were buying in their hordes. And they weren’t just buying devices, they were buying apps to play on these devices &#8211; in their millions. Lots of developers wanted a piece of this action but &#8211; quelle horreur! &#8211; You had to use an obscure variant of C to create them.</p>
<p>But &#8211; surprise, surprise &#8211; developers did it anyway. Luckily, they weren’t on their own, but this time rather than a managed runtime, they had an API to use. And they had to use it; it was, and is, literally a condition of sale that your app uses only the APIs that Apple provide and in the way that they intended. Whatever your view on the fairness of this approach, having a restricted surface area and well defined set of libraries helps developers win back some of the productivity they might otherwise have sacrificed by using Objective-C.</p>
<p>Microsoft must’ve been looking askance at this, wondering how Apple had so effectively switched the model around. MS had been based on the idea of developer productivity being king and the hardware being utterly insignificant. Now developers were writing code in a language that was broadly derided by people in the programming community, yet they were in a virtuous circle where writing apps helped to ship hardware that increased the market for their apps. </p>
<h3>We need libraries</h3>
<p>Is it possible to find a good balance between the raw power of C++ and the productivity of managed languages? I think it is; and partly it comes down to having a good set of libraries. When I say good, I mean consistent, relevant, well-documented, easily available set of libraries. Can you see where C++ may have struggled here before?</p>
<p>For the low-level, programming task oriented basics, Boost is the answer. Seriously, Boost always seems to be the answer to questions of “how do I do X in C++?” where X is a modern programming technique. Smart pointers, lambdas, higher-order functions… they’re all there. </p>
<p>A few years ago if you were working in C++, you didn’t have many options apart from vanilla STL, Boost, and writing-it-yourself (again). Now, the STL and the language itself is richer and anecdotally, organisations are more receptive to the use of Boost. So hopefully, this combination gives us back access to most of the functionality that’s available to managed developers in their pre-packaged base class libraries.</p>
<h3>C++ and Apps</h3>
<p>But how is that going to help people use it to produce compelling apps and “experiences” (cough) and specifically, how is Microsoft going to use its developer productivity nous to keep Windows relevant in the new hardware markets? </p>
<p>They need something else; something like the Apple Core frameworks. It looks like this is what Microsoft is talking about with Windows 8 and the Windows Runtime. It’s suddenly not embarrassed to admit that, hey, Windows itself is written in C++, so maybe you shouldn’t have to go through a managed ‘interpretation’ of the existing APIs, one that’s exclusively available to managed languages.</p>
<p>Of course, Microsoft can’t do anything as radical as forcing all developers targeting a mobile or tablet platform to use C++. For them, programmers, rather than any particular hardware, are the bread-and-butter, so they tend to have a slightly less dictator-style relationship with devs than Apple does. </p>
<p>Judging from what I’ve seen from Build, Microsofts chosen approach is to provide language-specific “projections” (their term) from the Windows Runtime layer into a variety of languages, including C++. The native C++ types are mapped into corresponding concepts in the vernacular of the higher level languages; Javascript, C# etc. They’ve gone to some lengths, it seems, to ensure that transitions between levels are efficient. Using C++ at both levels should be the fast path, and of course you can mix it freely with code that, for example, uses Boost or other C++ libraries. </p>
<p>Additionally and importantly, as well as basic types, collections etc, the Windows Runtime also contains all of the rich APIs for accessing app-level functionality; things like image capture, sound and geolocation. So suddenly, all of this stuff is available in all its glory directly from C++ &#8211; and other languages too via cheap bridges. What they’ve essentially got is an identical copy of the architecture that exists in the iOS world, while still attempting to keep non C++ developers on-side. </p>
<h3>The Return&#8230;?</h3>
<p>So, have Microsoft managed to bring C++ in from the cold? They seem to have admitted, at least to themselves, that developers will need to use it in order to effectively target some platforms, and they’ve used their tooling experience to make it look and feel like a managed language in their IDEs, as well as leveraging their compiler technology to do some additional useful performance tricks. It feels like C++ was a fundamental concern in the redesign of the new alternative to the creaking Win32 API.</p>
<p>But will the transition be something to make current developers switch to C++, especially those who’ve been used to living in the cosseted managed world? Perhaps, if the Microsoft-based tablet market becomes as compelling &#8211; read, large &#8211; as Apple’s. Otherwise I don’t see any reason why developers who don’t have specific platform or other runtime requirements would move; for the majority of environments, developer time is still the dominant cost, so developer productivity will still be paramount. </p>
<p>The gap between managed and unmanaged languages has certainly narrowed in that area, but it still exists. C++ is still proving surprisingly relevant, despite its 30+ years, and hopefully its use in new and different areas of computing will feed back into improvements in the language and libraries for everyone’s benefit. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2011/09/18/cpp-the-oldest-new-kid-on-the-block/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calling MSBuild tasks with F#</title>
		<link>http://www.voyce.com/index.php/2010/03/31/calling-msbuild-tasks-with-fsharp/</link>
		<comments>http://www.voyce.com/index.php/2010/03/31/calling-msbuild-tasks-with-fsharp/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 17:31:15 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[msbuild]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=774</guid>
		<description><![CDATA[It's easy to call MSBuild tasks directly from F#. Although possibly unnecessary.]]></description>
			<content:encoded><![CDATA[<p>The other day I was trying to understand some strange behaviour in msbuild with regard to how it resolves referenced assemblies. I thought I&#8217;d try directly invoking the tasks that are used during the build, specifically <a href="http://msdn.microsoft.com/en-us/library/9ad3f294.aspx">ResolveAssemblyReference</a>, so that I could experiment with them in F# interactive. It turned out to be pretty straightforward.<br />
<span id="more-774"></span><br />
In this example I&#8217;m attempting to resolve a reference to &#8220;class1.dll&#8221; from the GAC, taking into account the contents of the app.config (which can be used change the version resolution in MSBuild):</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #066; font-weight: bold;">#I @&quot;C:\winnt\Microsoft.NET\Framework\v2.0.50727\&quot;</span>
<span style="color: #066; font-weight: bold;">#r @&quot;Microsoft.Build.Tasks.dll&quot;</span>
<span style="color: #066; font-weight: bold;">#r @&quot;Microsoft.Build.Utilities.dll&quot;</span>
<span style="color: #066; font-weight: bold;">#r @&quot;Microsoft.Build.Framework.dll&quot;</span>
<span style="color: #066; font-weight: bold;">#r @&quot;Microsoft.Build.Engine.dll&quot;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">open</span> System
<span style="color: #06c; font-weight: bold;">open</span> Microsoft<span style="color: #000080;">.</span><span style="color: #505090;">Build</span><span style="color: #000080;">.</span><span style="color: #505090;">Framework</span>
<span style="color: #06c; font-weight: bold;">open</span> Microsoft<span style="color: #000080;">.</span><span style="color: #505090;">Build</span><span style="color: #000080;">.</span><span style="color: #505090;">Utilities</span>
<span style="color: #06c; font-weight: bold;">open</span> Microsoft<span style="color: #000080;">.</span><span style="color: #505090;">Build</span><span style="color: #000080;">.</span><span style="color: #505090;">Tasks</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">do</span>
    <span style="color: #06c; font-weight: bold;">let</span> t <span style="color: #000080;">=</span> 
        ResolveAssemblyReference<span style="color: #000080;">&#40;</span>Silent <span style="color: #000080;">=</span> <span style="color: #06c; font-weight: bold;">true</span>,
            Assemblies <span style="color: #000080;">=</span> <span style="color: #000080;">&#91;</span><span style="color: #000080;">|</span> <span style="color: #06c; font-weight: bold;">upcast</span> TaskItem<span style="color: #000080;">&#40;</span> ItemSpec<span style="color: #000080;">=</span><span style="color: #008080;">&quot;class1&quot;</span> <span style="color: #000080;">&#41;</span> <span style="color: #000080;">|</span><span style="color: #000080;">&#93;</span>,
            AllowedAssemblyExtensions <span style="color: #000080;">=</span> <span style="color: #000080;">&#91;</span><span style="color: #000080;">|</span><span style="color: #008080;">&quot;.dll&quot;</span><span style="color: #000080;">|</span><span style="color: #000080;">&#93;</span>,
            AppConfigFile <span style="color: #000080;">=</span> <span style="color: #008080;">&quot;c:<span style="color: #008080; font-weight: bold;">\\</span>dev<span style="color: #008080; font-weight: bold;">\\</span>myapp<span style="color: #008080; font-weight: bold;">\\</span>myapp.exe.config&quot;</span>,
            SearchPaths <span style="color: #000080;">=</span> <span style="color: #000080;">&#91;</span><span style="color: #000080;">|</span><span style="color: #008080;">&quot;{GAC}&quot;</span><span style="color: #000080;">|</span><span style="color: #000080;">&#93;</span>
            <span style="color: #000080;">&#41;</span>
    <span style="color: #06c; font-weight: bold;">match</span> t<span style="color: #000080;">.</span><span style="color: #505090;">Execute</span><span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span> <span style="color: #06c; font-weight: bold;">with</span>
    <span style="color: #000080;">|</span> <span style="color: #06c; font-weight: bold;">true</span>  <span style="color: #000080;">-&gt;</span> printf <span style="color: #008080;">&quot;%A<span style="color: #008080; font-weight: bold;">\n</span>&quot;</span> t<span style="color: #000080;">.</span><span style="color: #505090;">ResolvedFiles</span>
    <span style="color: #000080;">|</span> <span style="color: #06c; font-weight: bold;">false</span> <span style="color: #000080;">-&gt;</span> printf <span style="color: #008080;">&quot;Task failed&quot;</span></pre></div></div>

<p>The output is:</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #000080;">&#91;</span><span style="color: #000080;">|</span>C<span style="color: #000080;">:</span>\WINNT\assembly\GAC_MSIL\class1\1<span style="color: #000080;">.</span>1<span style="color: #000080;">.</span>8<span style="color: #000080;">.</span>0__120bce90f68b861a\class1<span style="color: #000080;">.</span><span style="color: #505090;">dll</span><span style="color: #000080;">|</span><span style="color: #000080;">&#93;</span></pre></div></div>

<p>The code makes good use of F#&#8217;s named constructor arguments, which map to property setters on the object we&#8217;ve just created. We can also create the arrays of <a href="http://msdn.microsoft.com/en-us/library/microsoft.build.utilities.taskitem.aspx">TaskItem</a>s and strings fairly easily, although an explicit upcast is required in order to obtain the ITaskItem (F# doesn&#8217;t upcast implicitly like many object oriented languages).</p>
<p>I&#8217;ve just discovered that Jomo Fisher wrote about <a href="http://blogs.msdn.com/jomo_fisher/archive/2008/05/22/programmatically-resolve-assembly-name-to-full-path-the-same-way-msbuild-does.aspx">exactly the same thing</a> back in May 2008! He mentions using an object expression in order to provide an implementation of <code>IBuildEngine</code>, which I&#8217;m getting away with by setting the <code>Silent</code> property on the <code>ResolveAssemblyReference</code> task, meaning that it never attempts to obtain the logging context from the build engine.</p>
<p>Another gotcha here is the fact that versions of various interfaces including <code>IBuildEngine</code> and <code>ITaskItem</code> exist in both the 2.0.0.0 and 3.5.0.0 versions of the <code>Microsoft.Build.Framework</code> assembly. Be careful that you reference the correct version for the task that you&#8217;re calling. Normally it will be the 2.0 versions, in which case you&#8217;ll need to use explicit file references in your script, adding the directory to the library include path:</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #066; font-weight: bold;">#I @&quot;C:\winnt\Microsoft.NET\Framework\v2.0.50727\&quot;</span>
<span style="color: #066; font-weight: bold;">#r @&quot;Microsoft.Build.Framework.dll&quot;</span></pre></div></div>

<p>Rather than partially qualified assembly references:</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #066; font-weight: bold;">#r @&quot;Microsoft.Build.Framework&quot;</span></pre></div></div>

<p>As the latter will resolve to the latest installed version of the assembly, 3.5, which is not what you want. Look out for errors like:</p>
<blockquote><p>
System.InvalidCastException: Unable to cast object of type &#8216;Microsoft.Build.Utilities.TaskItem&#8217; to type &#8216;Microsoft.Build.Framework.ITaskItem&#8217;.
</p></blockquote>
<h2>Alternatives</h2>
<p><div id="attachment_777" class="wp-caption alignleft" style="width: 310px"><a href="http://www.voyce.com/wp-content/uploads/2010/03/msbuild_verbosity.png"><img src="http://www.voyce.com/wp-content/uploads/2010/03/msbuild_verbosity-300x174.png" alt="The Tools|Options MSBuild verbosity setting" title="msbuild_verbosity" width="300" height="174" class="size-medium wp-image-777" /></a><p class="wp-caption-text">The Tools|Options MSBuild verbosity setting</p></div>Although this was a useful experiment, I discovered that it&#8217;s often much easier to just increase the MSBuild verbosity and wade through the reams of output to find what you&#8217;re after (but then <a href="http://en.wiktionary.org/wiki/yak_shaving">the Yak will remain hairy</a>). There&#8217;s an option in Tools|Options|Projects and Solutions|Build and Run to change the output level from Silent to Diagnostic. Beware: you can easily get megabytes of text output from diagnostic mode!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2010/03/31/calling-msbuild-tasks-with-fsharp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Generating and plotting random numbers</title>
		<link>http://www.voyce.com/index.php/2009/11/24/generating-and-plotting-random-numbers/</link>
		<comments>http://www.voyce.com/index.php/2009/11/24/generating-and-plotting-random-numbers/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 23:44:55 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Finance]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=562</guid>
		<description><![CDATA[An example of generating random numbers in F# and visualising their distribution using the WPF charting control.]]></description>
			<content:encoded><![CDATA[<p>For a while now I&#8217;ve been planning to write a blog post about pricing financial instruments using Monte Carlo techniques in F#. As part of this I needed to generate normally distributed random numbers, and while putting together the code to do it I realised it was interesting enough to warrant its own post.</p>
<p>I&#8217;m making use of a few F#/.NET idioms to make the process easier. For instance, sequences (.NET&#8217;s <code>IEnumerable</code>) are used as the source of uniformly distributed random numbers. Also, to verify that the resulting numbers are actually normally distributed, we can easily use existing WPF/silverlight controls to visualise the values direct from within Visual Studio, in a manner similar to <a href="http://www.voyce.com/index.php/2009/06/26/black-scholes-option-pricing-using-fsharp-and-wpf/">this previous post</a> &#8211; but without having to write the plotting code ourselves.<br />
<span id="more-562"></span></p>
<h3>Implementation</h3>
<p>So firstly, we create the random number stream:</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">let</span> rr <span style="color: #000080;">=</span> System<span style="color: #000080;">.</span><span style="color: #505090;">Random</span><span style="color: #000080;">&#40;</span>System<span style="color: #000080;">.</span><span style="color: #505090;">DateTime</span><span style="color: #000080;">.</span><span style="color: #505090;">Now</span><span style="color: #000080;">.</span><span style="color: #505090;">Minute</span><span style="color: #000080;">&#41;</span>
<span style="color: #06c; font-weight: bold;">let</span> rands <span style="color: #000080;">=</span> seq <span style="color: #000080;">&#123;</span> <span style="color: #06c; font-weight: bold;">while</span> <span style="color: #06c; font-weight: bold;">true</span> <span style="color: #06c; font-weight: bold;">do</span> <span style="color: #06c; font-weight: bold;">yield</span> rr<span style="color: #000080;">.</span><span style="color: #505090;">NextDouble</span><span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span> <span style="color: #000080;">&#125;</span></pre></div></div>

<p>As you can see <code>rands</code> is an infinite sequence. As such, you should be wary of the &#8220;eager&#8221; functions from the Seq module that attempt to consume the entire sequence at once, they&#8217;ll obviously cause a problem here. Also notice that I&#8217;ve picked a somewhat dubious seed for the random number generator, as this is only for demonstration purposes.</p>
<p>In order to obtain normally distributed random numbers I&#8217;m using the <a href="http://en.wikipedia.org/wiki/Box–Muller_transform">Box-Muller</a> transform. I started off with an implementation transcribed from VBA (from <a href="http://www.amazon.com/gp/product/0470319585?ie=UTF8&#038;tag=wwwvoycecom-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=0470319585">Wilmott</a><img src="http://www.assoc-amazon.com/e/ir?t=wwwvoycecom-20&#038;l=as2&#038;o=1&#038;a=0470319585" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> et al) &#8211; yes, yes, I know &#8211; but of course this used mutable references. Not nice. So I reworked it a little to use <code>Seq.pick</code>, which takes items from the sequence while a predicate returns <code>None</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">let</span> boxMuller <span style="color: #06c; font-weight: bold;">_</span> <span style="color: #000080;">=</span>
    <span style="color: #06c; font-weight: bold;">let</span> <span style="color: #000080;">&#40;</span>x,dist<span style="color: #000080;">&#41;</span> <span style="color: #000080;">=</span> 
        rands
        <span style="color: #000080;">|&gt;</span> Seq<span style="color: #000080;">.</span><span style="color: #505090;">pick</span> <span style="color: #000080;">&#40;</span><span style="color: #06c; font-weight: bold;">fun</span> x <span style="color: #000080;">-&gt;</span>
            <span style="color: #06c; font-weight: bold;">let</span> x <span style="color: #000080;">=</span> <span style="color: #c6c;">2.0</span> <span style="color: #000080;">*</span> x <span style="color: #000080;">-</span> <span style="color: #c6c;">1.0</span>
            <span style="color: #06c; font-weight: bold;">let</span> y <span style="color: #000080;">=</span> <span style="color: #c6c;">2.0</span> <span style="color: #000080;">*</span> <span style="color: #000080;">&#40;</span><span style="color: #000080;">&#40;</span>Seq<span style="color: #000080;">.</span><span style="color: #505090;">take</span> <span style="color: #c6c;">1</span> rands<span style="color: #000080;">&#41;</span> <span style="color: #000080;">|&gt;</span> Seq<span style="color: #000080;">.</span><span style="color: #505090;">hd</span><span style="color: #000080;">&#41;</span> <span style="color: #000080;">-</span> <span style="color: #c6c;">1.0</span>
            <span style="color: #06c; font-weight: bold;">match</span> <span style="color: #000080;">&#40;</span>x <span style="color: #000080;">*</span> x <span style="color: #000080;">+</span> y <span style="color: #000080;">*</span> y<span style="color: #000080;">&#41;</span> <span style="color: #06c; font-weight: bold;">with</span>
                <span style="color: #000080;">|</span> dist <span style="color: #06c; font-weight: bold;">when</span> dist <span style="color: #000080;">&lt;</span> <span style="color: #c6c;">1.0</span> <span style="color: #000080;">-&gt;</span> Some <span style="color: #000080;">&#40;</span>x,dist<span style="color: #000080;">&#41;</span>
                <span style="color: #000080;">|</span> dist <span style="color: #000080;">-&gt;</span> None
            <span style="color: #000080;">&#41;</span> 
    x <span style="color: #000080;">*</span> Math<span style="color: #000080;">.</span><span style="color: #505090;">Sqrt</span><span style="color: #000080;">&#40;</span><span style="color: #000080;">-</span><span style="color: #c6c;">2.0</span> <span style="color: #000080;">*</span> Math<span style="color: #000080;">.</span><span style="color: #505090;">Log</span><span style="color: #000080;">&#40;</span>dist<span style="color: #000080;">&#41;</span> <span style="color: #000080;">/</span> dist<span style="color: #000080;">&#41;</span></pre></div></div>

<p>It&#8217;s not particularly efficient as we&#8217;re consuming two uniform numbers to generate one normal one &#8211; hence the additional Seq.take within the pick. Of course we could change the function to return the 2 generated numbers as an extra element in the tuple.</p>
<p>Next, let&#8217;s generate some numbers, and get them in a suitable form to display:</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">let</span> makeData <span style="color: #06c; font-weight: bold;">_</span> <span style="color: #000080;">=</span>
    Seq<span style="color: #000080;">.</span><span style="color: #505090;">init</span> <span style="color: #c6c;">100000</span> boxMuller
    <span style="color: #000080;">|&gt;</span> Seq<span style="color: #000080;">.</span><span style="color: #505090;">countBy</span> <span style="color: #000080;">&#40;</span><span style="color: #06c; font-weight: bold;">fun</span> d <span style="color: #000080;">-&gt;</span> 
        <span style="color: #06c; font-weight: bold;">let</span> d <span style="color: #000080;">=</span> decimal d
        Math<span style="color: #000080;">.</span><span style="color: #505090;">Round</span><span style="color: #000080;">&#40;</span>d, <span style="color: #c6c;">1</span><span style="color: #000080;">&#41;</span><span style="color: #000080;">&#41;</span>
    <span style="color: #000080;">|&gt;</span> Seq<span style="color: #000080;">.</span><span style="color: #505090;">sortBy</span> fst</pre></div></div>

<p>We initialise a sequence with an arbitrary amount of numbers (100000, enough to get a good distribution, hopefully), then use <code>Seq.countBy</code> to do a naive grouping that allows us to see how the numbers are distributed, i.e. counting how many numbers fit in each 0.10 bucket. We then sort the output by bucket. </p>
<h3>Visualisation</h3>
<p>Now we can display what we&#8217;ve got. We can create a simple WPF object-model using imperative code, including the very useful chart control from the WpfToolkit. The chart control enables us to add a series and set our <code>seq&lt;decimal * float&gt;</code> directly as the series ItemsSource, which is the standard way to specify the items for a collection control. If you specify the tuple <code>Item1</code> and <code>Item2</code> properties for the bindings, WPF will be able to access the data from each element, and that&#8217;s all you need.</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;">    <span style="color: #06c; font-weight: bold;">let</span> series <span style="color: #000080;">=</span> 
        ColumnSeries<span style="color: #000080;">&#40;</span>
            IndependentValueBinding <span style="color: #000080;">=</span> Data<span style="color: #000080;">.</span><span style="color: #505090;">Binding</span><span style="color: #000080;">&#40;</span><span style="color: #008080;">&quot;Item1&quot;</span><span style="color: #000080;">&#41;</span>,
            DependentValueBinding <span style="color: #000080;">=</span> Data<span style="color: #000080;">.</span><span style="color: #505090;">Binding</span><span style="color: #000080;">&#40;</span><span style="color: #008080;">&quot;Item2&quot;</span><span style="color: #000080;">&#41;</span>,
            ItemsSource <span style="color: #000080;">=</span> makeData <span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span><span style="color: #000080;">&#41;</span>
    <span style="color: #06c; font-weight: bold;">let</span> chart <span style="color: #000080;">=</span> Chart<span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span>
    chart<span style="color: #000080;">.</span><span style="color: #505090;">Series</span><span style="color: #000080;">.</span><span style="color: #505090;">Add</span> series
    Window<span style="color: #000080;">&#40;</span>
        Name<span style="color: #000080;">=</span><span style="color: #008080;">&quot;Plot&quot;</span>,
        Title<span style="color: #000080;">=</span><span style="color: #008080;">&quot;Normally distributed random numbers&quot;</span>,
        Width<span style="color: #000080;">=</span><span style="color: #c6c;">900.0</span>,
        Height<span style="color: #000080;">=</span><span style="color: #c6c;">700.0</span>,
        Content<span style="color: #000080;">=</span>chart,
        Visibility<span style="color: #000080;">=</span>Visibility<span style="color: #000080;">.</span><span style="color: #505090;">Visible</span><span style="color: #000080;">&#41;</span></pre></div></div>

<p>Here&#8217;s the resulting output:<br />
<img src="http://www.voyce.com/wp-content/uploads/2009/11/dist-300x233.png" alt="dist" title="dist" width="300" height="233" class="alignleft size-medium wp-image-576" />As I&#8217;ve mentioned before, this is a fantastically immediate way of doing numerical development in Visual Studio. You can enter all of this code directly into F# interactive within VS, iterate, and quickly see the effect that your changes have. It&#8217;s just as interactive as using the graph features in Excel, and the resulting code is much more easily reusable.</p>
<p><span style="visibility:hidden"> XD5RRV3XDNHN </span><br />
<script type="text/javascript" src="http://www.assoc-amazon.com/s/link-enhancer?tag=wwwvoycecom-20&#038;o=1">
</script><br />
<noscript><br />
    <img src="http://www.assoc-amazon.com/s/noscript?tag=wwwvoycecom-20" alt="" /><br />
</noscript></p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2009/11/24/generating-and-plotting-random-numbers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pinned DataTips in Visual Studio 2010 Beta 2</title>
		<link>http://www.voyce.com/index.php/2009/11/02/pinned-datatips-in-visual-studio-2010-beta-2/</link>
		<comments>http://www.voyce.com/index.php/2009/11/02/pinned-datatips-in-visual-studio-2010-beta-2/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 23:59:38 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=511</guid>
		<description><![CDATA[I&#8217;ve just noticed a nice little feature in Visual Studio 2010 Beta 2: pinned DataTips. Values displayed in the debugger as you hover over a variable can now be pinned in place and remain aligned with the source. They can even have annotations added&#8230; Tasty!
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.voyce.com/wp-content/uploads/2009/11/vs2010_pinned_datatips.png"><img src="http://www.voyce.com/wp-content/uploads/2009/11/vs2010_pinned_datatips-300x42.png" alt="vs2010_pinned_datatips" title="vs2010_pinned_datatips" width="300" height="42" class="alignleft size-medium wp-image-512" /></a>I&#8217;ve just noticed a nice little feature in Visual Studio 2010 Beta 2: pinned DataTips. Values displayed in the debugger as you hover over a variable can now be pinned in place and remain aligned with the source. They can even have annotations added&#8230; Tasty!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2009/11/02/pinned-datatips-in-visual-studio-2010-beta-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Windows SDK breaks F# Visual Studio integration</title>
		<link>http://www.voyce.com/index.php/2009/04/14/windows-sdk-breaks-fsharp-integration/</link>
		<comments>http://www.voyce.com/index.php/2009/04/14/windows-sdk-breaks-fsharp-integration/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 09:00:22 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[F#]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[crash]]></category>
		<category><![CDATA[intellisense]]></category>
		<category><![CDATA[winsdk]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=116</guid>
		<description><![CDATA[Beware! If you install the Windows SDK &#8211; perhaps to get access to the interesting looking WPF performance tools &#8211; you&#8217;ll find that it hoses your F# Visual Studio integration. I found that it causes intellisense tooltips to stop appearing, and the integrated F# interactive to crash Visual Studio. Both of these issues are a [...]]]></description>
			<content:encoded><![CDATA[<p>Beware! If you install the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=F26B1AA4-741A-433A-9BE5-FA919850BDBF&#038;displaylang=en">Windows SDK</a> &#8211; perhaps to get access to the interesting looking <a href="http://blogs.msdn.com/jgoldb/archive/2008/09/25/updated-wpfperf-performance-profiling-tools-for-wpf.aspx">WPF performance tools</a> &#8211; you&#8217;ll find that it hoses your F# Visual Studio integration. I found that it causes intellisense tooltips to stop appearing, and the integrated F# interactive to crash Visual Studio. Both of these issues are a real pain; especially the inability to see the inferred types &#8220;live&#8221;, which is pretty much essential for F# development &#8211; where the focus is on compile time correctness.</p>
<p>I remembered seeing a <a href="http://blogs.msdn.com/windowssdk/comments/7850578.aspx">post on that Windows SDK blog</a> that I&#8217;d come across relating to a similar issue with the XAML editor (I&#8217;ve been doing some work with WPF recently, more on that in a later post) so thought I&#8217;d try the steps they recommend, in short, re-registering TextMgrP.dll:</p>
<p><code>regsvr32 "%CommonProgramFiles%\Microsoft Shared\MSEnv\TextMgrP.dll"</code></p>
<p>&#8230;and all my problems went away. Hope you find this useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2009/04/14/windows-sdk-breaks-fsharp-integration/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Visual Studio Toggle Brackets Macro</title>
		<link>http://www.voyce.com/index.php/2009/02/09/visual-studio-toggle-brackets-macro/</link>
		<comments>http://www.voyce.com/index.php/2009/02/09/visual-studio-toggle-brackets-macro/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 12:35:28 +0000</pubDate>
		<dc:creator>ian</dc:creator>
				<category><![CDATA[F#]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[brackets]]></category>
		<category><![CDATA[macro]]></category>
		<category><![CDATA[parentheses]]></category>

		<guid isPermaLink="false">http://www.voyce.com/?p=85</guid>
		<description><![CDATA[After using a F# heavily for a while, I often found myself wanting to add brackets (or rather, parentheses) around some text. This is normally when adding a type specification to an argument in order to be able to use dot notation, e.g. going from:

let typeName t = t.Name

which causes &#8220;error FS0072: Lookup on object [...]]]></description>
			<content:encoded><![CDATA[<p>After using a F# heavily for a while, I often found myself wanting to add brackets (or rather, parentheses) around some text. This is normally when adding a type specification to an argument in order to be able to use dot notation, e.g. going from:</p>
<div style="font-family: Lucida Sans Typewriter; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: blue;">let</span> typeName t = t.Name</p>
</div>
<p>which causes &#8220;error FS0072: Lookup on object of indeterminate type based on information prior to this program point&#8221;, to the correct:</p>
<div style="font-family: Lucida Sans Typewriter; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: blue;">let</span> typeName <strong>(t:Type)</strong> = t.Name</p>
</div>
<p>(These are obviously simplistic examples!)</p>
<p>So I broke out the Visual Studio macro editor for the first time in a while, and put together something to toggle brackets around the currently selected text. It&#8217;s naive, but, combined with Shift+Alt+Left Arrow to select the previous word, it&#8217;s effective:</p>
<div style="font-family: Courier New; font-size: 10pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: blue;">Public</span> <span style="color: blue;">Sub</span> AddBrackets()</p>
<p style="margin: 0px;"><span style="color: blue;"> Dim</span> s <span style="color: blue;">As</span> <span style="color: blue;">Object</span> = DTE.ActiveWindow.Selection()</p>
<p style="margin: 0px;"><span style="color: blue;"> If</span> s.Text.StartsWith(<span style="color: #a31515;">&#8220;(&#8221;</span>) <span style="color: blue;">And</span> s.Text.EndsWith(<span style="color: #a31515;">&#8220;)&#8221;</span>) <span style="color: blue;">Then</span></p>
<p style="margin: 0px;">s.Text = s.Text.Substring(1, s.Text.Length &#8211; 2)</p>
<p style="margin: 0px;"><span style="color: blue;"> Else</span></p>
<p style="margin: 0px;">s.Text = <span style="color: #a31515;">&#8220;(&#8221;</span> + s.Text + <span style="color: #a31515;">&#8220;)&#8221;</span></p>
<p style="margin: 0px;"><span style="color: blue;"> End</span> <span style="color: blue;">If</span></p>
<p style="margin: 0px;"><span style="color: blue;">End</span> <span style="color: blue;">Sub</span></p>
</div>
<p>Copy this text into a module within your macro project, and assign a suitable keystroke using Tools|Customize|Keyboard.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.voyce.com/index.php/2009/02/09/visual-studio-toggle-brackets-macro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

