FPish.net - All blog entriesAll blog entries shared on FPish.net by our members.d67277c4-116b-43f1-b688-e9ef184ea916:1844013http://feedproxy.google.com/~r/JonSkeetCodingBlog/~3/vjrMXb_LK48/casting-vs-quot-as-quot-embracing-exceptions.aspxc#designCasting vs "as" - embracing exceptions<p>(I&#39;ve ended up commenting on this issue on Stack Overflow quite a few times, so I figured it would be worth writing a blog post to refer to in the future.)</p> <p>There are lots of ways of converting values from one type to another – either changing the compile-time type but actually keeping the value the same, or actually changing the value (for example converting int to double). This post will not go into all of those - it would be enormous - just two of them, in one specific situation.</p> <p>The situation we&#39;re interested in here is where you have an expression (typically a variable) of one reference type, and you want to a value with a different compile-time type, without changing the actual value. You just want a different &quot;view&quot; on a reference. The two options we&#39;ll look at are <a href="http://msdn.microsoft.com/en-us/library/ms173105.aspx">casting</a> and using the <a href="http://msdn.microsoft.com/en-us/library/vstudio/cscsdfbt.aspx">&quot;as&quot; operator</a>. So for example:</p> <div class="code"><span class="ReferenceType">object</span> x = <span class="String">&quot;foo&quot;</span>;&#160; <br /><span class="ReferenceType">string</span> cast = (<span class="ReferenceType">string</span>) x;&#160; <br /><span class="ReferenceType">string</span> asOperator = x <span class="Keyword">as</span>&#160;<span class="ReferenceType">string</span>; </div> <p>The major differences between these are pretty well-understood:</p> <ul> <li>Casting is also used for other conversions (e.g. between value types); &quot;as&quot; is only valid for reference type expressions (although the target type can be a nullable value type) </li> <li>Casting can invoke user-defined conversions (if they&#39;re applicable at compile-time); &quot;as&quot; only ever performs a reference conversion </li> <li>If the actual value of the expression is a non-null reference to an incompatible type, casting will throw an <a href="http://msdn.microsoft.com/en-us/library/system.invalidcastexception.aspx">InvalidCastException</a> whereas the &quot;as&quot; operator will result in a null value instead </li> </ul> <p>The last point is the one I&#39;m interested in for this post, because it&#39;s a highly visible symptom of many developers&#39; allergic reaction to exceptions. Let&#39;s look at a few examples.</p> <h3>Use case 1: Unconditional dereferencing</h3> <p>First, let&#39;s suppose we have a number of buttons all with the same event handler attached to them. The event handler should just change the text of the button to &quot;Clicked&quot;. There are two simple approaches to this:</p> <div class="code"><span class="ValueType">void</span> HandleUsingCast(<span class="ReferenceType">object</span> sender, EventArgs e)&#160; <br />{&#160; <br />&#160;&#160;&#160; Button button = (Button) sender;&#160; <br />&#160;&#160;&#160; button.Text = <span class="String">&quot;Clicked&quot;</span>;&#160; <br />} <br /> <br /><span class="ValueType">void</span> HandleUsingAs(<span class="ReferenceType">object</span> sender, EventArgs e)&#160; <br />{&#160; <br />&#160;&#160;&#160; Button button = (Button) sender;&#160; <br />&#160;&#160;&#160; button.Text = <span class="String">&quot;Clicked&quot;</span>;&#160; <br />} </div> <p>(Obviously these aren&#39;t the method names I&#39;d use in real code - but they&#39;re handy for differentiating between the two approaches within this post.)</p> <p>In both cases, when the value of &quot;sender&quot; genuinely refers to a Button instance, the code will function correctly. Likewise when the value of &quot;sender&quot; is null, both will fail with a NullReferenceException on the second line. However, when the value of &quot;sender&quot; is a reference to an instance which <em>isn&#39;t</em> compatible with Button, the two behave differently:</p> <ul> <li>HandleUsingCast will fail on the first line, throwing a ClassCastException which includes information about the actual type of the object </li> <li>HandleUsingAs will fail on the second line with a NullReferenceException </li> </ul> <p>Which of these is the more useful behaviour? It seems pretty unambiguous to me that the HandleUsingCast option provides significantly more information, but still I see the code from HandleUsingAs in examples on Stack Overflow... sometimes with the rationale of &quot;I prefer to use as instead of a cast to avoid exceptions.&quot; There&#39;s going to be an exception anyway, so there&#39;s really no good reason to use &quot;as&quot; here.</p> <h3>Use case 2: Silently ignoring invalid input</h3> <p>Sometimes a slight change is proposed to the above code, checking for the result of the &quot;as&quot; operator not being null:</p> <div class="code"><span class="ValueType">void</span> HandleUsingAs(<span class="ReferenceType">object</span> sender, EventArgs e)&#160; <br />{&#160; <br />&#160;&#160;&#160; Button button = (Button) sender;&#160; <br />&#160;&#160;&#160; <span class="Statement">if</span> (button != <span class="Keyword">null</span>)&#160; <br />&#160;&#160;&#160; {&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; button.Text = <span class="String">&quot;Clicked&quot;</span>;&#160; <br />&#160;&#160;&#160; }&#160; <br />} </div> <p>Now we really don&#39;t have an exception. We can do this with the cast as well, using the &quot;is&quot; operator:</p> <div class="code"><span class="ValueType">void</span> HandleUsingCast(<span class="ReferenceType">object</span> sender, EventArgs e)&#160; <br />{&#160; <br />&#160;&#160;&#160; <span class="Statement">if</span> (sender <span class="Keyword">is</span> Button)&#160; <br />&#160;&#160;&#160; {&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Button button = (Button) sender;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; button.Text = <span class="String">&quot;Clicked&quot;</span>;&#160; <br />&#160;&#160;&#160; }&#160; <br />} </div> <p>These two methods now behave the same way, but here I genuinely prefer the &quot;as&quot; approach. Aside from anything else, it&#39;s only performing a single execution-time type check, rather than checking once with &quot;is&quot; and then once again with the cast. There are potential performance implications here, but in most cases they&#39;d be insignificant - it&#39;s the <em>principle</em> of the thing that really bothers me. Indeed, this is basically the situation that the &quot;as&quot; operator was designed for. But is it an appropriate design to start with?</p> <p>In this particular case, it&#39;s very unlikely that we&#39;ll have a non-Button sender unless there&#39;s been a coding error somewhere. For example, it&#39;s unlikely that bad user input or network resource issues would lead to entering this method with a sender of (say) a TextBox. So do you <em>really</em> want to silently ignore the problem? My personal view is that the response to a detected coding error should almost always be an exception which either goes completely uncaught or which is caught at some &quot;top level&quot;, abandoning the current operation as cleanly as possible. (For example, in a client application it may well be appropriate to terminate the app; in a web application we wouldn&#39;t want to terminate the server process, but we&#39;d want to abort the processing of the problematic request.) Fundamentally, the world is not in a state which we&#39;ve really considered: continuing regardless could easily make things worse, potentially losing or corrupting data.</p> <p>If you <em>are</em> going to ignore a requested operation involving an unexpected type, at least clearly log it - and then ensure that any such logs are monitored appropriately:</p> <div class="code"><span class="ValueType">void</span> HandleUsingAs(<span class="ReferenceType">object</span> sender, EventArgs e)&#160; <br />{&#160; <br />&#160;&#160;&#160; Button button = (Button) sender;&#160; <br />&#160;&#160;&#160; <span class="Statement">if</span> (button != <span class="Keyword">null</span>)&#160; <br />&#160;&#160;&#160; {&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; button.Text = <span class="String">&quot;Clicked&quot;</span>;&#160; <br />&#160;&#160;&#160; }&#160; <br />&#160;&#160;&#160; <span class="Statement">else</span>&#160; <br />&#160;&#160;&#160; {&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="InlineComment">// Log an error, potentially differentiating between </span> <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="InlineComment">// a null sender and input of a non-Button sender. </span> <br />&#160;&#160;&#160; }&#160; <br />} </div> <h3>Use case 3: consciously handling input of an unhelpful type</h3> <p>Despite the general thrust of the previous use case, there certainly <em>are</em> cases where it makes perfect sense to use &quot;as&quot; to handle input of a type other than the one you&#39;re really hoping for. The simplest example of this is probably equality testing:</p> <div class="code"><span class="Modifier">public</span>&#160;<span class="Modifier">sealed</span>&#160;<span class="ReferenceType">class</span> Foo : IEquatable&lt;Foo&gt;&#160; <br />{&#160; <br />&#160;&#160;&#160; <span class="InlineComment">// Fields, of course </span> <br /> <br />&#160;&#160;&#160; <span class="Modifier">public</span>&#160;<span class="Modifier">override</span>&#160;<span class="ValueType">bool</span> Equals(<span class="ReferenceType">object</span> obj)&#160; <br />&#160;&#160;&#160; {&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="Statement">return</span> Equals(obj <span class="Keyword">as</span> Foo);&#160; <br />&#160;&#160;&#160; }&#160; <br /> <br />&#160;&#160;&#160; <span class="Modifier">public</span>&#160;<span class="ValueType">bool</span> Equals(Foo other)&#160; <br />&#160;&#160;&#160; {&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="InlineComment">// Note: use ReferenceEquals if you overload the == operator </span> <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="Statement">if</span> (other == <span class="Keyword">null</span>)&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="Statement">return</span>&#160;<span class="Keyword">false</span>;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="InlineComment">// Now compare the fields of this and other for equality appropriately. </span> <br />&#160;&#160;&#160; }&#160; <br /> <br />&#160;&#160;&#160; <span class="InlineComment">// GetHashCode etc</span> <br />} </div> <p>(I&#39;ve deliberately sealed Foo to avoid having to worry about equality between subclasses.)</p> <p>Here we know that we really <em>do</em> want to deal with both null and &quot;non-null, non-Foo&quot; references in the same way from Equals(object) - we want to return false. The simplest way of handling that is to delegate to the Equals(Foo) method which needs to handle nullity but doesn&#39;t need to worry about non-Foo reference.</p> <p>We&#39;re <em>knowingly</em> anticipating the possibility of Equals(object) being called with a non-Foo reference. The documentation for the method explicitly states what we&#39;re meant to do; this does <em>not</em> necessarily indicate a programming error. We could implement Equals with a cast, of course:</p> <div class="code"><span class="Modifier">public</span>&#160;<span class="Modifier">override</span>&#160;<span class="ValueType">bool</span> Equals(<span class="ReferenceType">object</span> obj)&#160; <br />{&#160; <br />&#160;&#160;&#160; <span class="Statement">return</span> obj <span class="Keyword">is</span> Foo &amp;&amp; Equals((Foo) obj);&#160; <br />} </div> <p>... but I dislike that for the same reasons as I disliked the cast in use case 2.</p> <h3>Use case 4: deferring or delegating the decision</h3> <p>This is the case where we pass the converted value on to another method or constructor, which is likely to store the value for later use. For example:</p> <div class="code"><span class="Modifier">public</span>&#160;<span class="ValueType">void</span> CreatePersonWithCast(<span class="ReferenceType">object</span> firstName, <span class="ReferenceType">object</span> lastName)&#160; <br />{&#160; <br />&#160;&#160;&#160; <span class="Statement">return</span>&#160;<span class="Keyword">new</span> Person((<span class="ReferenceType">string</span>) firstName, (<span class="ReferenceType">string</span>) lastName);&#160; <br />} <br /> <br /><span class="Modifier">public</span>&#160;<span class="ValueType">void</span> CreatePersonWithAs(<span class="ReferenceType">object</span> firstName, <span class="ReferenceType">object</span> lastName)&#160; <br />{&#160; <br />&#160;&#160;&#160; <span class="Statement">return</span>&#160;<span class="Keyword">new</span> Person(firstName <span class="Keyword">as</span>&#160;<span class="ReferenceType">string</span>, lastName <span class="Keyword">as</span>&#160;<span class="ReferenceType">string</span>);&#160; <br />} </div> <p>In some ways use case 3 was a special case of this, where we knew what the Equals(Foo) method would do with a null reference. In general, however, there can be a significant delay between the conversion and some definite impact. It <em>may</em> be valid to use null for one or both arguments to the Person constructor - but is that really what you want to achieve? Is some later piece of code going to assume they&#39;re non-null?</p> <p>If the constructor is going to validate its parameters and check they&#39;re non-null, we&#39;re essentially back to use case 1, just with ArgumentNullException replacing NullReferenceException: again, it&#39;s cleaner to use the cast and end up with InvalidCastException before we have the chance for anything else to go wrong.</p> <p>In the worst scenario, it&#39;s really not expected that the caller will pass null arguments to the Person constructor, but due to sloppy validation the Person is constructed with no errors. The code may then proceed to do any number of things (some of them irreversible) before the problem is spotted. In this case, there may be lasting data loss or corruption and if an exception <em>is</em> eventually thrown, it may be very hard to trace the problem to the original CreatePersonWithAs parameter value not being a string reference.</p> <h3>Conclusion</h3> <p>I have nothing against the &quot;as&quot; operator, when used carefully. What I dislike is the assumption that it&#39;s &quot;safer&quot; than a cast, simply because in error cases it doesn&#39;t throw an exception. That&#39;s more <em>dangerous</em> behaviour, as it allows problems to propagate. In short: whenever you have a reference conversion, consider the possibility that it might fail. What sort of situation might cause that to occur, and how to you want to proceed?</p> <ul> <li>If everything about the system design reassures you that it really can&#39;t fail, then use a cast: if it turns out that your understanding of the system is wrong, then throwing an exception is usually preferable to proceeding in a context you didn&#39;t anticipate. Bear in mind that a null reference can be successfully cast to any nullable type, so a cast can never <em>replace</em> a null check. </li> <li>If it&#39;s expected that you really <em>might</em> receive a reference of the &quot;wrong&quot; type, then think how you want to handle it. Use the &quot;as&quot; operator and then test whether the result was null. Bear in mind that a null result doesn&#39;t always mean the original value was a reference of a different type - it could have been a null reference to start with. Consider whether or not you need to differentiate those two situations. </li> <li>If you <em>really</em> can&#39;t be bothered to really think things through (and I hope none of my readers are this lazy), default to using a cast: at least you&#39;ll notice if something&#39;s wrong, and have a useful stack trace. </li> </ul> <p>As a side note, writing this post has made me consider (yet again) the various types of &quot;exception&quot; situations we run into. At some point I may put enough thought into how we could express our intentions with regards to these situations more clearly - until then I&#39;d recommend reading <a href="http://blogs.msdn.com/b/ericlippert/archive/2008/09/10/vexing-exceptions.aspx">Eric Lippert&#39;s taxonomy of exceptions</a>, which has certainly influenced my thinking.</p><div style="clear:both;"></div><img src="http://msmvps.com/aggbug.aspx?PostID=1844013" width="1" height="1"><img src="http://feeds.feedburner.com/~r/JonSkeetCodingBlog/~4/vjrMXb_LK48" height="1" width="1"/>Thu, 19 Sep 2013 17:38:41 -0700http://theburningmonk.com/?p=3035http://theburningmonk.com/2013/09/stream_ext-version-0-2-0-is-out/rxprogrammingdartstream_extstream_ext – version 0.2.0 is outLately I’ve been making steady progress in porting over Rx APIs over to Dart with stream_ext, and with the release of version 0.2.0 a few more Rx methods have been added to the existing set of buffer, combineLatest, delay, max, merge, min, scan, sum, throttle, window and zip.   average StreamExt.average has the following signature: [...]Wed, 18 Sep 2013 19:56:28 -0700http://tomasp.net/blog/2013/tuples-in-csharphttp://tomasp.net/blog/2013/tuples-in-csharp/index.htmlf#How many tuple types are there in C#?<p>In a <a href="http://stackoverflow.com/questions/18718232/when-should-i-write-my-functions-in-curried-form/18721711">recent StackOverflow question</a> the poster asked about the difference between <em>tupled</em> and <em>curried</em> form of a function in F#. In F#, you can use pattern matching to easily define a function that takes a tuple as an argument. For example, the poster's function was a simple calculation that multiplies the number of units sold <em>n</em> by the price <em>p</em>:</p> <pre class="fssnip"> <span class="l">1: </span><span class="k">let</span> <span onmouseout="hideTip(event, 'abs159_1', 1)" onmouseover="showTip(event, 'abs159_1', 1)" class="i">salesTuple</span> (<span onmouseout="hideTip(event, 'abs159_2', 2)" onmouseover="showTip(event, 'abs159_2', 2)" class="i">price</span>, <span onmouseout="hideTip(event, 'abs159_3', 3)" onmouseover="showTip(event, 'abs159_3', 3)" class="i">count</span>) <span class="o">=</span> <span onmouseout="hideTip(event, 'abs159_2', 4)" onmouseover="showTip(event, 'abs159_2', 4)" class="i">price</span> <span class="o">*</span> (<span onmouseout="hideTip(event, 'abs159_4', 5)" onmouseover="showTip(event, 'abs159_4', 5)" class="i">float</span> <span onmouseout="hideTip(event, 'abs159_3', 6)" onmouseover="showTip(event, 'abs159_3', 6)" class="i">count</span>)</pre> <p>The function takes a single argument of type <code>Tuple&lt;float, int&gt;</code> (or, using the nicer F# notation <code>float * int</code>) and immediately decomposes it into two variables, <code>price</code> and <code>count</code>. The other alternative is to write a function in the <em>curried</em> form:</p> <pre class="fssnip"> <span class="l">1: </span><span class="k">let</span> <span onmouseout="hideTip(event, 'abs159_5', 7)" onmouseover="showTip(event, 'abs159_5', 7)" class="i">salesCurried</span> <span onmouseout="hideTip(event, 'abs159_2', 8)" onmouseover="showTip(event, 'abs159_2', 8)" class="i">price</span> <span onmouseout="hideTip(event, 'abs159_3', 9)" onmouseover="showTip(event, 'abs159_3', 9)" class="i">count</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'abs159_2', 10)" onmouseover="showTip(event, 'abs159_2', 10)" class="i">price</span> <span class="o">*</span> (<span onmouseout="hideTip(event, 'abs159_4', 11)" onmouseover="showTip(event, 'abs159_4', 11)" class="i">float</span> <span onmouseout="hideTip(event, 'abs159_3', 12)" onmouseover="showTip(event, 'abs159_3', 12)" class="i">count</span>)</pre> <p>Here, we get a function of type <code>float -&gt; int -&gt; float</code>. Usually, you can read this just as a function that takes <code>float</code> and <code>int</code> and returns <code>float</code>. However, you can also use <em>partial function application</em> and call the function with just a single argument - if the price of an apple is $1.20, we can write <code>salesCurried 1.20</code> to get a <em>new</em> function that takes just <code>int</code> and gives us the price of specified number of apples. The poster's question was:</p> <blockquote> <p>So when I want to implement a function that would have taken <em>n > 1</em> arguments, should I for example always use a curried function in F# (...)? Or should I take the simple route and use regular function with an n-tuple and curry later on if necessary?</p> </blockquote> <p>You can see <a href="http://stackoverflow.com/questions/18718232/when-should-i-write-my-functions-in-curried-form/18721711#18721711">my answer on StackOverflow</a>. The point of this short introduction was that the question inspired me to think about how the world looks from the C# perspective...</p> <div class="tip" id="abs159_1">val salesTuple : price:float * count:int -&gt; float<br /><br />Full name: Tuples-in-csharp_.salesTuple</div> <div class="tip" id="abs159_2">val price : float</div> <div class="tip" id="abs159_3">val count : int</div> <div class="tip" id="abs159_4">Multiple items<br />val float : value:&#39;T -&gt; float (requires member op_Explicit)<br /><br />Full name: Microsoft.FSharp.Core.Operators.float<br /><br />--------------------<br />type float = System.Double<br /><br />Full name: Microsoft.FSharp.Core.float<br /><br />--------------------<br />type float&lt;&#39;Measure&gt; = float<br /><br />Full name: Microsoft.FSharp.Core.float&lt;_&gt;</div> <div class="tip" id="abs159_5">val salesCurried : price:float -&gt; count:int -&gt; float<br /><br />Full name: Tuples-in-csharp_.salesCurried</div> Tue, 17 Sep 2013 13:11:57 -070091d46819-8472-40ad-a661-2c78acb4018c:10449462http://blogs.msdn.com/b/fsharpteam/archive/2013/09/16/a-new-f-meetup-the-paris-f-group.aspxocamlparisfsharp programmingf# meetupfranceA New F# Meetup - The Paris F# Group<p>&nbsp;A second F# meetup group has launched over the summer - <a href="http://www.meetup.com/Functional-Programming-in-F/">the Paris-based Functional Programming in F# group</a>.</p> <div id="urf-chapter-description" class="D_box"> <div class="D_boxbody"> <div id="groupDesc" class="groupDesc"> <p style="padding-left: 30px;"><em>Learn how to take advantage of F# and .NET platform to develop a real world&nbsp;functional programs If you are beginner or an expert in FP it doesn't matter.&nbsp;You are welcome !</em></p> <p>If you would like to contribute to the group, please&nbsp;join up - the group is still working out its schedule, so get involved now to help set the direction.</p> <p>&nbsp;</p> <p><a href="http://www.meetup.com/Functional-Programming-in-F/"><img style="margin-right: auto; margin-left: auto; display: block;" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-71/5826.Capture.JPG" alt="" border="0" /></a></p> </div> </div> </div><div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10449462" width="1" height="1">Mon, 16 Sep 2013 12:22:00 -070091d46819-8472-40ad-a661-2c78acb4018c:10449457http://blogs.msdn.com/b/fsharpteam/archive/2013/09/16/a-new-f-meetup-group-washington-dc-f-meetup.aspxmachine learningf# user groupsf# meetupswashington dcdcfsharpA new F# Meetup Group - Washington DC F# Meetup <p>&nbsp;</p> <p>Those of us in the Visual F# team are pleased to announce that&nbsp;the&nbsp;<a href="http://www.meetup.com/DC-fsharp/">Washington DC F# Meetup group</a> has now been launched!<img class="photo" style="float: right;" src="http://photos1.meetupstatic.com/photos/event/3/4/5/0/global_275053392.jpeg" alt="" /></p> <p>&nbsp;</p> <div id="urf-chapter-description" class="D_box"> <div class="D_boxbody"> <div id="groupDesc" class="groupDesc"> <p style="padding-left: 30px;"><em>Welcome! This is an F# meetup group that meets in and around the DC area. The goal is to bring likeminded local F# enthusiasts together to learn, play, and explore the F# language and ecosystem. Programmers of all skill levels and backgrounds are welcome.</em></p> <p style="padding-left: 30px;"><em>Tweet at us at&nbsp;<a href="https://twitter.com/DCFSharp">@DCFsharp</a>!</em></p> <p>The group already has 58 members, and of course is very welcoming to all. The group meets tonight for the topic <em><strong><a href="http://www.meetup.com/DC-fsharp/events/135766752/?trax_also_in_algorithm=original&amp;action=detail&amp;traxDebug_also_in_algorithm_picked=original&amp;eventId=135766752">Machine Learning From Disaster</a>, </strong></em>join the group on metup.com to follow for regular updates, and consider contributing a session of your own on your favourite F# topics.</p> <p></p> <p style="padding-left: 30px;"><em></em></p> </div> </div> </div><div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10449457" width="1" height="1">Mon, 16 Sep 2013 12:12:24 -0700http://sergeytihon.wordpress.com/?p=2227http://sergeytihon.wordpress.com/2013/09/16/f-weekly-37-2013/f#f# weeklynews:f# weeklyF# Weekly #37 2013Welcome to F# Weekly, A roundup of F# content from this past week: News FSharp.Data 1.1.10 was released with a bunch of bugfixes. RProvider 1.0.1 was released with latest R.NET and RDotNet.FSharp inside. Francesco De Vittori works on type inference for Smalltalk. Immo Landwerth announced that &#8220;Immutable collections are now RC&#8220;. Blogs Visual Studio FSharp Team posted [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sergeytihon.wordpress.com&#038;blog=15048173&#038;post=2227&#038;subd=sergeytihon&#038;ref=&#038;feed=1" width="1" height="1" />Sun, 15 Sep 2013 21:12:04 -0700http://theburningmonk.com/?p=3026http://theburningmonk.com/2013/09/run-taotie-run-new-here-be-monsteres-mini-game-made-with-dart-and-stagexl/programminggamesmehere be monstersdartstagexlstream_extRun Taotie Run – new Here Be Monsteres mini-game made with Dart and StageXLUsing StageXL and Dart, I built another mini-game themed around our MMORPG Here Be Monsters this week. The game follows a pack of Taotie monsters, which is a type of spirit monster created when a ghost with immense hunger possesses a Chinese pot. Taotie originates from Chinese folklores and is one of many monsters that [...]Sun, 15 Sep 2013 02:39:13 -070091d46819-8472-40ad-a661-2c78acb4018c:10448707http://blogs.msdn.com/b/fsharpteam/archive/2013/09/13/visual-studio-2013-rc-and-send-to-fsi.aspxannouncementf# 3.1visual studio 2013Visual Studio 2013 RC and Send to FSI<p>Earlier this week, the Release Candidate build of Visual Studio 2013 was <a href="http://blogs.msdn.com/b/somasegar/archive/2013/09/09/announcing-the-visual-studio-2013-release-candidate.aspx" target="_blank">announced</a>.&#160; Like the Preview build before it, the RC contains a host of new features for F# developers, including F# 3.1 language updates and improved Visual F# tooling.&#160; You can read the details in our <a href="http://blogs.msdn.com/b/fsharpteam/archive/2013/06/27/announcing-a-pre-release-of-f-3-1-and-the-visual-f-tools-in-visual-studio-2013.aspx" target="_blank">earlier blog post</a>.</p> <p>The RC contains one brand-new F# feature, though, which we are pleased to announce today: <strong>Send to F# Interactive.</strong></p> <p>The same solution explorer context menus used to manage assembly references in F# projects now give you the option to send those references to your FSI session.&#160; This is often much simpler and faster than typing out a full #r command.&#160; There are three ways to use the feature:</p> <ul> <li>Add individual references by selecting and right-clicking on them</li> </ul> <p><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-71-metablogapi/2677.fsi_5F00_individual_5F00_628A1121.png"><img title="fsi_individual" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block;" border="0" alt="fsi_individual" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-71-metablogapi/2260.fsi_5F00_individual_5F00_thumb_5F00_4CC028C4.png" width="482" height="388" /></a></p> <ul> <li>Add all project references at once by right-clicking the top-level References node</li> </ul> <p><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-71-metablogapi/6283.fsi_5F00_allrefs_5F00_217B91BD.png"><img title="fsi_allrefs" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block;" border="0" alt="fsi_allrefs" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-71-metablogapi/3175.fsi_5F00_allrefs_5F00_thumb_5F00_7A414887.png" width="453" height="339" /></a></p> <ul> <li>Add the output assembly of a project by right-clicking the project node</li> </ul> <p><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-71-metablogapi/0458.fsi_5F00_project_5F00_4BE7C2DA.png"><img title="fsi_project" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block;" border="0" alt="fsi_project" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-71-metablogapi/8054.fsi_5F00_project_5F00_thumb_5F00_47714213.png" width="490" height="405" /></a></p> <p>&#160;</p> <p>&#160;</p> <p>In all cases, the result is equivalent to a traditional #r FSI reference:</p> <p><a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-71-metablogapi/6232.fsi_5F00_fsi_5F00_32138CAB.png"><img title="fsi_fsi" style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block;" border="0" alt="fsi_fsi" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-39-71-metablogapi/1462.fsi_5F00_fsi_5F00_thumb_5F00_4AA329FB.png" width="640" height="266" /></a></p> <p>&#160;</p> <p>Note that once an assembly is loaded into FSI, it is locked on disk and a new version of the same assembly cannot be loaded into the session.&#160; Make sure to reset FSI (by right clicking the window and selecting “Reset Interactive Session”) when you want to load an updated version of an assembly, or unlock an assembly file on disk.</p><div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10448707" width="1" height="1">Fri, 13 Sep 2013 20:11:00 -0700http://trelford.com/blog/post.aspx?id=76eacfbc-1a16-4dd6-a2b0-efeb47b0a00dhttp://trelford.com/blog/post/specialk.aspxf#.netk-means clustering<p>The <a href="http://en.wikipedia.org/wiki/Machine_learning">machine learning</a> theme continues to be popular at the <a href="http://www.meetup.com/fsharplondon/">F#unctional Londoners</a> meetup group. Last night <a href="http://skillsmatter.com/expert-profile/scala/matt-moloney">Matt Moloney</a> gave a great hands on session on <a href="http://en.wikipedia.org/wiki/K-means_clustering">k-means clustering</a>. Matt has worked on large machine learning systems at e-Bay. More recently he has been working on the <a href="http://tsunami.io/">Tsunami IDE</a>, an extensible <a href="http://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop">REPL</a> environment for the desktop and cloud. </p> <p>Tsunami provides a lightweight environment focused on interactive development, very suited to machine learning. And with F# 3 Type Providers you get typed access to a diverse set of data from CSV files all the way up to <a href="http://www.youtube.com/watch?v=USw0o9Fccac">Hadoop</a>. Interestingly Tsunami can be embedded in to Excel and used as a replacement for VBA. </p> <p><a href="http://skillsmatter.com/expert/home/greg-young">Grey Young</a> describes Tsunami as a REPL on steroids.</p> <iframe style="margin-bottom: 5px; border-top: #ccc 1px solid; border-right: #ccc 1px solid; border-bottom: #ccc 0px solid; border-left: #ccc 1px solid" height="421" marginheight="0" src="http://www.slideshare.net/slideshow/embed_code/26123021" frameborder="0" width="512" marginwidth="0" scrolling="no" mozallowfullscreen="mozallowfullscreen" webkitallowfullscreen="webkitallowfullscreen" allowfullscreen="allowfullscreen"> </iframe> <div style="margin-bottom: 5px"><strong><a title="Machine Learning - Matt Moloney" href="https://www.slideshare.net/ptrelford/ml-presentation" target="_blank">Machine Learning - Matt Moloney</a> </strong>from <strong><a href="http://www.slideshare.net/ptrelford" target="_blank">ptrelford</a></strong> </div> <br /> <p><a href="http://en.wikipedia.org/wiki/K-means_clustering">k-means clustering</a> has a number of interesting application areas, from search to pharmaceuticals. For the session Matt provided an F# script to analyse the canonical iris data set (flowers). The script also produces a variety of charts for visualizing the data including animated gifs showing the centroid positions at each iteration:</p> <p><a href="http://trelford.com/blog/image.axd?picture=results_0_1.gif"><img title="results_0_1" style="display: inline" alt="results_0_1" src="http://trelford.com/blog/image.axd?picture=results_0_1_thumb.gif" width="512" height="346" /></a> </p> <p>The <a href="http://fsharp.github.io/FSharp.Data/">FSharp.Data</a> CSV Type Provider, available on Nuget, gives typed access over CSV files and was used to extract the values from the iris data file:</p> <pre class="code"><span style="background: white; color: blue">type </span><span style="background: white; color: black">Iris = CsvProvider&lt;irisDataFile&gt; </span><span style="background: white; color: blue">let </span><span style="background: white; color: black">iris = Iris.Load(irisDataFile) </span><span style="background: white; color: blue">let </span><span style="background: white; color: black">irisData = iris.Data |&gt; Seq.toArray </span><span style="background: white; color: green">/// classifcations </span><span style="background: white; color: blue">let </span><span style="background: white; color: black">y = irisData |&gt; Array.map (</span><span style="background: white; color: blue">fun </span><span style="background: white; color: black">row </span><span style="background: white; color: blue">-&gt; </span><span style="background: white; color: black">row.Class) </span><span style="background: white; color: green">/// feature vectors </span><span style="background: white; color: blue">let </span><span style="background: white; color: black">X = irisData |&gt; Array.map (</span><span style="background: white; color: blue">fun </span><span style="background: white; color: black">row </span><span style="background: white; color: blue">-&gt; </span><span style="background: white; color: black">[|row.``Sepal Length`` row.``Sepal Width`` row.``Petal Length`` row.``Petal Width`|])</span></pre> <a href="http://11011.net/software/vspaste"></a> <br /> <p>Computing k-means centroids:</p> <pre class="code"><span style="background: white; color: blue">let </span><span style="background: white; color: black">K = 3 </span><span style="background: white; color: green">// The Iris dataset is known to only have 3 clusters </span><span style="background: white; color: blue">let </span><span style="background: white; color: black">seed = [|X.[0]; X.[1]; X.[2]|] </span><span style="background: white; color: green">// pick bad centroids on purpose </span><span style="background: white; color: blue">let </span><span style="background: white; color: black">centroidResults = KMeans.computeCentroids seed X |&gt; Seq.take iterationLimit</span></pre> <a href="http://11011.net/software/vspaste"></a> <br /> <p>I was particularly impressed by the conciseness of Matt’s implementation of the algorithm:</p> <pre class="code"><span style="background: white; color: green">(* K-Means Algorithm *) /// Group all the vectors by the nearest center. </span><span style="background: white; color: blue">let </span><span style="background: white; color: black">classify centroids vectors = vectors |&gt; Array.groupBy (</span><span style="background: white; color: blue">fun </span><span style="background: white; color: black">v </span><span style="background: white; color: blue">-&gt; </span><span style="background: white; color: black">centroids |&gt; Array.minBy (distance v)) </span><span style="background: white; color: green">/// Repeatedly classify the vectors, starting with the seed centroids </span><span style="background: white; color: blue">let </span><span style="background: white; color: black">computeCentroids seed vectors = seed |&gt; Seq.iterate (</span><span style="background: white; color: blue">fun </span><span style="background: white; color: black">centers </span><span style="background: white; color: blue">-&gt; </span><span style="background: white; color: black">classify centers vectors </span></pre> <pre class="code"><span style="background: white; color: black"> |&gt; Array.map (snd &gt;&gt; average))</span></pre> <a href="http://11011.net/software/vspaste"></a> <br /> <p>Thanks again to Matt for giving a really interesting session.</p> <p><a href="http://trelford.com/blog/image.axd?picture=Learning%20Machine%20Learning.jpg"><img title="Learning Machine Learning" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="Learning Machine Learning" src="http://trelford.com/blog/image.axd?picture=Learning%20Machine%20Learning_thumb.jpg" width="516" height="388" /></a></p> <br /> <p>If you’re interested in learning Matt’s also giving an in depth session on machine learning at the <a href="http://skillsmatter.com/event/scala/progressive-f-tutorials-2013">Progressive F# Tutorials</a> in London at the end of October:</p> <p><a href="http://skillsmatter.com/event/scala/progressive-f-tutorials-2013"><img title="ProgFsharp London 2013" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="ProgFsharp London 2013" src="http://trelford.com/blog/image.axd?picture=ProgFsharp%20London%202013.png" width="516" height="196" /></a>&#160;</p> And if you’re in New York next week you can catch <a href="http://skillsmatter.com/expert-profile/scala/rachel-rees">Rachel Reese</a> give an introduction to data science followed by a machine learning introduction with <a href="http://www.clear-lines.com/blog/">Mathias Brandewinder</a> and I at the <a href="http://skillsmatter.com/event/scala/progressive-f-tutorials-nyc">Progressive F# Tutorials NYC</a>. Thu, 12 Sep 2013 07:23:27 -0700http://gettingsharper.de/?p=550http://gettingsharper.de/2013/09/10/installing-glpk-and-glpk-hs-on-windows/haskellinstallationglpklinear programminglpInstalling GLPK and GLPK-hs on WindowsAs I want to try some LP (looking into a coursera-course) I tried to setup GLPK on Windows. (BTW: doing this in Linux is trivial: apt-get or you friendly packet-manager). The goal was to get this simple skript: running. Well &#8230; <a href="http://gettingsharper.de/2013/09/10/installing-glpk-and-glpk-hs-on-windows/">Weiterlesen <span class="meta-nav">&#8594;</span></a>Tue, 10 Sep 2013 12:43:11 -0700http://sergeytihon.wordpress.com/?p=2220http://sergeytihon.wordpress.com/2013/09/09/stanford-word-segmenter-is-available-on-nuget/f#c#nugetikvm.netnlpstanford nlpStanford Word Segmenter is available on NuGetTokenization of raw text is a standard pre-processing step for many NLP tasks. For English, tokenization usually involves punctuation splitting and separation of some affixes like possessives. Other languages require more extensive token pre-processing, which is usually called segmentation. The Stanford Word Segmenter currently supports Arabic and Chinese. The provided segmentation schemes have been found to [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sergeytihon.wordpress.com&#038;blog=15048173&#038;post=2220&#038;subd=sergeytihon&#038;ref=&#038;feed=1" width="1" height="1" />Mon, 09 Sep 2013 19:43:47 -0700http://theburningmonk.com/?p=3023http://theburningmonk.com/2013/09/stream_ext-bringing-more-rx-api-to-the-dart/rxprogrammingdartstream_extstream_ext – bringing more Rx API to the DartOver the last week or so, I’ve been looking at and playing around with the Streams API in Dart, which has been (in part at least) based on the Rx API, and it’s easy to see the parallels between the two sets of APIs and you can find most of the core Rx APIs on [...]Sun, 08 Sep 2013 21:57:01 -0700http://sergeytihon.wordpress.com/?p=2214http://sergeytihon.wordpress.com/2013/09/09/f-weekly-36-2013/f#f# weeklynews:f# weeklyF# Weekly #36 2013Welcome to F# Weekly, A roundup of F# content from this past week: News New feature was proposed to F# - Implement interface by expression (example is here) New F# Cheatsheet in PDF and HTML format using FSharp.Formatting tool was published. James announced a new F# game Twaddle(FunScript) that is available on Android. F# User Group Sydney [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sergeytihon.wordpress.com&#038;blog=15048173&#038;post=2214&#038;subd=sergeytihon&#038;ref=&#038;feed=1" width="1" height="1" />Sun, 08 Sep 2013 21:04:46 -0700http://trelford.com/blog/post.aspx?id=8a8f832f-8379-4f0d-9fa9-991ca78c886fhttp://trelford.com/blog/post/scorchio.aspxf#silverlightscalawpfjavascriptc#.netarchitecturewinrtWalkie Scorchie<p>From the window at the office I’ve seen a series of futuristic buildings erected, first the Gherkin, then the Shard and now the Walkie Talkie:</p> <p><a href="http://www.theguardian.com/artanddesign/shortcuts/2013/sep/03/walkie-talkie-death-ray-buildings-heat"><img title="London skyline" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="London skyline" src="http://trelford.com/blog/image.axd?picture=City-of-London---the-Chee-010.jpg" width="404" height="244" /></a>&#160;</p> <p>The last one being recently been re-dubbed the <a href="http://www.telegraph.co.uk/culture/art/architecture/10283702/Whats-frying-at-Walkie-Scorchie.html">Walkie Scorchie</a> as it produces a supercharged solar <a href="http://www.theguardian.com/artanddesign/2013/sep/04/walkie-talkie-screen-death-ray">‘death ray’</a> that has burned holes in carpets, melted furniture and even the interior of a <a href="http://www.bbc.co.uk/news/uk-england-london-23930675">Jaguar</a> parked nearby.</p> <p>It feels almost reminiscent of the dystopian future portrayed in the cult film <a href="http://en.wikipedia.org/wiki/Idiocracy">Idiocracy:</a></p> <p><a title="Idiocracy" href="http://www.youtube.com/watch?v=icmRCixQrx8"><img title="Idiocracy skyline" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="Idiocracy skyline" src="http://trelford.com/blog/image.axd?picture=1166399006.jpg" width="404" height="229" /></a> </p> <p>Though our current society is probably closer to the surveillance society of <a href="http://en.wikipedia.org/wiki/Nineteen_Eighty-Four">1984</a> with the omnipresent Big Brother watching over you:</p> <p><a href="https://www.gov.uk/sortmytax"><img title="Big brother is watching you" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="Big brother is watching you" src="http://trelford.com/blog/image.axd?picture=taxe_2395740b_1.jpg" width="404" height="254" /></a> </p> <p>The everyday software we work with is no less broken, or so Scott Hanselman concludes in <a href="http://www.hanselman.com/blog/EverythingsBrokenAndNobodysUpset.aspx">everything's broken and nobody's upset</a>.</p> <p>Software is increasingly a world of <a href="http://en.wikipedia.org/wiki/Broken_windows_theory">broken windows</a> where developers are more accustomed to <a href="http://stackoverflow.com/">working around issues</a> than giving <a href="http://trelford.com/blog/post/Blackhole.aspx">feedback</a>, let alone tackling the <a href="http://www.infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare">root causes</a>.</p> <p><a href="http://connect.microsoft.com/VisualStudio/feedback/details/750025/waiting-for-vs-to-complete-background-task"><img title="waiting for background operation to complete modal dialog" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="waiting for background operation to complete modal dialog" src="http://trelford.com/blog/image.axd?picture=background%20operation.png" width="404" height="132" /></a>&#160;</p> <p>Anyone else struggling with the cognitive dissonance of a modal dialog waiting for a background operation to complete?</p> <h2>XAML</h2> <p>I’ve been using <a href="http://en.wikipedia.org/wiki/Extensible_Application_Markup_Language">XAML</a> in it’s various guises off an on for over 5 years now. Over that time I’ve used WPF, Silverlight and Metro. It feels like little has <a href="http://paulstovell.com/blog/six-years-of-wpf">changed</a> in that time. It’s still probably the best thing out there for desktop app development but surely we could do better.</p> <h3>XML</h3> <p>I’m still stuck editing views in XML, the poor man’s DSL. I, like the developers I know rarely use the designer view. When we do it frequently hangs and we’re left manually killing <a href="http://blog.spinthemoose.com/2013/03/24/disable-the-xaml-designer-in-visual-studio/">XDescProc.exe</a> from task manager.</p> <h3>Data Binding</h3> <p>Data binding is central to XAML. With it you can easily bind a collection to a data grid and get sorting and filtering for free. But binding comes with a high <a href="http://msdn.microsoft.com/en-us/library/bb613546.aspx#HowDataBindingReferencesAreResolved">performance cost</a> and it’s stringly typed nature means you’re left finding binding errors in the output window at runtime. </p> <p>Dynamically binding a view to a model would make more sense to me if I could edit the view at runtime, but you can’t, it’s compiled in.</p> <h3>Value Converters</h3> <p>If I want to transform a model value bound to the view to a different form I have to create a class that implements the <a href="http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter.aspx">IValueConverter</a> interface then reference it as a static resource in the resources section. It has all the elegance of C++ header files. Achieving the same thing in <a href="http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx">ASP.Net</a> is much simpler, you can just write inline some code in the view or call a function.</p> <h3>INotifyPropertyChanged</h3> <p>There’s a plethora of libraries and frameworks dedicated to working around this design decision, from the <a href="https://mvvmzero.codeplex.com/">MVVM frameworks</a> with LINQ expressions to <a href="http://www.postsharp.net/model/inotifypropertychanged">PostSharp</a> and attributes. The C# 5 compiler’s <a href="http://trelford.com/blog/post/CallMeMaybe.aspx">CallerMemberName</a> attribute has finally brought some sanity to the situation. But I know many developers, including myself, have wasted countless hours dealing with it and trying to think of ways of subverting it. </p> <p>Just about every view model class ends up inheriting from some <a href="https://mvvmlight.codeplex.com/SourceControl/latest#GalaSoft.MvvmLight/GalaSoft.MvvmLight (NET35)/ViewModelBase.cs">ViewModelBase</a> or <a href="https://mvvmzero.codeplex.com/SourceControl/latest#ObservableObject.cs">ObservableObject</a> class so that it can implement <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx">INotifyPropertyChanged</a>. </p> <h3>Inheritance</h3> <p>It is often said that <a href="http://en.wikipedia.org/wiki/Object-oriented_programming#History">object-oriented programming</a> is well suited to graphical user interfaces. Perhaps, but I start to have doubts when I see WPF’s <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.button.aspx">Button</a> class with 9 layers of inheritance and over 160 members.</p> <p>Visual Studio 2010 introduced <a href="http://blogs.msdn.com/b/somasegar/archive/2010/06/01/vs-2010-productivity-improvements-part-ii.aspx">improved intellisense</a> with substring search on members to partially work around this, but honestly I’d prefer to see buttons be closer to having content and a clicked event than their current diaspora of responsibilities.</p> <h3>Null Reference Exceptions</h3> <p>By far the most common error I see in C# applications is <a href="http://trelford.com/blog/post/StackTrace.aspx">Null Reference Exceptions</a>. Hardly a day goes by where yet another null check is added to the codebase. This needs to be fixed at the language level, <a href="http://vimeo.com/68226717">functional-first languages</a> like Scala and <a href="http://fsharpforfunandprofit.com/posts/ten-reasons-not-to-use-a-functional-programming-language/">F#</a> show it’s possible.</p> <h3>HTML5 &amp; JavaScript</h3> <p>HTML 5 and <a href="http://blogs.msdn.com/b/dsyme/archive/2012/04/12/is-javascript-code-always-so-full-of-bugs.aspx">JavaScript</a> are now being pushed as an alternate environment for desktop development. JavaScript has come a long way performance and <a href="https://github.com/mattdiamond/fuckitjs">libraries</a> wise and I like the HTML 5 <a href="http://trelford.com/PK.html">Canvas</a> model. However I’m not yet convinced how well this scales to multi-window applications that need to interact between processes.</p> <h3>Windows 8</h3> <p>I get that Metro style interfaces are good for tablets and touch, but for multi-window desktop applications it feels like a non-starter.</p> <p>&#160;<a href="http://trelford.com/blog/image.axd?picture=trading%20desk.jpg"><img title="" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="" src="http://trelford.com/blog/image.axd?picture=trading%20desk_thumb.jpg" width="404" height="270" /></a></p> <p>I’ve seen traders use 9 displays simultaneously, running a multitude of different apps from execution platforms and news services to <a href="http://office.microsoft.com/en-gb/excel-help/rtd-function-HP010342864.aspx">Excel</a>, Outlook and instant messengers.</p> <p>To me Windows 8 appears to be consumer orientated release. I’m hoping the next version will bring something for the larger customer base of business users.</p> <h3>Vendors</h3> <p>One person’s problem is another’s opportunity. Third party vendors like JetBrains are grasping the opportunity with both hands by patching flaws in Visual Studio and C# with <a href="http://trelford.com/blog/post/tools.aspx">tools</a> like Resharper. They’re now starting to provide elastoplasts over <a href="http://www.jetbrains.com/resharper/features/xaml_editor.html">XAML editing</a> too. Jetbrains are not the only ones, <a href="http://www.telerik.com/products/wpf/overview.aspx">Telerik</a> and others are making hay selling themes and <a href="http://stackoverflow.com/questions/697701/wpf-datagrid-performance">datagrids</a>.</p> <p><a href="https://www.youtube.com/watch?v=-Vw2CrY9Igs"><img title="627" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="627" src="http://trelford.com/blog/image.axd?picture=627.jpg" width="404" height="229" /></a>&#160;</p> <p>To temporarily workaround performance issues caused by the cost of the mouse handler events in one these products we were forced to throttle the number of system mouse events bubbling through the system.</p> <p>Duct tape is a good short term solution, but surely at some point we should consider building a stronger foundation.</p> <h2>Simplicity</h2> <p><i>I would not give a fig for the simplicity this side of complexity, but I would give my life for the simplicity on the other side of complexity.</i> - Oliver Wendell Holmes, Jr.</p> <p>XAML is huge and bloated, <a href="http://www.amazon.co.uk/WPF-4-5-Unleashed-Adam-Nathan/dp/0672336979/">WPF 4.5 Unleashed</a> is 864 pages long, yet XAML’s focus on data binding makes it feel like a one-trick pony. </p> <p>I think a modern desktop UI environment needs to cover a diverse range of product scenarios. There should be a <a href="http://www.microsoft.com/games/en-gb/aboutGFW/pages/directx.aspx">low-level core</a> that can be easily accessed with code for high performance features all the way up to a <a href="http://msdn.microsoft.com/en-us/vstudio/ff796201.aspx">designer view</a> for tacking databases on to views, and it should all interoperate seamlessly.</p> <p>Sections of the development community are striving to bring <a href="http://www.extremeprogramming.org/rules/simple.html">simplicity</a> to our environments. Language designers like <a href="http://www.infoq.com/presentations/Simple-Made-Easy">Rich Hickey</a> (Clojure) and <a href="https://www.simple-talk.com/opinion/geek-of-the-week/dr-byron-cook-geek-of-the-week/">Don Syme</a> (F#) are bringing us simplicity at the language level. I’d love to see these thought processes applied to UI environments too.</p> <p>To tackle the root causes of problems some times you need to stop continuously patching over the cracks, step back and take time to look at the big picture. To create Clojure Rich Hickey practised <a href="http://www.youtube.com/watch?v=f84n5oFoZBc">Hammock driven development</a>. I’d love to see more of this kind of thoughtful design and less <a href="http://refuctoring.wordpress.com/2011/01/13/the-mortgage-driven-development-manifesto/">Mortgage driven development</a>.</p> <p>Tackling the <a href="http://www.youtube.com/watch?v=O2QJvc_SxFQ">root causes</a> of complexity and defects in our software is not an easy choice, it requires investment and changes to the way we do things. But not changing is a choice too.</p> <blockquote> <p>They live out their lives in this virtual reality as they would have around the turn of the 20th and 21st centuries. The time period was chosen because it is supposedly the pinnacle of human civilization. – Agent Smith</p> </blockquote> <p>Must Java like languages and XML be considered the pinnacle of software development for time immemorial?</p>Sat, 07 Sep 2013 23:58:30 -0700http://www.clear-lines.com/blog/post.aspx?id=03ad1c32-66ec-4e01-acac-2ecc8ccc932bhttp://www.clear-lines.com/blog/post/First-Steps-With-Accord-NET-SVM-in-FSharp.aspxf#machine learningFirst steps with Accord.NET SVM in F#<p>Recently, <a href="https://twitter.com/cesarsouza">Cesar De Souza</a> began moving his .NET machine learning library, Accord.NET, from <a href="https://code.google.com/p/accord/">Google Code</a> to <a href="http://accord-net.github.io/">GitHub</a>. The move is still in progress, but that motivated me to take a closer look at the library; given that it is built in C#, with an intended C# usage in mind, I wanted to see how usable it is from F#.</p> <p>There is a lot in the library; as a starting point, I decided I would try out its Support Vector Machine (SVM), a classic machine learning algorithm, and run it on a classic problem, automatically recognizing hand-written digits. The dataset I will be using here is a subset of the <a href="http://www.kaggle.com/c/digit-recognizer">Kaggle Digit Recognizer contest</a>; each example in the dataset is a 28x28 grayscale pixels image, the result of scanning a number written down by a human, and what the actual number is. From that original dataset, I sampled 5,000 examples, which will be used to train the algorithm, and another 500 in a validation set, which we’ll use to evaluate the performance of the model on data it hasn’t “seen before”.</p> <p>The full example is available as a <a href="https://gist.github.com/mathias-brandewinder/6443302">gist on GitHub</a>.</p> <p>I’ll be working in a script file within a Library project, as I typically do when exploring data. First, we need to add references to Accord.NET via NuGet:</p><pre class="brush: fsharp; gutter: false; toolbar: false;">#r @"..\packages\Accord.2.8.1.0\lib\Accord.dll" #r @"..\packages\Accord.Math.2.8.1.0\lib\Accord.Math.dll" #r @"..\packages\Accord.Statistics.2.8.1.0\lib\Accord.Statistics.dll" #r @"..\packages\Accord.MachineLearning.2.8.1.0\lib\Accord.MachineLearning.dll" open System open System.IO open Accord.MachineLearning open Accord.MachineLearning.VectorMachines open Accord.MachineLearning.VectorMachines.Learning open Accord.Statistics.Kernels </pre> <p>Note the added reference to the Accord.dll and Accord.Math.dll assemblies; while the code presented below doesn’t reference it explicitly, it looks like Accord.MachineLearning is trying to load the assembly, which fails miserably if they are not referenced.</p> <p>Then, we need some data; once the training set and validation set have been downloaded to your local machine (see the gist for the datasets url), that’s fairly easy to do:</p><pre class="brush: fsharp; gutter: false; toolbar: false;">let training = @"C:/users/mathias/desktop/dojosample/trainingsample.csv" let validation = @"C:/users/mathias/desktop/dojosample/validationsample.csv" let readData filePath = File.ReadAllLines filePath |&gt; fun lines -&gt; lines.[1..] |&gt; Array.map (fun line -&gt; line.Split(',')) |&gt; Array.map (fun line -&gt; (line.[0] |&gt; Convert.ToInt32), (line.[1..] |&gt; Array.map Convert.ToDouble)) |&gt; Array.unzip let labels, observations = readData training </pre> <p>We read every line of the CSV file into an array of strings, drop the headers with array slicing, keeping only items at or after index 1, split each line around commas (so that each line is now an array of strings), retrieve separately the first element of each line (what the number actually is), and all the pixels, which we transform into a float, and finally unzip the result, so that we get an array of integers (the actual numbers), and an array of arrays, the grayscale level of each pixel.</p> <p>Now that we have data, we can begin the machine learning process. One nice thing about Accord.NET is that out of the box, it includes two implementations for multi-class learning. By default, a SVM is a binary classifier: it separates between two classes only. In our case, we need to separate between 10 classes, because each number could be anything between 0 and 9. Accord.NET has two SVM “extensions” built-in, a multi-label classifier, which constructs a one-versus-all classifier for each class, and a multi-class classifier, which constructs a one-versus-one classifier for every class; in both cases, the library handles determining what is ultimately the most likely class.</p> <p>I had never used a multi-class SVM, so that’s what I went for. The general library design is object oriented: we create a Support Vector Machine, which will be responsible for classifying, configure it, and pass it to a Learning class, which is responsible for training it using the training data it is given, and a “learning strategy”. In the case of a multi-class learning process, the setup follows two steps: we need to configure the overall multi-class SVM and Learning algorithm (what type of kernel to use, how many classes are involved, and what data to use), but also define how each one-versus-one SVMs should operate.</p><pre class="brush: fsharp; gutter: false; toolbar: false;">let features = 28 * 28 let classes = 10 let algorithm = fun (svm: KernelSupportVectorMachine) (classInputs: float[][]) (classOutputs: int[]) (i: int) (j: int) -&gt; let strategy = SequentialMinimalOptimization(svm, classInputs, classOutputs) strategy :&gt; ISupportVectorMachineLearning let kernel = Linear() let svm = new MulticlassSupportVectorMachine(features, kernel, classes) let learner = MulticlassSupportVectorLearning(svm, observations, labels) let config = SupportVectorMachineLearningConfigurationFunction(algorithm) learner.Algorithm &lt;- config let error = learner.Run() printfn "Error: %f" error </pre> <p>We have 28x28 features (the pixel of each image) and 10 classes (0 to 9, the actual number). The algorithm is a function (a delegate, in Accord.NET), defining how each one-vs-one classifier should be built. It expects a SVM (what SVM will be constructed to classify each pair of numbers), what input to use (the pixels, as a 2D array of floats) and the corresponding expected output (the numbers, an array of ints), and 2 numbers i and j, the specific pair we are building a model for. I haven’t checked, but I assume the “outer” multi-class machine creates a SVM for each case, filtering the training set to keep only the relevant training data for each possible combination of classes i and j. Using that data, we set up the learning strategy to use, in this case a SMO (Sequential Minimal Optimization), and return the corresponding interface.</p> <p>That’s the painful part – once this is done, we pick a Linear Kernel, the simplest one possible (Accord.NET comes with a battery of built-in Kernels to chose from), create our multi-class SVM, and setup the learner, who will be responsible for training the SVM, pass it the strategy – and the machine can start learning.</p> <p>If you run this in FSI, after a couple of seconds, you should see the following:</p> <p><font face="Consolas">Error: 0.000000</font></p> <p>The SVM properly classifies every example in the training set. Nice! Let’s see how it does on the validation set: </p><pre class="brush: fsharp; gutter: false; toolbar: false;">let validationLabels, validationObservations = readData validation let correct = Array.zip validationLabels validationObservations |&gt; Array.map (fun (l, o) -&gt; if l = svm.Compute(o) then 1. else 0.) |&gt; Array.average let view = Array.zip validationLabels validationObservations |&gt; fun x -&gt; x.[..20] |&gt; Array.iter (fun (l, o) -&gt; printfn "Real: %i, predicted: %i" l (svm.Compute(o))) </pre> <p>We extract the 500 examples from the second data set; for each example, if the SVM predicts the true label, we count it as a 1, otherwise a 0 – and average these out, which produces the percentage of examples correctly predicted by the SVM. For good measure, we also display the 20 first examples, and what was predicted by the SVM, which produces the following result: 90% correct, and</p> <p><font face="Consolas">Real: 8, predicted: 1<br>Real: 7, predicted: 7<br>Real: 2, predicted: 2<br>Real: 6, predicted: 6<br>Real: 3, predicted: 3<br>Real: 1, predicted: 8<br>Real: 2, predicted: 2<br>Real: 6, predicted: 6<br>Real: 6, predicted: 6<br>Real: 6, predicted: 6<br>Real: 6, predicted: 6<br>Real: 4, predicted: 4<br>Real: 8, predicted: 8<br>Real: 1, predicted: 1<br>Real: 0, predicted: 0<br>Real: 7, predicted: 7<br>Real: 6, predicted: 5<br>Real: 2, predicted: 4<br>Real: 0, predicted: 0<br>Real: 3, predicted: 3<br>Real: 6, predicted: 6</font></p> <p>We see a 1 and 8 being mistaken for each other, and a 6 classified as a 5, which makes some sense. And that’s it – in about 60 lines of code, we got a support vector machine working!</p> <h2>Conclusion</h2> <p>Getting the code to work was overall fairly simple; the two pain points were first the dynamic loading (I had to run it until I could figure out every dependency that needed referencing), and then setting up the delegate responsible for setting up the 1-vs-1 learning. I kept the code un-necessarily verbose, with type annotations everywhere – these are technically not needed, but they hopefully clarify how the arguments are being used. Also, a point of detail: the <font face="Consolas">MulticlassSupportVectorMachine</font> class implements IDisposable, and I am not certain why that is.</p> <p>The resulting classifier is OK, but not great – a trivial KNN classifier has a better accuracy than this. That being said, I can’t blame the library for that, I used the dumbest possible Kernel, and didn’t play with any of the Sequential Minimization parameters. On the plus side, the learning process is pretty fast, and the Supper Vector Machine should be faster than the KNN classifier: without modifying any of the options available or default values, Accord.NET trained a pretty decent model. I tried to run it on the full 50,000 examples Kaggle dataset, and ran into some memory issues there, but it seems there are also options to trade memory and speed, which is nice.</p> <p>All in all, a good first impression! Now that I got the basics working, I’ll probably revisit this later, and explore the advanced options, as well as some of the other algorithms implemented in the library (in particular, Neural Networks). I also need to think about whether it would make sense to build F# extensions to simplify usage a bit. In the meanwhile, hopefully this post might serve as a handy “quick-start” for someone!</p> <p>Full <a href="https://gist.github.com/mathias-brandewinder/6443302">gist available on GitHub</a>.</p><div class="feedflare"> <a href="http://feeds.feedburner.com/~ff/ClearLinesBlog?a=GBYumpxa1_I:IieQ1FhJ3KM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ClearLinesBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ClearLinesBlog?a=GBYumpxa1_I:IieQ1FhJ3KM:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/ClearLinesBlog?i=GBYumpxa1_I:IieQ1FhJ3KM:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ClearLinesBlog?a=GBYumpxa1_I:IieQ1FhJ3KM:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/ClearLinesBlog?i=GBYumpxa1_I:IieQ1FhJ3KM:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ClearLinesBlog?a=GBYumpxa1_I:IieQ1FhJ3KM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/ClearLinesBlog?i=GBYumpxa1_I:IieQ1FhJ3KM:V_sGLiPBpWU" border="0"></img></a> </div><img src="http://feeds.feedburner.com/~r/ClearLinesBlog/~4/GBYumpxa1_I" height="1" width="1"/>Fri, 06 Sep 2013 21:15:29 -0700http://strangelights.com/blog/archive/2013/09/04/the-software-developer-identity-crisis.aspxhttp://strangelights.com/blog/archive/2013/09/04/the-software-developer-identity-crisis.aspxThe Software Developer Identity Crisis<p>This is post tries to explain some of what I was talking about in my talk at <a href="http://weactuallybuildstuff.com/">weactuallybuildstuff.com</a>, it’s series of two posts, I’ve tried write it as one post but it got too long and icky, so I’ve split it into two.</p> <p>I believe at the heart of Software Development culture there is an identity crisis. I say this because I believe software development to be an engineering discipline, based on science, but many of fellow developers do not believe this. They say it is an art form or a craft.</p> <p>To support my argument I think first it would be useful to look at what engineering is. Wikipedia currently defines <a href="http://en.wikipedia.org/wiki/Engineering">engineering</a> as:</p> <blockquote> <p>Engineering is the application of scientific, economic, social, and practical knowledge in order to design, build, and maintain structures, machines, devices, systems, materials and processes</p> </blockquote> <p>In software, we’re trying build stuff so, it seems clear to me that following engineering practices is necessary. But what are good engineering practices? This is where the science bit comes in. Wikipedia currently defines science as:</p> <blockquote> <p>Science (from Latin scientia, meaning "knowledge") is a systematic enterprise that builds and organizes knowledge in the form of testable explanations and predictions about the universe.</p> </blockquote> <p>So science is how we organize knowledge, so we can use science and particularly the <a href="http://en.wikipedia.org/wiki/Scientific_method">scientific method</a> to investigate what are good software engineering practices. Accept, I’m left with the overwhelming feeling that we don’t do this. With open source we have become very good at sharing building blocks for software, this is a good thing and I think it’s something our industry can be proud of, but it isn’t enough. To again more insight into best practices we need industry and write more papers and reports on successful and unsuccessful projects (understand the reasons for failure is very import too). Industry also needs to get better about publish statics about projects, and knowing which statistics to collect. We also need a better relations between academia and industry so academics can take up the challenge of performing meta-analysis once this data is available. I not knocking academia, I believe there’s some good working been done out there, but what also needed is a different kind of work. I think more people need to do the for software what epidemiologist do for medicine. In medicine an epidemiologist is someone how looks for health best practices by studying the available data, think computer science desperately needs someone to pull together the available data on software engineering and help tease out what the best practices of our industry really are. (Apologies if you are an academic working in the way I describe, but I don’t feel your voice is being heard)</p> <p>When I talk about this there are two arguments I often hear people use against software needing science and engineering, so I’d like to deal with them briefly here. The first is that software can’t be engineering as it is an art/craft. I think this is wrong as it false dichotomy. Many artists and crafts folk rely on science and engineering, they often spend years learning the details of how things look and techniques to reproduce them in there chosen medium. If you want to produce giant sculptures as <a href="http://en.wikipedia.org/wiki/Louise_Bourgeois">Louise Bourgeois</a> did, then you’ll need to know a thing or two about engineering, though if your Damien Hirst <a href="http://www.theatlanticwire.com/entertainment/2012/01/david-hockey-reminds-damien-hirst-he-doesnt-use-assistants/46924/">you may outsource this</a>. Interestingly, for perhaps the most famous artist, Leonardo da Vinci, there was no difference between art and science. Leonardo often drew the world <a href="http://www.bbc.co.uk/news/magazine-17907305">in an attempt to understand</a> it better and also to express his <a href="http://www.britishmuseum.org/explore/highlights/highlight_objects/pd/l/leonardo_da_vinci,_military_ma.aspx">ideas about science and technology</a>. The second I often hear against the use of science/engineering in software is that software engineering is simply too complex to be study by science. While it’s true than there are many factors that effect what makes a successful software project and this makes it difficult for scientist to pull part how to build software successful project and give it back to us in easy to understand chunks, not to even try seems a little defeatist. After all, where people have applied the scientific method with rigor we have learn a great deal on <a href="http://en.wikipedia.org/wiki/Evaluation">many</a> <a href="http://en.wikipedia.org/wiki/Theory_of_relativity">complex</a> <a href="http://en.wikipedia.org/wiki/Quantum_mechanics">subjects</a>.</p> <p>For what it’s worth I’m not saying current trends in software development, like agile and craftsmanship, are wrong, I merely saying we’re not doing enough to check they are taking us in the right directions. As Scott Hanselman pointed out there’s <a href="http://www.hanselman.com/blog/EverythingsBrokenAndNobodysUpset.aspx">clearly room for improvement</a>. So, summary, don’t be afraid to follow intuition and draw inspirations form many other unrelated domains, but always fall back on scientific method to check these intuitions are leading in the right direction.</p> <p>The follow will “How We Fool Ourselves: Why Intuition Isn't Enough” will be published shortly (at my current blogging rate “shortly” means before end of 2015).</p> <p>(Interesting aside: I found this article from Joe Duffy <a href="http://joeduffyblog.com/2013/07/13/blurring-the-line-between-research-and-engineering/">“Bluring the line between research and development”</a> had and interesting and not dissimilar view of the relationship between industry and academia)</p><img src="http://strangelights.com/blog/aggbug/1712.aspx" width="1" height="1" /><div class="feedflare"> <a href="http://feeds.feedburner.com/~ff/RobertPickeringsStrangeBlog?a=xvXS2PNFfbo:6eZ4cXnfOvk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/RobertPickeringsStrangeBlog?d=yIl2AUoC8zA" border="0"></img></a> </div>Wed, 04 Sep 2013 12:59:48 -0700http://fwaris.wordpress.com/?p=462http://fwaris.wordpress.com/2013/09/03/talking-to-you-car-with-openxc-android-xamarin-f/uncategorizedTalking to you car – with OpenXC, Android, Xamarin & F#Virtually all current vehicles today operate an internal network called the CAN bus. Different modules (or ECUs &#8211; electronic control units) in the car communicate with each other via this network (e.g. engine, transmission, dashboard, etc.). In this post I reference &#8230; <a href="http://fwaris.wordpress.com/2013/09/03/talking-to-you-car-with-openxc-android-xamarin-f/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fwaris.wordpress.com&#038;blog=17515918&#038;post=462&#038;subd=fwaris&#038;ref=&#038;feed=1" width="1" height="1" />Tue, 03 Sep 2013 04:18:12 -0700http://fwaris.wordpress.com/?p=462http://fwaris.wordpress.com/2013/09/03/talking-to-you-car-with-openxc-android-xamarin-f/uncategorizedTalking to you car – with OpenXC, Android, Xamarin & F#Virtually all current vehicles today operate an internal network called the CAN bus. Different modules (or ECUs &#8211; electronic control units) in the car communicate with each other via this network (e.g. engine, transmission, dashboard, etc.). In this post I reference &#8230; <a href="http://fwaris.wordpress.com/2013/09/03/talking-to-you-car-with-openxc-android-xamarin-f/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=fwaris.wordpress.com&#038;blog=17515918&#038;post=462&#038;subd=fwaris&#038;ref=&#038;feed=1" width="1" height="1" />Tue, 03 Sep 2013 04:18:12 -0700http://theburningmonk.com/?p=3014http://theburningmonk.com/2013/09/clojure-multi-arity-and-variadic-functions/f#clojureprogrammingClojure – Multi-Arity and Variadic functionsIn F#, you can’t overload a let–bound function, and whilst it’s a hindrance sometimes you can generally work around it easily enough since you can still overload members of a class. All you need to do is to wrap the module and constituent functions into a class and overload the class members instead. Multi-Arity Functions [...]Tue, 03 Sep 2013 00:40:11 -0700http://www.clear-lines.com/blog/post.aspx?id=a3771fe8-c9ac-439f-8d81-4001d572af3dhttp://www.clear-lines.com/blog/post/Field-notes-from-the-F-tour.aspxf#.net.net communityField notes from the F# tour<p>I have been back for about a week now, after nearly <a href="http://clear-lines.com/blog/post/Summer-of-FSharp-Tour.aspx">three weeks on the road, talking about F#</a> all over the US. The first day I woke up in my own bed, my first thought was “where am I again? And where am I speaking tonight?”, now life is slowly getting back to normal, and I thought it would be a good time to share some impressions from the trip.</p> <ul> <li>I am <u>very</u> proud to have inaugurated two new F# meetup groups during that trip! The <a href="http://www.meetup.com/DC-fsharp/">Washington DC F# meetup</a>, organized by <a href="https://twitter.com/devshorts">@devshorts</a>, is off to a great start, we had a full house at <a href="https://twitter.com/blinemedical">B-Line Medical</a> that evening, with a great crowd mixing F# fans, C# developers, as well as OCaml and Python people, it was great. My favorite moment there was with Sam. Sam, a solid C# developer, looked very worried about writing F# code for the first time. Two hours later, he was so proud (and legitimately so) of having a nice classifier working, all in F#, that he couldn’t resist, and <a href="http://tech.blinemedical.com/machine-learning-with-f-and-c-side-by-side/">presented his code to the entire group</a>. Nice job! Detroit was my final stop on the road, and didn’t disappoint: the Detroit F# meetup was awesome. It was hosted at the <a href="http://www.grandtrunkpub.com/history/">Grand Trunk Pub</a>; while the location had minor logistics drawbacks, it was amply compensated by having food and drinks right there, as well as a great crowd. Thanks to&nbsp; <font style="font-weight: normal"><a href="https://twitter.com/OldDutchCap">@OldDutchCap</a> and <a href="https://twitter.com/JohnBFair">@JohnBFair</a> for making this happen, this was a suitable grand finale for this trip!</font> <li>In general, August seems to be the blossoming period for F# meetups – two other groups popped up in the same month, one in <a href="http://www.meetup.com/Minsk-F-User-Group/">Minsk</a>, thanks to the efforts of <a href="https://twitter.com/lu_a_jalla">@lu_a_jalla</a> and <a href="https://twitter.com/sergey_tihon">@sergey_tihon</a>, and one in <a href="http://www.meetup.com/Functional-Programming-in-F/">Paris</a>, spearheaded by <a href="https://twitter.com/tjaskula">@tjaskula</a>, <a href="https://twitter.com/robertpi">@robertpi</a> and <a href="https://twitter.com/thinkb4coding">@thinkb4coding</a>, this is very exciting, and I am looking forward to meeting some F#ers next time I stop back home! <li>A lesson I learnt the hard way is that San Francisco is most definitely not a good benchmark for what to wear in August in the US. My first stops were all in the south – Houston, Nashville, Charlotte and Raleigh, and boy was I not ready for the crazy heat and humidity! On the other hand, I can confirm the rumor, the South knows how to make a guest welcome. For that matter, I am extremely grateful to everyone who hosted me during this trip – you know who you are, thank you for all the help. <li>One surprise during this trip was the general level of interest in F#. I regularly hear <strike>nonsense</strike> sentences like “F# is a niche language”, so I expected smaller crowds in general .NET groups. Well, apparently someone forgot to tell the .NET developers, because I got pretty solid audiences in these groups as well, with an amazing <a href="http://www.meetup.com/TriNUG/events/126183832/">100 people showing up in Raleigh</a>. Trinug rocked! <li>In general, I was a bit stressed out by running a hands-on machine learning lab with F# novices; for an experienced F# user, it’s not incredibly complex, but for someone who hasn’t used the language before, it’s a bit of a “here is the deep-end of the swimming pool, now go see if you can swim” moment. I was very impressed by how people did in these groups, everyone either finished or ended up very close. Amusingly, in one of the groups, the first person who completed the exercise, in very short time, was… a DBA, who explained that he immediately went for a set-oriented style. Bingo! The lesson for me is that F# is not complicated, but you have to embrace its flow, and largely forget about C#. One trick which seemed to help was to ask the question “how would you write it if you were using only LINQ”. Otherwise, C# developers seemed to often over-think and build code blocks too large for their own good, whereas F# works best by creating very small and simple functions, and then assembling them in larger workflows. <li>Another fun moment was in Boston, where I ran the Machine Learning dojo at <a href="https://twitter.com/hackreduce">Hack/Reduce</a>, language agnostic (thanks <a href="https://twitter.com/JonnyBoats">@JonnyBoats</a> for making the introductions!). Pretty much every language under the sun was represented (C#, Java, F#, Scala, Python, Matlab, Octave, R, Clojure, Ruby) – but one of the participants still managed to pull “something special”, and tried to implement a classifier entirely in PostgreSQL. It didn’t quite work out, but hats off nevertheless, that was a valiant experiment!</li></ul><iframe class="vine-embed" height="320" src="https://vine.co/v/he7DDrtJKKH/embed/simple" frameborder="0" width="320"></iframe><script async src="//platform.vine.co/static/scripts/embed.js" charset="utf-8"></script> <ul> <li>As a Frenchman, I take food seriously. As a scientist, I want to see the data. Therefore, I was very excited to have the opportunity to investigate whether Northern Carolina style BBQ is indeed an heresy, first hand. I got the chance to try out BBQ in Houston and Raleigh, and I have to give it to Texas, hands down.</li></ul> <p><a href="http://www.clear-lines.com/blog/image.axd?picture=Texas-BBQ.jpg"><img title="Texas-BBQ" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="Texas-BBQ" src="http://www.clear-lines.com/blog/image.axd?picture=Texas-BBQ_thumb.jpg" width="240" height="189"></a></p> <ul> <li>Lesson learnt the hard way: do not ever depend on the internet for a presentation. Some of my material was on a Gist on GitHub, and a couple of hours before a presentation, I realized that they were under a DOS attack. Not happy times. <li>I am more and more of a fan of the hands-on, write code in groups format. It has its limitations – you can’t really do it with a very large crowd, and it requires more time than a traditional talk – but it’s a very different experience. One thing I really enjoyed when starting with F# was its interactivity; the “write code and see what happens” experience rekindled the joy of coding for me. The hands-on format captures some of that “happy hacking” spirit, and gets people really engaged. Once someone start writing code, they own it – and working in groups is a great way to accelerate the learning process, and build a community.</li></ul> <p><a href="http://www.clear-lines.com/blog/image.axd?picture=Philly.jpg"><img title="Great afternoon with @phillyaltnet crowd hacking at #kaggle machine learning dataset with #fsharp" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="Great afternoon with @phillyaltnet crowd hacking at #kaggle machine learning dataset with #fsharp" src="http://www.clear-lines.com/blog/image.axd?picture=Philly_thumb.jpg" width="240" height="180"></a><a href="http://www.clear-lines.com/blog/image.axd?picture=Raleigh.jpg"><img title="Machine learning and lots of fun with #fsharp @trinug tonight, you guys rocked!" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="Machine learning and lots of fun with #fsharp @trinug tonight, you guys rocked!" src="http://www.clear-lines.com/blog/image.axd?picture=Raleigh_thumb.jpg" width="240" height="180"></a></p> <ul> <li>I have been complacent with the story “it works on environments other than Windows/Visual Studio”. It does, but the best moment to figure out how to make it work exactly is not during a group coding exercise. In these situations, <a href="http://fsharp.org/">fsharp.org</a> is your friend – and since I came back, I started actually trying all that out, because “I heard it should work” is just not good enough. <li>I saw probably somewhere between 500 and 1,000 developers during this trip, and while this was completely exhausting, I don’t regret any of it. One of the highpoints of the whole experience was to just get some time to hang out with old or new friends from the F#/functional community – <a href="https://twitter.com/panesofglass">@panesofglass</a> in Houston, <a href="https://twitter.com/bryan_hunter">@bryan_hunter</a> and the FireFly Logic &amp; <a href="https://twitter.com/nashfp">@NashFP</a> crew in Nashville, @rickasaurus, <a href="https://twitter.com/tomaspetricek">@tomaspetricek</a>, <a href="https://twitter.com/pblasucci">@pblasucci</a>, <a href="https://twitter.com/mitekm">@mitekm</a> and <a href="https://twitter.com/hmansell">@hmansell</a> in New York City, and <a href="https://twitter.com/plepilov">@plepilov</a>, <a href="https://twitter.com/kbattocchi">@kbattocchi</a> and <a href="https://twitter.com/talbott">@talbott</a> in Boston (sorry if I forgot anyone!). If this trip taught me one thing, it’s that there is actually a <strong>lot</strong> of interest for F# in the .NET community, and beyond – but we, the F# community, are very scattered, and from our smaller local groups, it’s often hard to get a sense for that. Having a chance to talk to all of you guys who have been holding the fort and spreading F# around, discussing what we do, what works and what doesn’t, and simply having a good time, was fantastic. We need more of this – I am incredibly invigorated, and very hopeful that 2014 will be a great year for F#!</li></ul><div class="feedflare"> <a href="http://feeds.feedburner.com/~ff/ClearLinesBlog?a=JdLHudgbJmg:W0hokF_cyAw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ClearLinesBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ClearLinesBlog?a=JdLHudgbJmg:W0hokF_cyAw:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/ClearLinesBlog?i=JdLHudgbJmg:W0hokF_cyAw:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ClearLinesBlog?a=JdLHudgbJmg:W0hokF_cyAw:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/ClearLinesBlog?i=JdLHudgbJmg:W0hokF_cyAw:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ClearLinesBlog?a=JdLHudgbJmg:W0hokF_cyAw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/ClearLinesBlog?i=JdLHudgbJmg:W0hokF_cyAw:V_sGLiPBpWU" border="0"></img></a> </div><img src="http://feeds.feedburner.com/~r/ClearLinesBlog/~4/JdLHudgbJmg" height="1" width="1"/>Mon, 02 Sep 2013 02:39:30 -0700http://theburningmonk.com/?p=3011http://theburningmonk.com/2013/09/binary-and-json-serializer-benchmarks-updated/programmingperformancesimplespeedtesterBinary and JSON serializer benchmarks updatedFirst of all I’d like to offer my sincere apologies to those who have asked me to update my benchmark numbers following the release of Json.NET 5.0.6, it took me a long time to clear some of my backlogs and only just got around to it, sorry for the waiting! The good news is that, [...]Mon, 02 Sep 2013 00:45:11 -0700http://sergeytihon.wordpress.com/?p=2174http://sergeytihon.wordpress.com/2013/09/02/f-weekly-35-2013/f#f# weeklynews:f# weeklyF# Weekly #35 2013Welcome to F# Weekly, A roundup of F# content from this past week: News Canopy 0.8.0 was released with PhantomJS support. Brahma.FSharp(F# quotation to OpenCL translator) is available on NuGet. Will Smith embedded FSI in Quake3 (part 2). Paris F# User Group was registered and growing up. Code, build and run &#8211; WebSharper mobile apps in [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sergeytihon.wordpress.com&#038;blog=15048173&#038;post=2174&#038;subd=sergeytihon&#038;ref=&#038;feed=1" width="1" height="1" />Sun, 01 Sep 2013 21:00:27 -0700http://sergeytihon.wordpress.com/?p=2164http://sergeytihon.wordpress.com/2013/09/01/msr-splat-overview-for-f/f#nlpmicrosoft researchMSR-SPLAT Overview for F#Some weeks ago, Microsoft Research announced NLP toolkit called MSR SPLAT. It is time to play with it and take a look what it can do. Statistical Parsing and Linguistic Analysis Toolkit is a linguistic analysis toolkit. Its main goal is to allow easy access to the linguistic analysis tools produced by the Natural Language [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sergeytihon.wordpress.com&#038;blog=15048173&#038;post=2164&#038;subd=sergeytihon&#038;ref=&#038;feed=1" width="1" height="1" />Sun, 01 Sep 2013 14:44:17 -0700http://theburningmonk.com/?p=3000http://theburningmonk.com/2013/09/dart-implementing-the-singleton-pattern-with-factory-constructors/programmingdesign patternsdartDart – implementing the Singleton pattern with factory constructorsIn Dart there is an interesting language feature called ‘Factory Constructors’, which effectively allows you to override the default behaviour when using the new keyword – instead of always creating a new instance the factory constructor is merely required to return an instance of the class, the difference is important. Factory constructors allow you to [...]Sun, 01 Sep 2013 00:59:17 -0700http://trelford.com/blog/post.aspx?id=7070b91f-d8de-4f6c-a21b-8d4b66b9a442http://trelford.com/blog/post/ten.aspxf#scalaerlanghaskelljavascriptclojureluaTry 10 Programming Languages in 10 minutes<p>There are a lot of interesting programming languages out there, but downloading and setting up the environment can be very time consuming when you just want to try one out. The good news is that you can try out many languages in your browser straight away, often with tutorials which guide you through the basics. </p> <p>Following the pattern of <a href="http://pragprog.com/book/btlang/seven-languages-in-seven-weeks">7 languages in 7 weeks</a> book, here’s a somewhat abridged version.</p> <h2><strong>Dynamic Languages</strong></strong> </h2> <p>Fed up of long compile times, want a lightweight environment for scripting? Dynamic languages could be your new friend.</p> <h3><a href="http://trylua.org/">Try Lua</a></h3> <p><a href="http://en.wikipedia.org/wiki/Lua_(programming_language)">Lua</a> is a lightweight dynamic language with excellent <a href="http://en.wikipedia.org/wiki/Coroutine">coroutine</a> support and a simple C API making it hugely popular in video gaming for scripting. Have fun with game engines like <strong><a href="https://love2d.org/">LÖVE</a> </strong>and <a href="http://www.madewithmarmalade.com/quick">Marmalade Quick</a>.</p> <h3><a href="http://tryclj.com/">Try Clojure</a></h3> <p><a href="http://en.wikipedia.org/wiki/Clojure">Clojure</a> is the brainchild of the hugely charismatic speaker <a href="http://www.infoq.com/presentations/Simple-Made-Easy-QCon-London-2012">Rich Hickey</a>, it is a descendant of one of the earliest programming languages <a href="http://en.wikipedia.org/wiki/Lisp_(programming_language)">LISP</a>. There’s a really rich community around Clojure, one of my favourite projects is <a href="http://www.youtube.com/watch?v=imoWGsipe4k">Sam Aaron</a>’s <a href="http://overtone.github.io/">Overtone</a> live coding audio environment.</p> <h3><a href="http://www.codeschool.com/courses/try-r">Try R</a> (quick registration required)</h3> <p><a href="http://en.wikipedia.org/wiki/R_(programming_language)">R</a> is a free environment for statistical computing and graphics, with a huge range of user-submitted packages. Ever wondered how to draw an <a href="http://vis.supstat.com/2013/03/draw-easter-eggs/">egg</a>?</p> <h2>Functional Languages</h2> <p>Aspects of functional programming have permeated most mainstream languages from C++ to VB. However to really appreciate the expressiveness of the functional approach a functional-first language is required.</p> <h3><a href="http://www.tryerlang.org/">Try Erlang</a></h3> <p><a href="http://en.wikipedia.org/wiki/Erlang_(programming_language)">Erlang</a> is a really interesting language for building fault tolerant concurrent systems. It also has great <a href="http://en.wikipedia.org/wiki/Pattern_matching">pattern matching</a> capabilities. It has many industrial applications and tools including the <a href="http://en.wikipedia.org/wiki/RabbitMQ">RabbitMQ</a> messaging system and the distribute database <a href="http://en.wikipedia.org/wiki/Riak">Riak</a>.</p> <h3><a href="http://tryhaskell.org/">Try Haskell</a></h3> <p><a href="http://en.wikipedia.org/wiki/Haskell_(programming_language)">Haskell</a> is heavily based on the <a href="http://en.wikipedia.org/wiki/Miranda_(programming_language)">Miranda programming language</a> which was taught in British universities in the 80s and 90s. Haskell added Monads and Type Classes, and is still taught in a few universities, it is also still quite popular in academic research.</p> <h3><a href="http://try.ocamlpro.com/">Try OCaml</a></h3> <p><a href="http://en.wikipedia.org/wiki/OCaml">OCaml</a> like Miranda is based on the <a href="http://en.wikipedia.org/wiki/ML_(programming_language)">ML programming language</a> adding object-oriented constructs. <a href="http://fsharp.org/">F#</a> is based on OCaml, there is even a compatibility mode. OCaml still has industrial application, for example at Jane Street Capital and XenSource. </p> <h2>Web Languages</h2> <p>There’s a plethora of languages that <a href="http://altjs.org/">compile to JavaScript languages</a> out there. Also worth a look are the new features in JavaScript itself, see <a href="https://twitter.com/BrendanEich">Brendan Eich</a>’s talk at <a href="https://thestrangeloop.com/">Strangeloop</a> last year on the <a href="http://brendaneich.github.io/Strange-Loop-2012/#/">The State of JavaScript</a>. Here’s 3 *Script languages I find particularly interesting:</p> <h3><a href="http://livescript.net/">LiveScript</a></h3> <p>LiveScript is an indirect descendant of <a href="http://en.wikipedia.org/wiki/Coffeescript">CoffeeScript</a> with features to assist functional programming like <a href="http://en.wikipedia.org/wiki/Pattern_matching">pattern matching</a> and <a href="http://en.wikipedia.org/wiki/Function_composition_(computer_science)">function composition</a>. Check out <a href="http://livescript.net/blog/livescript-one-liners-to-impress-your-friends.html">10 LiveScript one liners to impress your friends</a>.</p> <h3><a href="http://elm-lang.org/try">Try Elm</a></h3> <p><a href="http://elm-lang.org/">Elm</a> is a functional reactive language for creating highly interactive programs, including <a href="http://elm-lang.org/blog/games-in-elm/part-0/Making-Pong.html">games</a>. Reactive programming is an interesting direction and I think languages designed specifically for this are worth investigating.</p> <h3><a href="http://pogoscript.org/">PogoScript</a></h3> <p>Unfortunately there’s currently no online editor for this one, but there is a command line <a href="http://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop">REPL</a>. PogoScript is <a href="http://en.wikipedia.org/wiki/Domain-specific_language">DSL</a> friendly allowing white space in function names.</p> <h2>Esoteric Languages</h2> <p><a href="http://en.wikipedia.org/wiki/Esoteric_programming_language">Esoteric languages</a> tend to be write-only, a bit like <a href="http://en.wikipedia.org/wiki/Perl">Perl</a> but just for fun.</p> <h3><a href="http://trybrainfuck.org/">Try Brainfuck</a></h3> <p><a href="http://en.wikipedia.org/wiki/Brainfuck">Brainfuck</a> is the Rubik’s cube of programming languages. I built the site last year with the interpreter written in plain old JavaScript, check out the fib sample.</p> <h2>Browser IDEs</h2> <p>With so many programming language experimentation environments available online, the next logical step is to host the IDE there. Imagine not having to wait 4 hours for Visual Studio to install. </p> <p><a href="https://c9.io/">Cloud 9</a> is an online environment for creating <a href="http://nodejs.org/">Node.js</a> apps, pulling together sets of relevant packages. Tools like <a href="http://www.sploder.com/">Sploder</a> let you build games online.</p> <p>The <a href="http://www.tryfsharp.org/">Try F#</a> site offers arguably the most extensive online learning features of any language. Cloud <a href="http://tsunami.io/">Tsunami IDE</a> also offers a rich online development experience for F#. In the near future <a href="https://twitter.com/CloudSharper/status/370255557724078082/photo/1">CloudSharper</a> will offer an online IDE experience for developing web applications with F# using <a href="http://www.websharper.com/">WebSharper</a>,</p> <h2>Scaling up</h2> <p>Once you’ve completed some <a href="http://rosettacode.org/wiki/Rosetta_Code">basic tasks</a> in a new language you’ll want to move on to slightly larger tasks. I like to use exercises from the coding <a href="http://codingdojo.org/cgi-bin/wiki.pl?KataCatalogue">Kata Catalogue</a> like <a href="http://trelford.com/blog/post/FizzBuzz.aspx">FizzBuzz</a>, the <a href="http://trelford.com/blog/post/140.aspx">Game of Life</a> and <a href="http://pastebin.com/s9mChuPp">Minesweeper</a>. </p> <p>Some people enjoy going through the <a href="http://projecteuler.net/">Project Euler</a> problems, others have their own hello world applications. For <a href="http://martintrojer.github.io/">Martin Trojer</a> it’s a <a href="http://martintrojer.github.io/scala/2013/06/06/scheme-in-scala/">Scheme interpreter</a> and <a href="https://github.com/lukehoban">Luke Hoban</a> often writes a <a href="http://blogs.msdn.com/b/lukeh/archive/2007/04/03/a-ray-tracer-in-c-3-0.aspx">Ray Tracer</a>.</p> <p>I’d also recommend joining a local meetup group. The <a href="http://www.meetup.com/london-scala/">London Scala meetup</a> have a coding dojo every month and the <a href="http://www.meetup.com/fsharplondon/">F#unctional Londoners</a> meetup have hands on session in the middle the month, the next one is on <a href="http://www.meetup.com/FSharpLondon/events/129198542/">Machine Learning</a>.</p> <p>Programming language books that include questions at the end of sections are a good way to practice what you’ve learned but are <a href="http://tirania.org/blog/archive/2013/Apr-25.html">few and far between</a>. The recent <a href="http://www.cambridge.org/gb/academic/subjects/computer-science/programming-languages-and-applied-logic/functional-programming-using-f">Functional Programming with F#</a> book is an excellent example of what can be done with questions at the end of each chapter.</p> <p>While the basics of a language can be picked up in a few hours, expect it to take a few weeks before you’re productive and at least a few months before you start to gain mastery.</p> <p>Want to write your own language? Pete Sestoft’s <a href="http://www.itu.dk/people/sestoft/plc/">Programming Language Concepts</a> book offers a good introduction to the subject.</p>Sat, 31 Aug 2013 17:47:43 -0700http://trelford.com/blog/post.aspx?id=1126e9d4-ba81-4777-b22f-ac5157b67f79http://trelford.com/blog/post/gday.aspxf#silverlightluamonoBuilding a game in a day<p>Last night I gave a talk at the <a href="http://www.meetup.com/FSharpLondon/">F#unctional Londoners meetup</a> about my experiences working in a team building a game in a day at the recent London <a href="http://globalgamecraft.com/">GameCraft</a> game jam event. We went with a continuous runner and used XNA to build the game on Windows with a <a href="http://stackoverflow.com/questions/10881005/how-to-install-xna-game-studio-on-visual-studio-2012">hack</a> to get it working on Visual Studio 2012, then <a href="http://neildanson.wordpress.com/">Neil Danson</a> was able to port it to iOS and Android using <a href="http://www.monogame.net/">MonoGame</a>. I brought along an Apple iPad and Google Nexus 7 both happily running the game.</p> <iframe src="http://www.slideshare.net/slideshow/embed_code/25730944" width="512" height="421" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="border:1px solid #CCC;border-width:1px 1px 0;margin-bottom:5px" allowfullscreen webkitallowfullscreen mozallowfullscreen> </iframe> <div style="margin-bottom:5px"> <strong> <a href="https://www.slideshare.net/ptrelford/building-a-game-in-a-day" title="Building a game in a day" target="_blank">Building a game in a day</a> </strong> from <strong><a href="http://www.slideshare.net/ptrelford" target="_blank">ptrelford</a></strong> </div> <br/> <p><strong>iOS and Android</strong></p> <p>A recent article in the <a href="http://www.theguardian.com/technology/appsblog/2013/aug/21/android-games-outselling-sony-nintendo">Guardian</a> suggests that iOS and Android combined now generate four times the revenue of dedicated gaming handhelds. Both Unity and MonoGame let you target those platforms. I played a little with <a href="http://unity3d.com/">Unity</a> at the <a href="http://www.eurogamer.net/articles/2013-07-03-rezzed-game-jam-2013">Rezzed game jam</a> early in the year, and MonoGame at GameCraft. As a coder by trade I felt more comfortable with MonoGame, where Unity can get you a long way fast but it felt more designer orientated (not necessarily a bad thing).</p> <p><a href="http://trelford.com/blog/image.axd?picture=24.jpg"><img title="@ptrelford @qmcoetzee #theprismer on iPad from #gamecraft thanks #monogame!" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="@ptrelford @qmcoetzee #theprismer on iPad from #gamecraft thanks #monogame!" src="http://trelford.com/blog/image.axd?picture=24_thumb.jpg" width="244" height="184" /></a> </p> <p>Check out Neil’s article on <a href="http://neildanson.wordpress.com/2013/08/13/f-and-monogame-part-4-content-pipeline/">F# and Monogame Part 4 – Content Pipeline</a></p> <p><strong>F#</strong></p> <p>At a recent <a href="http://www.quakecon.org/wp-content/plugins/age-verification/age-verification.php?redirect_to=http://www.quakecon.org%2F">QuakeCon</a> conference veteran game developer John Carmack spent a chunk of his annual <a href="http://youtu.be/1PhArSujR_A">monologue</a> extolling the virtues of functional programming. F# is a rich functional-first programming language with excellent imperative and OO features when you need them. The experience is similar to the <a href="http://www.lua.org/">Lua</a> programming language, which is hugely popular in gaming, with it’s light syntax and all important <a href="http://en.wikipedia.org/wiki/Coroutine#Common_uses">coroutine</a> support. Given that it can run cross platform I think it’s an interesting choice for Indie games development. The XBLA title <a href="http://research.microsoft.com/en-us/projects/pathofgo/">Path of Go</a> is a good example of what is possible. There’s also a book on F# game development <a href="http://www.amazon.co.uk/Friendly-Fun-game-programming-ebook/dp/B005HHYIWC/">Friendly F# (Fun with game programming)</a>.</p> <p><a href="http://trelford.com/blog/image.axd?picture=Path%20to%20Go.jpg"><img title="Path to Go" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="Path to Go" src="http://trelford.com/blog/image.axd?picture=Path%20to%20Go_thumb.jpg" width="244" height="139" /></a> </p> <p><strong>Code Samples</strong></p> <p><a href="http://fssnip.net/ca">Berzerk</a> shows how to build a simple game AI using seq expressions:</p> <pre class="code"><span style="background: white; color: blue">let </span><span style="background: white; color: black">zombie target state = seq { </span><span style="background: white; color: blue">yield! </span><span style="background: white; color: black">random_pause state 10 </span><span style="background: white; color: blue">while true do yield! </span><span style="background: white; color: black">wait target state 50.0 </span><span style="background: white; color: blue">yield! </span><span style="background: white; color: black">home target state 10 }</span></pre> <a href="http://11011.net/software/vspaste"></a><font face="Lucida Sans Unicode"></font> <br/> <p>Flint Eastwood is a small game I built in 6 hours at the first <a href="http://trelford.com/blog/post/DubGamecraft.aspx">Dublin GameCraft</a> event:</p> <p><a href="http://trelford.com/blog/post/DubGamecraft.aspx"><img title="Flint Eastwood" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="Flint Eastwood" src="http://trelford.com/blog/image.axd?picture=Flint%20Eastwood.png" width="244" height="198" /></a> </p> <p><a href="http://trelford.com/blog/post/Balls.aspx">Balls</a> is a sound game, similar to Sound Drop I built last week:</p> <p><a href="http://trelford.com/blog/post/Balls.aspx"><img title="Tsunami Balls" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="Tsunami Balls" src="http://trelford.com/blog/image.axd?picture=Tsunami%20Balls_2.png" width="244" height="214" /></a> </p> <p>The Prismer is our entry to the <a href="http://gamecrafty.herokuapp.com/london-august-2013/the-prismer/">London GameCraft</a> game jam:</p> <p><a href="http://gamecrafty.herokuapp.com/london-august-2013/the-prismer/"><img title="ThePrismer" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="ThePrismer" src="http://trelford.com/blog/image.axd?picture=ThePrismer.jpg" width="244" height="139" /></a> </p> <p><strong>New York, New York</strong></p> <p>If you’re interested in learning more about F# check out the <a href="http://skillsmatter.com/event/scala/progressive-f-tutorials-nyc">Progressive F# Tutorials</a> on 18th/19th in New York followed by a <a href="http://skillsmatter.com/event/java-jee/new-york-gamecraft">GameCraft</a> game jam on Friday the 20th.</p> <p><a href="http://skillsmatter.com/event/scala/progressive-f-tutorials-nyc"><img title="rev-progfsharpnyc-800x300px" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="rev-progfsharpnyc-800x300px" src="http://trelford.com/blog/image.axd?picture=rev-progfsharpnyc-800x300px_4.png" width="504" height="192" /></a></p>Fri, 30 Aug 2013 07:23:11 -0700http://theburningmonk.com/?p=2998http://theburningmonk.com/2013/08/mostly-erlang-episode-13/f#erlangmeMostly Erlang episode 13I was recently invited to chat to the Mostly Erlang podcast about F#, with co-host Bryan Hunter, Fred Hebert (author of the excellent Learn You Some Erlang for Great Good!) and fellow F# addict Phil Trelford (author of many popular F# libraries such as TickSpec, Mini Rx and Foq). It’s always nice to talk about [...]Fri, 30 Aug 2013 01:26:19 -0700http://tomasp.net/blog/2013/fsharp-new-yorkhttp://tomasp.net/blog/2013/fsharp-new-york/index.htmlf#Hello New York. Learn some F#!<img src="http://tomasp.net/blog/2013/fsharp-new-york/nyc.jpg" class="rdecor" title="I'm cheating a little - the photo is from my previous visit in April." style="margin-left:20px;margin-bottom:15px"/> <p>Exactly two weeks ago, I started a three month internship at BlueMountain Capital in New York. They have a <a href="http://techblog.bluemountaincapital.com/">technical blog</a> and should be well known to the F# community thanks to the <a href="https://github.com/BlueMountainCapital/FSharpRProvider">R type provider</a> which was written by Howard Mansell (<a href="https://twitter.com/hmansell">@hmansell</a>). I'll have the pleasure of working with Howard on some more open source data-science related tools for F# (and C#). I'll write more about these when we have something to share, but if you want to contribute and help us, join the Data and Machine Learning <a href="http://fsharp.org/technical-groups/">working group at F# Foundation</a>.</p> <p>Aside from my work, I'm also happy to get involved with the great F# community in New York! We already have some events planned - <strong>Progressive F# Tutorials</strong> and <strong>FastTrack to F#</strong> are scheduled for September 16.-19. so you can become an F# guru in 4 days :-). But I'm also happy to have a chat with anyone interested in F# and perhaps do a lunch time talk, if you need to convince your colleagues or boss that F# is a good choice.</p> Thu, 29 Aug 2013 13:02:06 -0700http://tomasp.net/blog/2013\fsharp-new-yorkhttp://tomasp.net/blog/2013/fsharp-new-york/index.htmlf#Hello New York. Learn some F#!<img src="http://tomasp.net/blog/2013/fsharp-new-york/nyc.jpg" class="rdecor" title="I'm cheating a little - the photo is from my previous visit in April." style="margin-left:20px;margin-bottom:15px"/> <p>Exactly two weeks ago, I started a three month internship at BlueMountain Capital in New York. They have a <a href="http://techblog.bluemountaincapital.com/">technical blog</a> and should be well known to the F# community thanks to the <a href="https://github.com/BlueMountainCapital/FSharpRProvider">R type provider</a> which was written by Howard Mansell (<a href="https://twitter.com/hmansell">@hmansell</a>). I'll have the pleasure of working with Howard on some more open source data-science related tools for F# (and C#). I'll write more about these when we have something to share, but if you want to contribute and help us, join the Data and Machine Learning <a href="http://fsharp.org/technical-groups/">working group at F# Foundation</a>.</p> <p>Aside from my work, I'm also happy to get involved with the great F# community in New York! We already have some events planned - <strong>Progressive F# Tutorials</strong> and <strong>FastTrack to F#</strong> are scheduled for September 16.-19. so you can become an F# guru in 4 days :-). But I'm also happy to have a chat with anyone interested in F# and perhaps do a lunch time talk, if you need to convince your colleagues or boss that F# is a good choice.</p> Thu, 29 Aug 2013 13:02:06 -0700http://beautifulfsharp.wordpress.com/?p=46http://beautifulfsharp.wordpress.com/2013/08/28/progressive-f-tutorials-teaser/f#Progressive F# Tutorials TeaserA big F# community event is coming to NYC on September 18-19 &#8211; Progressive F# Tutorials. Jack Pappas and me are doing Code Quotations tutorial in advanced track. I want to do my share of promoting this great event. Here is something that might get you interested. Code Quotations is an advanced and powerful tool. [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=beautifulfsharp.wordpress.com&#038;blog=38164354&#038;post=46&#038;subd=beautifulfsharp&#038;ref=&#038;feed=1" width="1" height="1" />Wed, 28 Aug 2013 21:28:05 -0700