<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: A Refactoring: Explicit Modeling And Reducing Duplication</title>
	<atom:link href="http://lostechies.com/derickbailey/2010/09/25/a-refactoring-explicit-modeling-and-reducing-duplication/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/derickbailey/2010/09/25/a-refactoring-explicit-modeling-and-reducing-duplication/</link>
	<description>Better Than Yesterday</description>
	<lastBuildDate>Thu, 13 Jun 2013 17:35:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<item>
		<title>By: Augi</title>
		<link>http://lostechies.com/derickbailey/2010/09/25/a-refactoring-explicit-modeling-and-reducing-duplication/#comment-1181</link>
		<dc:creator>Augi</dc:creator>
		<pubDate>Thu, 30 Sep 2010 06:52:28 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2010/09/24/a-refactoring-explicit-modeling-and-reducing-duplication.aspx#comment-1181</guid>
		<description>The first code example can be easily cleaned using null-coalescing operator:

return GuardClause1(something) ?? GuardClause2(whatever) ?? Step1(whoCares) ?? Step2(doesntMatter);

The solution you proposed in &quot;Reducing Duplication&quot; paragraph is actually well known as Template Method pattern: http://en.wikipedia.org/wiki/Template_method_pattern</description>
		<content:encoded><![CDATA[<p>The first code example can be easily cleaned using null-coalescing operator:</p>
<p>return GuardClause1(something) ?? GuardClause2(whatever) ?? Step1(whoCares) ?? Step2(doesntMatter);</p>
<p>The solution you proposed in &#8220;Reducing Duplication&#8221; paragraph is actually well known as Template Method pattern: <a href="http://en.wikipedia.org/wiki/Template_method_pattern" rel="nofollow">http://en.wikipedia.org/wiki/Template_method_pattern</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: derick.bailey</title>
		<link>http://lostechies.com/derickbailey/2010/09/25/a-refactoring-explicit-modeling-and-reducing-duplication/#comment-1180</link>
		<dc:creator>derick.bailey</dc:creator>
		<pubDate>Thu, 30 Sep 2010 03:10:26 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2010/09/24/a-refactoring-explicit-modeling-and-reducing-duplication.aspx#comment-1180</guid>
		<description>@Michael and @Mike Murray

I&#039;ve been reading up on monads and have put together some examples to try and learn about them, specifically with Maybe&lt;T&gt; - your article was VERY helpful, Mike Murray...thank you for the link!

i can certainly see how the Maybe monad would be an option for the original code... however, I don&#039;t think it would be the best option. i think a monad, in general, though, could create a potentially more elegant solution - just not the Maybe monad. 

Assuming my understanding of monads is correct (see my monads post that i just put up), I&#039;ll be posting what I think is a better monadic solution that still accounts for everything I want from explicit modelling, etc, in this post. :)</description>
		<content:encoded><![CDATA[<p>@Michael and @Mike Murray</p>
<p>I&#8217;ve been reading up on monads and have put together some examples to try and learn about them, specifically with Maybe<t> &#8211; your article was VERY helpful, Mike Murray&#8230;thank you for the link!</p>
<p>i can certainly see how the Maybe monad would be an option for the original code&#8230; however, I don&#8217;t think it would be the best option. i think a monad, in general, though, could create a potentially more elegant solution &#8211; just not the Maybe monad. </p>
<p>Assuming my understanding of monads is correct (see my monads post that i just put up), I&#8217;ll be posting what I think is a better monadic solution that still accounts for everything I want from explicit modelling, etc, in this post. :)</t></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Murray</title>
		<link>http://lostechies.com/derickbailey/2010/09/25/a-refactoring-explicit-modeling-and-reducing-duplication/#comment-1179</link>
		<dc:creator>Mike Murray</dc:creator>
		<pubDate>Wed, 29 Sep 2010 16:06:14 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2010/09/24/a-refactoring-explicit-modeling-and-reducing-duplication.aspx#comment-1179</guid>
		<description>My first thought when looking at the code was also to perhaps utilize the Maybe Monad.  I&#039;ve been looking into that recently, and blogged about it:  http://murrayon.net/2010/09/maybe-from-murray-monads.html

I will have a follow up blog post by the end of the week with a link to a different Monad library that I put together instead of the one I introduced in the above linked to blog post.</description>
		<content:encoded><![CDATA[<p>My first thought when looking at the code was also to perhaps utilize the Maybe Monad.  I&#8217;ve been looking into that recently, and blogged about it:  <a href="http://murrayon.net/2010/09/maybe-from-murray-monads.html" rel="nofollow">http://murrayon.net/2010/09/maybe-from-murray-monads.html</a></p>
<p>I will have a follow up blog post by the end of the week with a link to a different Monad library that I put together instead of the one I introduced in the above linked to blog post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Clarke</title>
		<link>http://lostechies.com/derickbailey/2010/09/25/a-refactoring-explicit-modeling-and-reducing-duplication/#comment-1178</link>
		<dc:creator>David Clarke</dc:creator>
		<pubDate>Wed, 29 Sep 2010 01:11:35 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2010/09/24/a-refactoring-explicit-modeling-and-reducing-duplication.aspx#comment-1178</guid>
		<description>To me a guard clause is the Release version equivalent of an Assert. A guard clause says if one of my inputs is not valid then I cannot continue and should either return an error or throw an exception. Maybe I&#039;m misinterpreting your example code but to me your method lacks cohesion and instead of refactoring to have actual guard clauses and higher cohesion with (apart from the guard clause returns) a single return you have instead used artifice via a func to give the appearance of a single return. Just saying.</description>
		<content:encoded><![CDATA[<p>To me a guard clause is the Release version equivalent of an Assert. A guard clause says if one of my inputs is not valid then I cannot continue and should either return an error or throw an exception. Maybe I&#8217;m misinterpreting your example code but to me your method lacks cohesion and instead of refactoring to have actual guard clauses and higher cohesion with (apart from the guard clause returns) a single return you have instead used artifice via a func to give the appearance of a single return. Just saying.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: derick.bailey</title>
		<link>http://lostechies.com/derickbailey/2010/09/25/a-refactoring-explicit-modeling-and-reducing-duplication/#comment-1177</link>
		<dc:creator>derick.bailey</dc:creator>
		<pubDate>Mon, 27 Sep 2010 15:22:20 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2010/09/24/a-refactoring-explicit-modeling-and-reducing-duplication.aspx#comment-1177</guid>
		<description>@john - thanks! :)

i was 50/50 split on whether or not to do the one return statement change. in this simple case, it&#039;s not really a big deal either way. i decided to go with it just to make the point, but i wouldn&#039;t care either way if the code were really this small. 

i agree on early returns, when they are from guard clauses. otherwise, i try to keep the code small enough that an early return is not really needed. :)


@michael - i&#039;ve been reading more about monads and Maybe&lt;T&gt; and i&#039;m intrigued... 

i can see some potential value here, though i&#039;m not sure an &quot;Empty&quot; value is what i&#039;m looking for. i think the idea of a monad for piping these calls together is a potentially good idea, though. i&#039;m going to have to continue doing some reading and experimenting to really figure out this monad stuff in c#, and see if i can come up with a monad version of the solution. 

thanks for the suggestion! you&#039;ve given me something to obsess over and something new to learn, for a while :) </description>
		<content:encoded><![CDATA[<p>@john &#8211; thanks! :)</p>
<p>i was 50/50 split on whether or not to do the one return statement change. in this simple case, it&#8217;s not really a big deal either way. i decided to go with it just to make the point, but i wouldn&#8217;t care either way if the code were really this small. </p>
<p>i agree on early returns, when they are from guard clauses. otherwise, i try to keep the code small enough that an early return is not really needed. :)</p>
<p>@michael &#8211; i&#8217;ve been reading more about monads and Maybe<t> and i&#8217;m intrigued&#8230; </p>
<p>i can see some potential value here, though i&#8217;m not sure an &#8220;Empty&#8221; value is what i&#8217;m looking for. i think the idea of a monad for piping these calls together is a potentially good idea, though. i&#8217;m going to have to continue doing some reading and experimenting to really figure out this monad stuff in c#, and see if i can come up with a monad version of the solution. </p>
<p>thanks for the suggestion! you&#8217;ve given me something to obsess over and something new to learn, for a while :) </t></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Sonmez</title>
		<link>http://lostechies.com/derickbailey/2010/09/25/a-refactoring-explicit-modeling-and-reducing-duplication/#comment-1176</link>
		<dc:creator>John Sonmez</dc:creator>
		<pubDate>Mon, 27 Sep 2010 15:02:00 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2010/09/24/a-refactoring-explicit-modeling-and-reducing-duplication.aspx#comment-1176</guid>
		<description>Excellent post!

As soon as I saw the first part of the code, I was pretty sure you were going to go the Func&lt;&gt; way!

The only thing I disagree with is the one return refactor.  I am fan of early return.  Although, I do agree with you that many returns is a problem.

Nice refactor though, I see this kind of code many times and it is not immediately obvious how to refactor it.</description>
		<content:encoded><![CDATA[<p>Excellent post!</p>
<p>As soon as I saw the first part of the code, I was pretty sure you were going to go the Func<> way!</p>
<p>The only thing I disagree with is the one return refactor.  I am fan of early return.  Although, I do agree with you that many returns is a problem.</p>
<p>Nice refactor though, I see this kind of code many times and it is not immediately obvious how to refactor it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: derick.bailey</title>
		<link>http://lostechies.com/derickbailey/2010/09/25/a-refactoring-explicit-modeling-and-reducing-duplication/#comment-1175</link>
		<dc:creator>derick.bailey</dc:creator>
		<pubDate>Mon, 27 Sep 2010 00:57:08 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2010/09/24/a-refactoring-explicit-modeling-and-reducing-duplication.aspx#comment-1175</guid>
		<description>hmmm.... ok - i&#039;m pretty sure i did completely miss what you were trying to suggest. i&#039;m going to have to read up on monads in c# and see if this would be beneficial here... cause i think it might be fun, at least. :)</description>
		<content:encoded><![CDATA[<p>hmmm&#8230;. ok &#8211; i&#8217;m pretty sure i did completely miss what you were trying to suggest. i&#8217;m going to have to read up on monads in c# and see if this would be beneficial here&#8230; cause i think it might be fun, at least. :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: derick.bailey</title>
		<link>http://lostechies.com/derickbailey/2010/09/25/a-refactoring-explicit-modeling-and-reducing-duplication/#comment-1174</link>
		<dc:creator>derick.bailey</dc:creator>
		<pubDate>Mon, 27 Sep 2010 00:51:27 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2010/09/24/a-refactoring-explicit-modeling-and-reducing-duplication.aspx#comment-1174</guid>
		<description>michael - i haven&#039;t even heard of that, let alone tried it. :) is there a Maybe&lt;T&gt; built into .NET 4? we&#039;re still on .NET 3.5, but there seem to be plenty of articles on building a Maybe&lt;T&gt; implementation. 

from what i&#039;ve ready in the last 10 minutes, it looks like Maybe&lt;T&gt; is used often as a null-object pattern and/or a way to ensure that you never have null references in your code. I can certainly see the advantage of that, but in this case I don&#039;t think a null object pattern would model the result the way i want to see it. 

the core of the logic here, is &quot;if the step fails, return the result immediately, without processing any additional steps&quot;. by using a Maybe&lt;T&gt; we would have to change our if statement in ProcessSteps to &quot;if (result.HasValue)&quot; which does not tell me anything other than the object having a value or not. By modeling the result with a status and checking to see if that status equals a well known Error type (an enum in this case), I know what the value means instead of only knowing whether or not there is a value and then having to implicitly understand what the presence of a value indicates.

... or did i completely misunderstand your suggestion? Feel free to share some code on how you would recommend using this (post the code on Pastie.org or another site like that, and link to it here in the comments). I&#039;d love to understand what you&#039;re trying to say and see when / where this would be useful.</description>
		<content:encoded><![CDATA[<p>michael &#8211; i haven&#8217;t even heard of that, let alone tried it. :) is there a Maybe<t> built into .NET 4? we&#8217;re still on .NET 3.5, but there seem to be plenty of articles on building a Maybe</t><t> implementation. </p>
<p>from what i&#8217;ve ready in the last 10 minutes, it looks like Maybe</t><t> is used often as a null-object pattern and/or a way to ensure that you never have null references in your code. I can certainly see the advantage of that, but in this case I don&#8217;t think a null object pattern would model the result the way i want to see it. </p>
<p>the core of the logic here, is &#8220;if the step fails, return the result immediately, without processing any additional steps&#8221;. by using a Maybe</t><t> we would have to change our if statement in ProcessSteps to &#8220;if (result.HasValue)&#8221; which does not tell me anything other than the object having a value or not. By modeling the result with a status and checking to see if that status equals a well known Error type (an enum in this case), I know what the value means instead of only knowing whether or not there is a value and then having to implicitly understand what the presence of a value indicates.</p>
<p>&#8230; or did i completely misunderstand your suggestion? Feel free to share some code on how you would recommend using this (post the code on Pastie.org or another site like that, and link to it here in the comments). I&#8217;d love to understand what you&#8217;re trying to say and see when / where this would be useful.</t></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Chandler</title>
		<link>http://lostechies.com/derickbailey/2010/09/25/a-refactoring-explicit-modeling-and-reducing-duplication/#comment-1173</link>
		<dc:creator>Michael Chandler</dc:creator>
		<pubDate>Mon, 27 Sep 2010 00:03:26 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2010/09/24/a-refactoring-explicit-modeling-and-reducing-duplication.aspx#comment-1173</guid>
		<description>Did you try using the maybe monad?</description>
		<content:encoded><![CDATA[<p>Did you try using the maybe monad?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
