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

<channel>
	<title>{(something&#124;&#124;other).soft()} &#187; Development</title>
	<atom:link href="http://www.somethingorothersoft.com/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.somethingorothersoft.com</link>
	<description>About Software Development And Other Stuff By Igor Zevaka</description>
	<lastBuildDate>Fri, 18 Jun 2010 00:15:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Handling 404, unhandled and unsafe URL errors in ASP.NET MVC application</title>
		<link>http://www.somethingorothersoft.com/2010/06/18/handling-404-unhandled-and-unsafe-url-errors-in-asp-net-mvc-application/</link>
		<comments>http://www.somethingorothersoft.com/2010/06/18/handling-404-unhandled-and-unsafe-url-errors-in-asp-net-mvc-application/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 00:15:36 +0000</pubDate>
		<dc:creator>igor</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[asp.net-mvc]]></category>
		<category><![CDATA[csharp]]></category>

		<guid isPermaLink="false">http://www.somethingorothersoft.com/?p=411</guid>
		<description><![CDATA[Spent a bit of time recently to try and get my MVC application handle 404 errors exactly as I want. The solution that I ended up choosing is based on this excellent SO answer. The advantage of rendering the Error view by calling ErrorController.Execute, as opposed to making an entry in web.config, is that you <a href="http://www.somethingorothersoft.com/2010/06/18/handling-404-unhandled-and-unsafe-url-errors-in-asp-net-mvc-application/" rel="bookmark" title="Read on...">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Spent a bit of time recently to try and get my MVC application handle 404 errors exactly as I want. The solution that I ended up choosing is based on this excellent <a href="http://stackoverflow.com/questions/619895/how-can-i-properly-handle-404s-in-asp-net-mvc/2577095#2577095">SO answer</a>.</p>

<p>The advantage of rendering the Error view by calling <code>ErrorController.Execute</code>, as opposed to making an entry in web.config, is that you get to preserve the URL without a browser redirect.</p>

<p>If you think about which scenarios warrant a 404 response a more involved strategy is justifiable:</p>

<ol>
<li>Non-supported controller name &#8211; captured by <code>{controller}/{action}/{parameter}</code> rule.</li>
<li>Supported controller but bad action &#8211; captured by <code>Controller.HandleUnknownAction</code>.</li>
<li>Non-supported URL format &#8211; captured by the catch-all rule.</li>
</ol>

<p>Using <code>ErrorController.Execute</code> allows to preserve the URL for all of those scenarios. Now, to trap all unhandled exceptions in order to not show a Yellow Screen of Death, you would need to do some error handling in <code>Application.Error</code> event handler. Something similar is described in <a href="http://stackoverflow.com/questions/619895/how-can-i-properly-handle-404s-in-asp-net-mvc/620559#620559">this answer</a>.</p>

<p>There is a catch, however. If the anti-XSS features kick in and disallow a URL containing, say, angle brackets, executing error controller from global exception handler will throw an exception resulting in a YSOD.</p>

<p>The best solution i found was to catch the exception when doing <code>Execute</code> and do a browser redirect then. This prevents the runtime from creating a YSOD due to an unhandled exception in the exception event.</p>

<div>
<pre class="brush: csharp;">
IController errorController = ControllerBuilder.Current.GetControllerFactory().CreateController(null, &quot;error&quot;);
try {
    errorController.Execute(new RequestContext(
            contextBase, errorRoute));
} catch(Exception) {
    //If we are here it means that the URL is unsafe and the only way to handle it gracefully is to redirect.
    Response.Redirect(&quot;~/Error/BadRequest&quot;); //Controller/View pair that returns 400 - Bad Request
}

</pre>
</div>

<p>It&#8217;s probably not the best idea to handle 400 error as 404, hence we redirect to a &#8220;BadRequest&#8221; action in the <code>ErrorController</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.somethingorothersoft.com/2010/06/18/handling-404-unhandled-and-unsafe-url-errors-in-asp-net-mvc-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Keeping your sanity whilst developing for Windows Phone 7</title>
		<link>http://www.somethingorothersoft.com/2010/04/28/keeping-your-sanity-whilst-developing-for-windows-phone-7/</link>
		<comments>http://www.somethingorothersoft.com/2010/04/28/keeping-your-sanity-whilst-developing-for-windows-phone-7/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 23:04:18 +0000</pubDate>
		<dc:creator>igor</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[windows-phone-7]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://www.somethingorothersoft.com/?p=368</guid>
		<description><![CDATA[Dealing with those obtuse run-time errors whilst developing for WP7.

<img src="http://www.somethingorothersoft.com/wp-content/uploads/2010/04/frustration-300x299.jpg"/>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.somethingorothersoft.com/wp-content/uploads/2010/04/frustration-300x299.jpg"><img src="http://www.somethingorothersoft.com/wp-content/uploads/2010/04/frustration-300x299.jpg" alt="" title="frustration-300x299" width="300" height="299" class="alignnone size-full wp-image-380" /></a></p>

<p>Please note that this post is written in April 2010, when the WP7 SDK is only one month old. Most of the issues described here will likely not be a problem in later releases. The defining characteristic of such pre-release SDK is that when you are doing the right thing, everything is OK. When you screw up, it just goes KABOOM! without much explanation.</p>

<p>I spent a few hours of trying to work out why I am getting these run-time errors and so I&#8217;ve put together a list of the most painful ones, enjoy.</p>

<h2>Using <code>{x:Static ...}</code> Syntax</h2>

<p><strong>Problem:</strong> <code>{x:Static ...}</code> is not supported in Silverlight.</p>

<p>If you to do something like this:</p>

<div><pre class="brush: xml;">
&lt;DiscreteObjectKeyFrame  KeyTime=&quot;00:00:00&quot; Value=&quot;{x:Static Visibility.Collapsed}&quot;&gt;
</pre></div>

<p>You will get an obtuse error at runtime:</p>

<p><pre>
A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in System.Windows.dll
Additional information: 2024 An error has occurred. [Line: 114 Position: 61]
</pre></p>

<p>Get used to seeing that error. It&#8217;ll happen every time you screw up the XAML. Sometimes it&#8217;s more helpful than other times and you get the line number of the offending XAML. The line number, along with the exception text will be available in the Output window:</p>

<p><a href="http://www.somethingorothersoft.com/wp-content/uploads/2010/04/crash1.png"><img src="http://www.somethingorothersoft.com/wp-content/uploads/2010/04/crash1-1024x611.png" alt="" title="crash1" width="450" height="268" class="alignnone size-large wp-image-369" /></a></p>

<p>If you are like me and rarely look at the error window, perhaps you should start now. This particular error doesn&#8217;t raise a warning during compilation, but does come up as an error when the file is open in the editor:</p>

<p><a href="http://www.somethingorothersoft.com/wp-content/uploads/2010/04/xaml_error.png"><img src="http://www.somethingorothersoft.com/wp-content/uploads/2010/04/xaml_error.png" alt="" title="xaml_error" width="641" height="262" class="alignnone size-full wp-image-370" /></a></p>

<p><strong>Solution:</strong> Don&#8217;t use <code>x:Static</code> but instead an instance of a type in XAML like so:</p>

<div><pre class="brush: xml;">
    &lt;DiscreteObjectKeyFrame  KeyTime=&quot;00:00:00&quot;&gt;
        &lt;DiscreteObjectKeyFrame.Value&gt;
            &lt;Visibility&gt;Collapsed&lt;/Visibility&gt;
        &lt;/DiscreteObjectKeyFrame.Value&gt;
    &lt;/DiscreteObjectKeyFrame&gt;
</pre></div>

<h2>Misspelling Animation Element or Property Name</h2>

<p><strong>Problem:</strong> Misspelling Animation Element or Property Name</p>

<p>In the below code <code>Storyboard.TargetName</code> is invalid. The project compiles and there are no errors in the error window.</p>

<div><pre class="brush: xml;">
    &lt;ObjectAnimationUsingKeyFrames Storyboard.TargetName=&quot;SearchBoxMisspelled&quot; Storyboard.TargetProperty=&quot;Visibility&quot;&gt;
        &lt;!--animation key frames--&gt;
    &lt;/ObjectAnimationUsingKeyFrames&gt;
</pre></div>

<p>At run-time, you get this error message:</p>

<p><pre>
A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.dll
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.dll
Additional information: 2213 An error has occurred.
</pre></p>

<p>The call stack only tells you that this is something to do with the animation:</p>

<p><pre>
System.Windows.dll!MS.Internal.XcpImports.MethodEx(System.IntPtr ptr = 146517008, string name = "Begin", MS.Internal.CValue[] cvData = null) + 0x9d bytes
System.Windows.dll!MS.Internal.XcpImports.MethodEx(System.Windows.DependencyObject obj = {System.Windows.Media.Animation.Storyboard}, string name = "Begin") + 0x6 bytes<br />
System.Windows.dll!MS.Internal.XcpImports.Storyboard_Begin(System.Windows.Media.Animation.Storyboard storyboard = {System.Windows.Media.Animation.Storyboard})
System.Windows.dll!System.Windows.Media.Animation.Storyboard.Begin() + 0x6 bytes
</pre></p>

<p><strong>Solution:</strong> To resolve this, check your animation element and property names. Unfortunately I haven&#8217;t found a way to get at the offending animation frame from the call stack. Would be happy to find out if there is a way.</p>

<h2>References&#8217; Dependencies</h2>

<p><strong>Problem:</strong> &#8220;Object reference is not set to an instance of an object&#8221; error when debugging and crashes when running without debugger.</p>

<p>After adding a reference library you might start getting this error when you debug the project:</p>

<p><a href="http://www.somethingorothersoft.com/wp-content/uploads/2010/04/error_debugging.png"><img src="http://www.somethingorothersoft.com/wp-content/uploads/2010/04/error_debugging.png" alt="" title="error_debugging" width="391" height="171" class="alignnone size-full wp-image-371" /></a></p>

<p>This is caused, as far as I can tell, by your references&#8217; dependencies not being copied to the device. After hours of playing around with this it&#8217;s apparent to me that this is an intermittent issue with Visual Studio. It is supposed to work out what all the references&#8217; dependencies are, copy them to the output folder and add them to the manifest file (<code>$(OutputDir)\AppManifest.xaml</code>).</p>

<p>Sometimes that doesn&#8217;t happen and the app gets deployed without those dependencies. It will still work, up until the point where a class is referenced from a dependant assembly and that assembly cannot be loaded. I expect this problem to go away in later releases of WP7 SDK.</p>

<p>The error will look something like this:</p>

<p><a href="http://www.somethingorothersoft.com/wp-content/uploads/2010/04/runtime_error.png"><img src="http://www.somethingorothersoft.com/wp-content/uploads/2010/04/runtime_error.png" alt="" title="runtime_error" width="396" height="772" class="alignnone size-full wp-image-372" /></a></p>

<p><pre>
2024 An error has occurred[Line: <line> Position: <position>]
at
System.Windows.Application.LoadComponent
...Rest of the callstack.
</pre></p>

<p><strong>Solution:</strong> Add all the assembiles that your references depend upon as references to the project.
<strong>Edit:</strong> This error kept happening to me until my coworker pointed out the solution, which led to the &#8220;Doh moment of the week.&#8221;
<strong>Solution2:</strong> When debugging the project <strong>select the project in the solution pane and press F5</strong>. Yeah, that simple.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.somethingorothersoft.com/2010/04/28/keeping-your-sanity-whilst-developing-for-windows-phone-7/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>F# &#8211; Combinators And Tail Recursion</title>
		<link>http://www.somethingorothersoft.com/2010/03/01/f-combinators-and-tail-recursion/</link>
		<comments>http://www.somethingorothersoft.com/2010/03/01/f-combinators-and-tail-recursion/#comments</comments>
		<pubDate>Sun, 28 Feb 2010 21:37:08 +0000</pubDate>
		<dc:creator>igor</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[f#]]></category>

		<guid isPermaLink="false">http://www.somethingorothersoft.com/?p=312</guid>
		<description><![CDATA[Perhaps combinators and tail recursion are not the best beginner topics in F# but they are the ones I got stuck into pretty much straight away. I blame Google. After reading a few google hits on functional programming I of course found out about combinators and I just had to understand them. I finally got <a href="http://www.somethingorothersoft.com/2010/03/01/f-combinators-and-tail-recursion/" rel="bookmark" title="Read on...">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Perhaps combinators and tail recursion are not the best beginner topics in F# but they are the ones I got stuck into pretty much straight away. I blame Google. After reading a few google hits on functional programming I of course found out about combinators and I just had to understand them.</p>

<p>I finally got it but it took a while. The issue, particularly in F#, is that combinators don&#8217;t make all that much sense as a substitute for non-recursive functions. After all, the only way to run the combinator recursively is with a recursive function (as in <code>let rec</code>). A different solution might be to use recursive types, but that&#8217;s is pretty pointless. There was a great <a href="http://stackoverflow.com/questions/1998407/how-do-i-define-y-combinator-without-let-rec">StackOverflow question</a> about that by the way.</p>

<h3>What is a combinator</h3>

<p>I am getting ahead of myself though. Combinators are a mathematical concept pioneered by Haskell Curry. The essence of combinators is that they allow sophisticated computation by combining simple functions. Hence the term combinator. Combinators allow a recursive algorithm to be written using a function that does not call itself but instead invokes another function that is passed in as one of the arguments.</p>

<p>One distinct characteristic of a combinator function is that all of its variables are bound. That means that the function only depends on its parameters, not any other data structures or function defined elsewhere. Just about the best description of what is a combinator and what isn&#8217;t can be found <a href="http://mvanier.livejournal.com/2897.html">here</a></p>

<div>
<pre class="brush: fsharp;">
let freevar=3 //a variable

let IAmACombinator x = x*2;; //variable x is bound as a formal parameter
let IAmNotACombinator x = x*y;; x is bound but y is free. This is not a combinator
</pre>
</div>

<h3>Example</h3>

<p>Lets do some examples. An algorithm that I will implement is the sum of arithmetic  progression. It&#8217;s an algorithm that can really be solved in O(1) time (by using the formula (m+n)*(m-n+1)/2, but it makes for good tail recursion test (i.e. you can blow the stack quite easily, unlike the factorial, which runs out of the integer range at about 15).</p>

<p>This is the normal recursive arithmetic progression function:</p>

<div>
<pre class="brush: fsharp;">
let rec progsum x =  
    if x &lt;= 1 then 1 
    else x+progsum (x-1)
</pre>
</div>

<h3>Combinator Version</h3>

<p>Thanks to F# type inference, the  combinator function is pretty the same for any application and only depends on the number of parameters to the worker function.</p>

<p>This is the combinator version of the above function:</p>

<div>
<pre class="brush: fsharp;">
//Normal arithmentic progression sum combinator
let rec comb f = f (fun x -&gt; comb f x)
let progworker f x = 
    if x &lt;= 1 then 1 
    else x+f(x-1)
//Use partial application to wrap up the combinator call    
let progCombinator x = comb progworker x ;;
</pre>
</div>

<p>This might need a bit of explaining. <code>comb</code> is a higher order function that takes another function as a parameter and returns a function taking one argument. This returned function is what we actually want &#8211; a function taking one parameter and returning something of the same type as the parameter.</p>

<p>In the above snippet <code>progCombinator</code> is a convenient way to partially apply our combinator to the arithmetic progression worker function. We could have just as easily done for a factorial:</p>

<div>
<pre class="brush: fsharp;">
let factworker f x = 
    if x &lt;= 1 then 1
    else f(x-1) * x;;
//Use partial application to wrap up the combinator call    
let factCombinator x = comb factworker x ;;
</pre>
</div>

<h3>Tail recursion</h3>

<p><em>Tail Call Optimization</em> is an F# compiler feature (and in some cases <a href="http://blogs.msdn.com/jomo_fisher/archive/2007/09/19/adventures-in-f-tail-recursion-in-three-languages.aspx">JIT Compiler feature</a>) where it will transform a recursive function into a while loop if the recursive call is the last statement in the function. Let&#8217;s go back to the original arithmetic progression function and see if that is the case:</p>

<div>
<pre class="brush: fsharp;">
let rec progsum x =  
    if x &lt;= 1 then 1 
    else x+progsum(x-1)
</pre>
</div>

<p>And it isn&#8217;t. Even though it looks like the function call is the last statement of the function, <code>progsum(x+1)</code>  will be evaluated before <code>x+progsum(x+1)</code> can be computed. Let&#8217;s rewrite it to take advantage of tail recursion:</p>

<div>
<pre class="brush: fsharp;">
let progTR x =  
    let rec inner x sum = 
        if x &lt;= 1 then sum 
        else inner (x-1) (sum + x)
    inner x 1;;
</pre>
</div>

<p>So, what happened here? Well, for once we declared a wrapper function and the worker function inside it. This is not strictly necessary, but allows to hide some of the implementation semantics. So, if we can visualize how the original function worked, this is a crude diagram that shows the execution path for <code>x = 4</code>:</p>

<p><pre>
progsum 4
->calls progsum 3
  ->calls progsum 2
    ->calls progsum 1
       ->returns 1
    <-returns (progsum 1) + 2
  <-returns (progsum 2) + 3
<-returns (progsum 3) + 4
</pre></p>

<p>As you can see the result is computed "on the way out" - i.e. as the function returns. In the tail recursive version we compute the result "on the way in", which allows the recursive function invocation to be the last statement in the function. Here is the diagram:</p>

<p><pre>
inner 4 1
->calls inner 3 (1 + 4)
  ->calls inner 2 (5 + 3)
    ->calls inner 1 (8 + 2)
      -> returns 10
    <-returns 10
  <-returns 10
<-returns 10
</pre></p>

<p>An interesting side effect of this tail recursive function is the fact that the order in which sum happens is not quite the same as in the original function.</p>

<p>Original:</p>

<p><pre>
4 + (3 + (2 +(1)))
</pre></p>

<p>Tail Recursive:</p>

<p><pre>
((4 + 1) + 3) + 2
</pre></p>

<h3>Tail Recursive Combinator</h3>

<p>So, now that we've gone over combinator functions and tail recursive functions you may ask: "What about tail recursive combinators? Do those exist?". And the answer would be "Yes, indeed, such beasts do exist". Here is the same algorithm implemented as a tail recursive combinator:</p>

<div>
<pre class="brush: fsharp;">
let rec combTR f = f (fun x acc -&gt; combTR f x acc)
let progTR f x acc = 
    match x with
    | 1 -&gt; acc
    | x -&gt; f(x-1) (acc + x);;
    
let progCombTR x = combTR progTR x 1;;
</pre>
</div>

<p>Looking at the code, there is nothing groundbreaking there. Just as we converted the original function into a tail recursive function by adding a second parameter, we did the same for the both the combinator function and the inner function.</p>

<p>For more details on tail recursion and different ways to optimise it have a look <a href="http://thevalerios.net/matt/2009/01/recursion-in-f-and-the-tail-recursion-police/">here</a> and <a href="http://blogs.msdn.com/jomo_fisher/archive/2007/09/19/adventures-in-f-tail-recursion-in-three-languages.aspx">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.somethingorothersoft.com/2010/03/01/f-combinators-and-tail-recursion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Double dispatch without RTTI</title>
		<link>http://www.somethingorothersoft.com/2010/02/01/double-dispatch-without-rtti/</link>
		<comments>http://www.somethingorothersoft.com/2010/02/01/double-dispatch-without-rtti/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 22:15:16 +0000</pubDate>
		<dc:creator>igor</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[c++]]></category>

		<guid isPermaLink="false">http://www.somethingorothersoft.com/?p=230</guid>
		<description><![CDATA[I liked my StackOverflow answer so much that I decided to make it into a blog post. The question was how to implement a double dispatch mechanism for subclasses of one base class without casting. After dismissing the question as stupid, I spent a bit of time trying to come up with a solution that <a href="http://www.somethingorothersoft.com/2010/02/01/double-dispatch-without-rtti/" rel="bookmark" title="Read on...">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>I liked my <a href="http://stackoverflow.com/questions/2159496/c-problem-with-function-overloading/2159524#2159524">StackOverflow answer</a> so much that I decided to make it into a blog post. The question was how to implement a double dispatch mechanism for subclasses of one base class without casting. After dismissing the question as stupid, I spent a bit of time trying to come up with a solution that didn&#8217;t rely on <code>dynamic_cast</code>. The solution is pretty pointless as it&#8217;s pretty confusing and might be slower than RTTI solution due to an extra function call. It was largely inspired by wikipedia article on double dispatch found <a href="http://en.wikipedia.org/wiki/Double_dispatch">here</a>.</p>

<p>So the trick to get this working as pointed out in the article was to call the function on the pointer or reference of the parameter to the original function, thus cauising a second dispatch.</p>

<div class="foo">
<pre class="brush: cpp;">
class A {
  virtual void PublicFunction(B&amp; b) {
    b.PerformFunction(*this);
  }
}
</pre>
</div>

<p>The problem with doing this sort of thing with subclasses of the same base is that we need to allow the possibility of the base class being called with one of its subclasses as a parameter. Luckily we can use forward declarations to define the functions and implement them later on.</p>

<div class="foo">
<pre class="brush: cpp;">
class b;
class c;
class a {
protected:
    virtual void doFoobar(a&amp; a2); //do stuff here 
    virtual void doFoobar(b&amp; b2); //delegate to b
    virtual void doFoobar(c&amp; c2); //delegate to c
public:
    virtual void foobar(a&amp; a2) {
        a2.doFoobar(*this);
    }
    friend class b;
    friend class c;
};
class b : public a {
protected:
    virtual void doFoobar(a&amp; a2); //do stuff here 
    virtual void doFoobar(b&amp; b2); //do stuff here
    virtual void doFoobar(c&amp; c2); //delegate to c
public:
    virtual void foobar(a&amp; a2) {
        a2.doFoobar(*this);
    }
    friend class a;
};
class c : public b {
protected:
    virtual void doFoobar(a&amp; a2); //do stuff here 
    virtual void doFoobar(b&amp; b2); //do stuff here
    virtual void doFoobar(c&amp; c2); //delegate to c
public:
    virtual void foobar(a&amp; a2) {
        a2.doFoobar(*this);
    }
    friend class a;
    friend class b;
};
//class a
void a::doFoobar(a&amp; a2)  {
    printf(&quot;Doing a&lt;-&gt;a\n&quot;);
}
void a::doFoobar(b&amp; b2)  {
    b2.doFoobar(*this);
}
void a::doFoobar(c&amp; c2)  {
    c2.doFoobar(*this);
}
//class b
void b::doFoobar(a&amp; a2)  {
    printf(&quot;Doing b&lt;-&gt;a\n&quot;);
}
void b::doFoobar(b&amp; b2)  {
    printf(&quot;Doing b&lt;-&gt;b\n&quot;);
}
void b::doFoobar(c&amp; c2)  {
    c2.doFoobar(*this);
}
//class c
void c::doFoobar(a&amp; a2)  {
    printf(&quot;Doing c&lt;-&gt;a\n&quot;);
}
void c::doFoobar(b&amp; b2)  {
    printf(&quot;Doing c&lt;-&gt;b\n&quot;);
}
void c::doFoobar(c&amp; c2)  {
    printf(&quot;Doing c&lt;-&gt;c\n&quot;);
}
</pre>
</div>

<p>The code is far from an ideal double dispatch solution as it relies on the forward declaration trick to resolve the circular dependency between the subclasses. This means that all the classes that need to have this functionality must be known at compile-time (of the base class). This means the base class cannot be made into a library component.</p>

<p>To explain all the friend declarations. Considering the fact that all the classes <code>a</code>, <code>b</code> and <code>c</code> are tightly coupled as is, I added friend declarations so that the actual worker function is private and cannot be called from the outside.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.somethingorothersoft.com/2010/02/01/double-dispatch-without-rtti/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>I have a new pet hate browser</title>
		<link>http://www.somethingorothersoft.com/2010/01/08/i-have-a-new-pet-hate-browser/</link>
		<comments>http://www.somethingorothersoft.com/2010/01/08/i-have-a-new-pet-hate-browser/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 04:04:32 +0000</pubDate>
		<dc:creator>igor</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[ie]]></category>

		<guid isPermaLink="false">http://www.somethingorothersoft.com/?p=181</guid>
		<description><![CDATA[Hating IE6 is so 2003. I hate Chrome now. Maybe I am biased. I only used Chrome to test a layout that has a lot of transparency. It&#8217;s quite well known that webkit sucks a bit handling RGBA. But I am getting ahead of myself. Everyone kept going on about how fast Chrome after it <a href="http://www.somethingorothersoft.com/2010/01/08/i-have-a-new-pet-hate-browser/" rel="bookmark" title="Read on...">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Hating IE6 is so 2003. I hate Chrome now. Maybe I am biased. I only used Chrome to test a layout that has a lot of transparency. It&#8217;s quite well known that webkit sucks a bit handling RGBA. But I am getting ahead of myself.</p>

<p>Everyone kept going on about how fast Chrome after it came out. My experience has been the opposite. A few months back every time I would start Chrome it would sit for half a minute, discovering proxy, I think. It hasn&#8217;t really altered my browsing experience once it got started. That was fixed a while back.</p>

<p>Now I have found more issues that actually make it the slower browser out of IE(!!!) and Firefox. Try browsing this site:</p>

<p><a href="24ways.org">24ways.org</a></p>

<p>Yeah. You can&#8217;t scroll for shit.</p>

<p>Fair enough, it&#8217;s a bug. That&#8217;s OK, we all write bugs. I would have completely not cared if not for yet another Chrome idiosynchrasy that just tipped me over the edge.</p>

<p>The layout that I am working on is largely inspired by 24ways.org, so it has a few semi-transparent elements, which of course don&#8217;t work in IE. As a workaround I am using one pixel PNGs with alpha channel. Supposedly this is the way to do it:</p>

<p><pre class="brush: css;">
.transparent {
  background: url(pngwithalpha.png);
  background: rgba(255,255,255,0.1);
}
</pre></p>

<p>What the browser is meant to do is to disregard the first <code>background</code> declaration and use the second if it supports RGBA colours. That&#8217;s what Firefox does&#8230; But no, Chrome loads those images anyway.</p>

<p>Fair enough, it has quirks. At least it would cache the images, right? <span style="font-size: x-large">WRONG!!!</span>. Unlike Firefox <strong>and</strong> IE, Chrome would request those image even though you don&#8217;t refresh the page. Both IE and Firefox, when you focus on the address bar and hit enter will retrieve the images from local cache. When you refresh, they would do an <code>If-Modified-Since</code> request. Chrome does an <code>If-Modified-Since</code> request regardless.</p>

<p>Actually, I lie. It doesn&#8217;t do the request regardless. It will do a status request for images that are visible straight away. If there is a background image that is in a <code>:hover</code> pseudo-class, it will retrieve that one from the local cache. Go figure.</p>

<p><a href="http://925html.com/code/rgba-ie-fallback/">Here</a> is an excellent and very detailed comparison of browser support for transparencies and pngs. Go Firefox!!!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.somethingorothersoft.com/2010/01/08/i-have-a-new-pet-hate-browser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shouldn&#8217;t RAII should be RDID???</title>
		<link>http://www.somethingorothersoft.com/2009/12/11/shouldnt-raii-should-be-rdid/</link>
		<comments>http://www.somethingorothersoft.com/2009/12/11/shouldnt-raii-should-be-rdid/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 12:16:27 +0000</pubDate>
		<dc:creator>igor</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[design-patterns]]></category>

		<guid isPermaLink="false">http://www.somethingorothersoft.com/?p=157</guid>
		<description><![CDATA[I will openly plead ignorance for design patterns. I know this is really not the way to be and Design Patterns and Code Complete are on my &#8220;to read&#8221; list. It&#8217;s only that I trawl through StackOverflow a bit lately that I get to hear a lot of buzz about patterns and idioms. Some people <a href="http://www.somethingorothersoft.com/2009/12/11/shouldnt-raii-should-be-rdid/" rel="bookmark" title="Read on...">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>I will openly plead ignorance for design patterns. I know this is really not the way to be and <em>Design Patterns</em> and <em>Code Complete</em> are on my &#8220;to read&#8221; list. It&#8217;s only that I trawl through StackOverflow a bit lately that I get to hear a lot of buzz about patterns and idioms. Some people get really obsessive about identifying the patterns and making sure they use the right one. But that&#8217;s not really the point of this post.</p>

<p>Most of the time I realize that a lot of those pattens is osmething that I have been doing for years without thinking. In fact this inspires me to go through &#8220;the list&#8221; of all the patterns and do a series of blog posts &#8211; <strong>&#8220;Design Patterns &#8211; What you have coded for years is actually an idiom &#8211; [insert design pattern here]&#8220;</strong>.</p>

<p>So, I only just recently found out that the practice of using smart pointers is officially called RAII &#8211; Resource Allocation Is Initialization. The  <a href="http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization">Wikipedia article</a> bangs on about ojects being allocated on the stack and exception safety, but in my opinion those considerations are not as significant as the magic of destruction.</p>

<p>The only way this works in C++ is due to deterministic destructors. The magic happens upon destruction, not upon initialization. Any garbage collected language can have Allocation on Initialization, but they can&#8217;t guarantee implicit destruction when going out of scope like C++ does.</p>

<p>I also think that that object scope (the fact that it should be on the stack) is somewhat peripheral again. The destructor will get called whenever you explicitly delete the object as well. Whilst this is not strictly automagic destruction, it can be &#8211; for example when using collections that are aware of element removal semantics. For example a collection might either call a Release method on a ref counted object or call operator delete on plain old pointer.</p>

<p>So this brings me back to the title of hte post &#8211; shouldn&#8217;t Resource Allocation Is Initialization be Resource Deallocation Is Destruction? That&#8217;s where the magic happens, right?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.somethingorothersoft.com/2009/12/11/shouldnt-raii-should-be-rdid/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Test Driven Development</title>
		<link>http://www.somethingorothersoft.com/2009/08/01/test-driven-development/</link>
		<comments>http://www.somethingorothersoft.com/2009/08/01/test-driven-development/#comments</comments>
		<pubDate>Sat, 01 Aug 2009 05:14:20 +0000</pubDate>
		<dc:creator>igor</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://www.somethingorothersoft.com/?p=37</guid>
		<description><![CDATA[I heard a lot of buzz about test driven development. All that time I thought that all that means is writing unit tests. Then I found out about writing tests before writing code. Meh, I thought, no big deal, a bit fussy if you ask me, it still hasn&#8217;t changed my view on the whole <a href="http://www.somethingorothersoft.com/2009/08/01/test-driven-development/" rel="bookmark" title="Read on...">[...]</a>]]></description>
			<content:encoded><![CDATA[<p>I heard a lot of buzz about test driven development. All that time I thought that all that means is writing unit tests. Then I found out about writing tests before writing code. Meh, I thought, no big deal, a bit fussy if you ask me, it still hasn&#8217;t changed my view on the whole thing.</p>

<p>Then recently I saw some unit tests in a Microsoft article talking about using TDD to create web controls using Model-View-Presenter paradigm. The article itself can be found here <a href="http://msdn.microsoft.com/en-us/magazine/cc188690.aspx">http://msdn.microsoft.com/en-us/magazine/cc188690.aspx</a>.</p>

<p>Its crazy! You write twice as much code! Not only that, you have to use this framework to create mock objects and test methods on the interfaces before even writing them (tests before code, doh).</p>

<p>Having said that, I am willing to give TDD for really just one reason. And the reason is that writing tests that independently test the two halves (e.g. View and Presenter) makes you think upfront about the design of the two interfaces a bit more. This, in turn, precipitates the right design faster, without having to write a lot of either UI or business logic code.</p>

<p>The long  term advantage is quite obvious and is comes from both Separation Of Concerns principles (whatever shape they come in &#8211; MVP, MVC, MVV, MVA) and having unit tests. In some time, if there is a need to rewrite the implementation of any part of the system, the interfaces between them are loosely coupled and testable. The latter, in my opinion, is even more important than the former. Having a testable interface will aid finding the problems in the new implementation more than a &#8220;beautifully&#8221; designed one.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.somethingorothersoft.com/2009/08/01/test-driven-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
