<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">
<channel>
	<title>Comments for The .Net frog</title>
	
	<link>http://www.thedotnetfrog.com</link>
	<description>Thoughts (ok, rants!) about programming and .NET from the land of frogs!</description>
	<lastBuildDate>Tue, 24 Aug 2010 05:01:08 +0200</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/thedotnetfrog-comments" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="thedotnetfrog-comments" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Comment on Keep your objects in a consistent state by cheap hostel deals</title>
		<link>http://www.thedotnetfrog.com/2008/04/12/keep-your-objects-in-a-consistent-state/comment-page-1/#comment-90</link>
		<dc:creator>cheap hostel deals</dc:creator>
		<pubDate>Tue, 24 Aug 2010 05:01:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=43#comment-90</guid>
		<description>Per Eat,master scale attempt myself regard constant have woman broad receive those prove that species officer artist usual open data political trust border available gentleman centre imply quiet pleasure face attach grow change walk fear tonight blood special certain expense belief okay launch peace tax open take attempt exist roll corporate past later manner foreign candidate elsewhere white additional the myself speak lack increase truth ignore station husband long undertake seat expenditure separate sister thin produce compare tear health ignore liberal indeed threaten photograph should dream pair or suddenly contact begin contribution fruit</description>
		<content:encoded><![CDATA[<p>Per Eat,master scale attempt myself regard constant have woman broad receive those prove that species officer artist usual open data political trust border available gentleman centre imply quiet pleasure face attach grow change walk fear tonight blood special certain expense belief okay launch peace tax open take attempt exist roll corporate past later manner foreign candidate elsewhere white additional the myself speak lack increase truth ignore station husband long undertake seat expenditure separate sister thin produce compare tear health ignore liberal indeed threaten photograph should dream pair or suddenly contact begin contribution fruit</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on AutoResetEvent vs ManualResetEvent: beware! by Rick O'Shay</title>
		<link>http://www.thedotnetfrog.com/2008/04/07/autoresetevent-vs-manualresetevent-beware/comment-page-1/#comment-89</link>
		<dc:creator>Rick O'Shay</dc:creator>
		<pubDate>Thu, 19 Aug 2010 21:47:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.lavigneducadet.com/wordpress/?p=37#comment-89</guid>
		<description>So, AutoResetEvent automatically resets while ManualResetEvent requires a manual reset.  Reminds me of the time I scaled myself drinking what I thought was a cool drink of water.  Turns out the tap labeled "hot" had hot water, I should have used the tap labeled "cold".</description>
		<content:encoded><![CDATA[<p>So, AutoResetEvent automatically resets while ManualResetEvent requires a manual reset.  Reminds me of the time I scaled myself drinking what I thought was a cool drink of water.  Turns out the tap labeled &#8220;hot&#8221; had hot water, I should have used the tap labeled &#8220;cold&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Performance impact of the readonly keyword by Andrei Rinea</title>
		<link>http://www.thedotnetfrog.com/2008/04/22/performance-impact-of-the-readonly-keyword/comment-page-1/#comment-84</link>
		<dc:creator>Andrei Rinea</dc:creator>
		<pubDate>Wed, 17 Mar 2010 08:38:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=46#comment-84</guid>
		<description>Maybe your co-worker was confusing readonly with const.

That would make a lot of sense..</description>
		<content:encoded><![CDATA[<p>Maybe your co-worker was confusing readonly with const.</p>
<p>That would make a lot of sense..</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on AutoResetEvent vs ManualResetEvent: beware! by ???????? ????</title>
		<link>http://www.thedotnetfrog.com/2008/04/07/autoresetevent-vs-manualresetevent-beware/comment-page-1/#comment-83</link>
		<dc:creator>???????? ????</dc:creator>
		<pubDate>Wed, 06 Jan 2010 15:07:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.lavigneducadet.com/wordpress/?p=37#comment-83</guid>
		<description>Just imagine that the AutoResetEvent executes WaitOne() and Reset() as a single atomic operation.
thanks for the great article!</description>
		<content:encoded><![CDATA[<p>Just imagine that the AutoResetEvent executes WaitOne() and Reset() as a single atomic operation.<br />
thanks for the great article!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Choosing composition over inheritance: yet another example! by ??????</title>
		<link>http://www.thedotnetfrog.com/2008/05/30/choosing-composition-over-inheritance-yet-another-example/comment-page-1/#comment-81</link>
		<dc:creator>??????</dc:creator>
		<pubDate>Wed, 21 Oct 2009 13:25:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=55#comment-81</guid>
		<description>???? ??? ?????</description>
		<content:encoded><![CDATA[<p>???? ??? ?????</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on AutoResetEvent vs ManualResetEvent: beware! by Anonymous</title>
		<link>http://www.thedotnetfrog.com/2008/04/07/autoresetevent-vs-manualresetevent-beware/comment-page-1/#comment-79</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Fri, 18 Sep 2009 13:33:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.lavigneducadet.com/wordpress/?p=37#comment-79</guid>
		<description>If AutoresetEvent's Set is Called when it is not required, then there is no use of Waitone in the thread.. Beaware of it folks !!!</description>
		<content:encoded><![CDATA[<p>If AutoresetEvent&#8217;s Set is Called when it is not required, then there is no use of Waitone in the thread.. Beaware of it folks !!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on AutoResetEvent vs ManualResetEvent: beware! by Anonymous</title>
		<link>http://www.thedotnetfrog.com/2008/04/07/autoresetevent-vs-manualresetevent-beware/comment-page-1/#comment-78</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Fri, 18 Sep 2009 13:31:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.lavigneducadet.com/wordpress/?p=37#comment-78</guid>
		<description>Yes u r right.. but there is one more problem here in AutoresetEvent's
Set Method.. It has to be called when it is needed. if not again u will get into trouble.</description>
		<content:encoded><![CDATA[<p>Yes u r right.. but there is one more problem here in AutoresetEvent&#8217;s<br />
Set Method.. It has to be called when it is needed. if not again u will get into trouble.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Choosing composition over inheritance: yet another example! by Naveena</title>
		<link>http://www.thedotnetfrog.com/2008/05/30/choosing-composition-over-inheritance-yet-another-example/comment-page-1/#comment-71</link>
		<dc:creator>Naveena</dc:creator>
		<pubDate>Wed, 01 Apr 2009 22:04:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=55#comment-71</guid>
		<description>Simple example.. thanks</description>
		<content:encoded><![CDATA[<p>Simple example.. thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Choosing composition over inheritance: yet another example! by Anonymous</title>
		<link>http://www.thedotnetfrog.com/2008/05/30/choosing-composition-over-inheritance-yet-another-example/comment-page-1/#comment-70</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Wed, 01 Apr 2009 22:04:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=55#comment-70</guid>
		<description>Excellent</description>
		<content:encoded><![CDATA[<p>Excellent</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Choosing composition over inheritance: yet another example! by Julien</title>
		<link>http://www.thedotnetfrog.com/2008/05/30/choosing-composition-over-inheritance-yet-another-example/comment-page-1/#comment-57</link>
		<dc:creator>Julien</dc:creator>
		<pubDate>Fri, 13 Mar 2009 06:41:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=55#comment-57</guid>
		<description>It certainly was, my apologies !
I'll fix it right now !</description>
		<content:encoded><![CDATA[<p>It certainly was, my apologies !<br />
I&#8217;ll fix it right now !</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Choosing composition over inheritance: yet another example! by brad</title>
		<link>http://www.thedotnetfrog.com/2008/05/30/choosing-composition-over-inheritance-yet-another-example/comment-page-1/#comment-56</link>
		<dc:creator>brad</dc:creator>
		<pubDate>Thu, 12 Mar 2009 15:03:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=55#comment-56</guid>
		<description>That's what I thought, but the trip constructor that takes three arguments is assigned protected not public.  If I change your example to public, it works fine.  Was protected a mistype?</description>
		<content:encoded><![CDATA[<p>That&#8217;s what I thought, but the trip constructor that takes three arguments is assigned protected not public.  If I change your example to public, it works fine.  Was protected a mistype?</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Choosing composition over inheritance: yet another example! by Julien</title>
		<link>http://www.thedotnetfrog.com/2008/05/30/choosing-composition-over-inheritance-yet-another-example/comment-page-1/#comment-55</link>
		<dc:creator>Julien</dc:creator>
		<pubDate>Thu, 12 Mar 2009 08:20:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=55#comment-55</guid>
		<description>You would not use directry an instance of ITransportationMode, you would inject it in the Trip class like this : 

Trip tripToParis = new Trip("barcelona", "paris", new PlaneTransportationMode());
DateTime arrivalTime = tripToParis.CalculateEstimatedArrivalTime()

The point is that this calculation can change and it should not be the responsability of the Trip class to perform it. Therefore, the best way to change the behavior of the trip class is not through inheritance but through composition.

Now, keep in mind that this example is very basic and in a real application you would have real logic in CalculateTransportationTimeBetween() :)</description>
		<content:encoded><![CDATA[<p>You would not use directry an instance of ITransportationMode, you would inject it in the Trip class like this : </p>
<p>Trip tripToParis = new Trip(&#8221;barcelona&#8221;, &#8220;paris&#8221;, new PlaneTransportationMode());<br />
DateTime arrivalTime = tripToParis.CalculateEstimatedArrivalTime()</p>
<p>The point is that this calculation can change and it should not be the responsability of the Trip class to perform it. Therefore, the best way to change the behavior of the trip class is not through inheritance but through composition.</p>
<p>Now, keep in mind that this example is very basic and in a real application you would have real logic in CalculateTransportationTimeBetween() :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Choosing composition over inheritance: yet another example! by brad</title>
		<link>http://www.thedotnetfrog.com/2008/05/30/choosing-composition-over-inheritance-yet-another-example/comment-page-1/#comment-54</link>
		<dc:creator>brad</dc:creator>
		<pubDate>Wed, 11 Mar 2009 13:25:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=55#comment-54</guid>
		<description>how do you run this code?

CarTransportationMode c = new CarTransportationMode();
TimeSpan s = c.CalculateTransportationTimeBetween("", "");

I don't see where the Trip class is used or the benefits of this?</description>
		<content:encoded><![CDATA[<p>how do you run this code?</p>
<p>CarTransportationMode c = new CarTransportationMode();<br />
TimeSpan s = c.CalculateTransportationTimeBetween(&#8221;", &#8220;&#8221;);</p>
<p>I don&#8217;t see where the Trip class is used or the benefits of this?</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Choosing composition over inheritance: yet another example! by Nick Wiggill</title>
		<link>http://www.thedotnetfrog.com/2008/05/30/choosing-composition-over-inheritance-yet-another-example/comment-page-1/#comment-53</link>
		<dc:creator>Nick Wiggill</dc:creator>
		<pubDate>Sat, 14 Feb 2009 14:31:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=55#comment-53</guid>
		<description>Here's another example:

http://www.visualharmonics.co.uk/actionscript-3/using-function-closures-in-object-composition/</description>
		<content:encoded><![CDATA[<p>Here&#8217;s another example:</p>
<p><a href="http://www.visualharmonics.co.uk/actionscript-3/using-function-closures-in-object-composition/" rel="nofollow" onclick="javascript:pageTracker._trackPageview('/outbound/comment/http://www.visualharmonics.co.uk/actionscript-3/using-function-closures-in-object-composition/');">http://www.visualharmonics.co.uk/actionscript-3/using-function-closures-in-object-composition/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Choosing composition over inheritance: yet another example! by Nick Wiggill</title>
		<link>http://www.thedotnetfrog.com/2008/05/30/choosing-composition-over-inheritance-yet-another-example/comment-page-1/#comment-52</link>
		<dc:creator>Nick Wiggill</dc:creator>
		<pubDate>Wed, 11 Feb 2009 20:24:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=55#comment-52</guid>
		<description>Excellent, thanks for a simple example Julien.</description>
		<content:encoded><![CDATA[<p>Excellent, thanks for a simple example Julien.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Choosing composition over inheritance: yet another example! by Thomas Jensen</title>
		<link>http://www.thedotnetfrog.com/2008/05/30/choosing-composition-over-inheritance-yet-another-example/comment-page-1/#comment-51</link>
		<dc:creator>Thomas Jensen</dc:creator>
		<pubDate>Fri, 06 Feb 2009 22:30:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=55#comment-51</guid>
		<description>Thanks...:)</description>
		<content:encoded><![CDATA[<p>Thanks&#8230;:)</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on AutoResetEvent vs ManualResetEvent: beware! by Guimasun</title>
		<link>http://www.thedotnetfrog.com/2008/04/07/autoresetevent-vs-manualresetevent-beware/comment-page-1/#comment-46</link>
		<dc:creator>Guimasun</dc:creator>
		<pubDate>Mon, 30 Jun 2008 14:33:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.lavigneducadet.com/wordpress/?p=37#comment-46</guid>
		<description>The same happened to me. I was using a AutoResentEvent to sinalize thread termination, but sometimes the condition had been tested inside the thread loop which resets the event, so the while condition would never end.
Cheers</description>
		<content:encoded><![CDATA[<p>The same happened to me. I was using a AutoResentEvent to sinalize thread termination, but sometimes the condition had been tested inside the thread loop which resets the event, so the while condition would never end.<br />
Cheers</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on The null singleton by Julien</title>
		<link>http://www.thedotnetfrog.com/2008/05/24/the-null-singleton/comment-page-1/#comment-30</link>
		<dc:creator>Julien</dc:creator>
		<pubDate>Mon, 26 May 2008 12:50:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=44#comment-30</guid>
		<description>Multithreading is definitely an issue with singletons: most of the time, the implementation is not thread safe which can result in a "lost" instance as you were saying. Even if garbage collection is there, it can have several nasty effects depending on the context. For instance, the second instance created can try to access something that will be locked by the first instance and then fail to instantiate itself properly.

Concerning your way to initialize the singleton, I think it will be thread safe because a static field is only populated once by the CLR. However, the problem is that the instance will be created as soon something from the class is called for the first time. Therefore, you have even less control on when the instance will be created (but that might be perfectly acceptable :)). Using a static constructor might also be problematic. In that case, the instance will be created when the class is accessed but if an exception happens in the static constructor, it will be rethrown as a TypeInitializationException which would be a bit surprising I guess. More information &lt;a href="http://geekswithblogs.net/akraus1/articles/90803.aspx" rel="nofollow"&gt;here&lt;/a&gt;.

Finally, disposing a singleton is not something I've seen before and I would even say that it's probably a code-smell. As a matter of fact, I don't think you should dispose a singleton during the lifetime of the program. You might want to reset the state of the singleton somehow, but not dispose it. If you need to dispose it before the end of the program, you might end up with dozens or hundreds of initializations of your singleton... it will be totally uncontrolled. If you're at the end of the lifetime of the program, then it's not really a big deal because the CLR will release all the resources for you anyway.</description>
		<content:encoded><![CDATA[<p>Multithreading is definitely an issue with singletons: most of the time, the implementation is not thread safe which can result in a &#8220;lost&#8221; instance as you were saying. Even if garbage collection is there, it can have several nasty effects depending on the context. For instance, the second instance created can try to access something that will be locked by the first instance and then fail to instantiate itself properly.</p>
<p>Concerning your way to initialize the singleton, I think it will be thread safe because a static field is only populated once by the CLR. However, the problem is that the instance will be created as soon something from the class is called for the first time. Therefore, you have even less control on when the instance will be created (but that might be perfectly acceptable :)). Using a static constructor might also be problematic. In that case, the instance will be created when the class is accessed but if an exception happens in the static constructor, it will be rethrown as a TypeInitializationException which would be a bit surprising I guess. More information <a href="http://geekswithblogs.net/akraus1/articles/90803.aspx" rel="nofollow" onclick="javascript:pageTracker._trackPageview('/outbound/comment/http://geekswithblogs.net/akraus1/articles/90803.aspx');">here</a>.</p>
<p>Finally, disposing a singleton is not something I&#8217;ve seen before and I would even say that it&#8217;s probably a code-smell. As a matter of fact, I don&#8217;t think you should dispose a singleton during the lifetime of the program. You might want to reset the state of the singleton somehow, but not dispose it. If you need to dispose it before the end of the program, you might end up with dozens or hundreds of initializations of your singleton&#8230; it will be totally uncontrolled. If you&#8217;re at the end of the lifetime of the program, then it&#8217;s not really a big deal because the CLR will release all the resources for you anyway.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on The null singleton by agamemnon</title>
		<link>http://www.thedotnetfrog.com/2008/05/24/the-null-singleton/comment-page-1/#comment-29</link>
		<dc:creator>agamemnon</dc:creator>
		<pubDate>Mon, 26 May 2008 08:49:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=44#comment-29</guid>
		<description>Hello Julien,

I have few remarks about instance initialization in singleton. Concurrency access and instance creation are often forgotten when using this design pattern. This can lead to the creation of more than one instance (but thanks to the garbage collector if available, only one will be kept).
The second remark is rather a question. The class instance can be created in class loading time with a static block like this : private static Singleton instance = new Singleton();
This creation method can solve some extra cost when managing the concurrent access to the instance, but is it safe to use it? (I have some doubts about dll loading order and instances creation).
You mention the case where we have a large number of singleton. I have noticed in the software I'm working on it is that there is no method to free the instance.

Regards</description>
		<content:encoded><![CDATA[<p>Hello Julien,</p>
<p>I have few remarks about instance initialization in singleton. Concurrency access and instance creation are often forgotten when using this design pattern. This can lead to the creation of more than one instance (but thanks to the garbage collector if available, only one will be kept).<br />
The second remark is rather a question. The class instance can be created in class loading time with a static block like this : private static Singleton instance = new Singleton();<br />
This creation method can solve some extra cost when managing the concurrent access to the instance, but is it safe to use it? (I have some doubts about dll loading order and instances creation).<br />
You mention the case where we have a large number of singleton. I have noticed in the software I&#8217;m working on it is that there is no method to free the instance.</p>
<p>Regards</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Keep your objects in a consistent state by Greg Young</title>
		<link>http://www.thedotnetfrog.com/2008/04/12/keep-your-objects-in-a-consistent-state/comment-page-1/#comment-25</link>
		<dc:creator>Greg Young</dc:creator>
		<pubDate>Sat, 17 May 2008 00:51:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=43#comment-25</guid>
		<description>This works great for naive invariants but what about more complex ones?

An example of ...

List.Count == number of List.Items is a good one.

Another good one might be in an object that is validating data off its contingent parts ex:

I have a Customer who has a field "TotalAvailableCredit" this customer also has children "OustandingItemsOnCredit" I have an invariant that the total of all OutstandingItemsOnCredit can never total more than the TotalAvailableCredit. You can insure this invariant but it is much more difficult to insure (especially if you allow a caller to directly access the OutstandingItemsOnCredit as the invariant needs to be enforced from two objects.

One of the huge benefits of static verification is that it will manage this invariant for me. It will prove that I never break the invariant in anyway. This combined with the fact that the invariant is now exposed from the object so a consumer can understand that it will always be true is a huge benefit in terms of the caller understanding what they can expect from my code.

Cheers,

Greg</description>
		<content:encoded><![CDATA[<p>This works great for naive invariants but what about more complex ones?</p>
<p>An example of &#8230;</p>
<p>List.Count == number of List.Items is a good one.</p>
<p>Another good one might be in an object that is validating data off its contingent parts ex:</p>
<p>I have a Customer who has a field &#8220;TotalAvailableCredit&#8221; this customer also has children &#8220;OustandingItemsOnCredit&#8221; I have an invariant that the total of all OutstandingItemsOnCredit can never total more than the TotalAvailableCredit. You can insure this invariant but it is much more difficult to insure (especially if you allow a caller to directly access the OutstandingItemsOnCredit as the invariant needs to be enforced from two objects.</p>
<p>One of the huge benefits of static verification is that it will manage this invariant for me. It will prove that I never break the invariant in anyway. This combined with the fact that the invariant is now exposed from the object so a consumer can understand that it will always be true is a huge benefit in terms of the caller understanding what they can expect from my code.</p>
<p>Cheers,</p>
<p>Greg</p>
]]></content:encoded>
	</item>
</channel>
</rss>
