<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><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" 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>
	<pubDate>Thu, 13 Nov 2008 21:03:00 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/thedotnetfrog-comments" type="application/rss+xml" /><item>
		<title>Comment on Spec#: should we really wait for it? by Brenton Brennan</title>
		<link>http://www.thedotnetfrog.com/2008/05/13/spec-should-we-really-wait-for-it/#comment-50</link>
		<dc:creator>Brenton Brennan</dc:creator>
		<pubDate>Thu, 13 Nov 2008 02:25:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=49#comment-50</guid>
		<description>ad2kg7c5tmm2et6h</description>
		<content:encoded><![CDATA[<p>ad2kg7c5tmm2et6h</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Performance impact of the readonly keyword by Danny Valentine</title>
		<link>http://www.thedotnetfrog.com/2008/04/22/performance-impact-of-the-readonly-keyword/#comment-49</link>
		<dc:creator>Danny Valentine</dc:creator>
		<pubDate>Thu, 13 Nov 2008 01:44:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=46#comment-49</guid>
		<description>y26xjgmlseka3gj6</description>
		<content:encoded><![CDATA[<p>y26xjgmlseka3gj6</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Yet another blogger on earth! by Eva Clayton</title>
		<link>http://www.thedotnetfrog.com/2008/04/04/yet-another-blogger-on-earth/#comment-48</link>
		<dc:creator>Eva Clayton</dc:creator>
		<pubDate>Thu, 13 Nov 2008 01:14:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=42#comment-48</guid>
		<description>y3cw01h8bft4ufa4</description>
		<content:encoded><![CDATA[<p>y3cw01h8bft4ufa4</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Choosing composition over inheritance: yet another example! by Lizette Weeks</title>
		<link>http://www.thedotnetfrog.com/2008/05/30/choosing-composition-over-inheritance-yet-another-example/#comment-47</link>
		<dc:creator>Lizette Weeks</dc:creator>
		<pubDate>Wed, 12 Nov 2008 20:52:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=55#comment-47</guid>
		<description>uwhvfie773s6yhzq</description>
		<content:encoded><![CDATA[<p>uwhvfie773s6yhzq</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-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-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-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-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>
	<item>
		<title>Comment on Spec#: should we really wait for it? by Greg Young</title>
		<link>http://www.thedotnetfrog.com/2008/05/13/spec-should-we-really-wait-for-it/#comment-24</link>
		<dc:creator>Greg Young</dc:creator>
		<pubDate>Sat, 17 May 2008 00:45:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=49#comment-24</guid>
		<description>I can't speak for everyone but for myself I am not actually wanting spec# per se... I am much more interested in having Boogie and all of the contracts for the framework. Any language could feasibly allow instrumentation of IL to include contracts that a theorem prover could understand.

You are correct that migrations will take a long time (especially for the ultra buggy code sitting in the mainstream today). The best way to help move towards it is as you say to start writing better defensive code today. Not only will your code be better but it will be quite easy to refactor your pre/post conditions to a similar system.

One side note, everyone seems to test pre-conditions to be true but I rarely see people verifying their post conditions with an if statement in their code which is just as important.

Cheers,

Greg

*leaving another comment on invariants post*</description>
		<content:encoded><![CDATA[<p>I can&#8217;t speak for everyone but for myself I am not actually wanting spec# per se&#8230; I am much more interested in having Boogie and all of the contracts for the framework. Any language could feasibly allow instrumentation of IL to include contracts that a theorem prover could understand.</p>
<p>You are correct that migrations will take a long time (especially for the ultra buggy code sitting in the mainstream today). The best way to help move towards it is as you say to start writing better defensive code today. Not only will your code be better but it will be quite easy to refactor your pre/post conditions to a similar system.</p>
<p>One side note, everyone seems to test pre-conditions to be true but I rarely see people verifying their post conditions with an if statement in their code which is just as important.</p>
<p>Cheers,</p>
<p>Greg</p>
<p>*leaving another comment on invariants post*</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Keep your objects in a consistent state by Spec#: should we really wait for it? | The .Net frog</title>
		<link>http://www.thedotnetfrog.com/2008/04/12/keep-your-objects-in-a-consistent-state/#comment-23</link>
		<dc:creator>Spec#: should we really wait for it? | The .Net frog</dc:creator>
		<pubDate>Tue, 13 May 2008 17:52:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=43#comment-23</guid>
		<description>[...] The bottom line is that I believe that we should focus our efforts on improving the way we do defensive programming with the framework as it is, and not hope for a white knight. Even if they are not perfect solutions, I think we can cover a lot of ground by systematically checking the inputs, checking the post conditions/side effects with unit testing, and checking that our object are satisfying invariants. [...]</description>
		<content:encoded><![CDATA[<p>[...] The bottom line is that I believe that we should focus our efforts on improving the way we do defensive programming with the framework as it is, and not hope for a white knight. Even if they are not perfect solutions, I think we can cover a lot of ground by systematically checking the inputs, checking the post conditions/side effects with unit testing, and checking that our object are satisfying invariants. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Performance impact of the readonly keyword by James Curran</title>
		<link>http://www.thedotnetfrog.com/2008/04/22/performance-impact-of-the-readonly-keyword/#comment-18</link>
		<dc:creator>James Curran</dc:creator>
		<pubDate>Fri, 25 Apr 2008 16:08:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=46#comment-18</guid>
		<description>My general feeling is that "More information is better", and so would use "readonly" when appropriate.  Remember, just because the jitter doesn't necessarily optimize for readonly now, doesn't mean that it won't in the future.

In think that jitter optimization could be the next big area of .Net innovation, where the .net framework installation process would choose one from perhaps a dozen  different jitters, each customized to a particular CPU/platform, which would generate code which would run only a machine exactly like mine.</description>
		<content:encoded><![CDATA[<p>My general feeling is that &#8220;More information is better&#8221;, and so would use &#8220;readonly&#8221; when appropriate.  Remember, just because the jitter doesn&#8217;t necessarily optimize for readonly now, doesn&#8217;t mean that it won&#8217;t in the future.</p>
<p>In think that jitter optimization could be the next big area of .Net innovation, where the .net framework installation process would choose one from perhaps a dozen  different jitters, each customized to a particular CPU/platform, which would generate code which would run only a machine exactly like mine.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Performance impact of the readonly keyword by Reflective Perspective - Chris Alcock » The Morning Brew #81</title>
		<link>http://www.thedotnetfrog.com/2008/04/22/performance-impact-of-the-readonly-keyword/#comment-17</link>
		<dc:creator>Reflective Perspective - Chris Alcock » The Morning Brew #81</dc:creator>
		<pubDate>Fri, 25 Apr 2008 07:13:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=46#comment-17</guid>
		<description>[...] Performance impact of the readonly keyword - A look at the performance difference obtained by using the readonly keyword [...]</description>
		<content:encoded><![CDATA[<p>[...] Performance impact of the readonly keyword - A look at the performance difference obtained by using the readonly keyword [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Performance impact of the readonly keyword by Dew Drop - April 24, 2008 | Alvin Ashcraft's Morning Dew</title>
		<link>http://www.thedotnetfrog.com/2008/04/22/performance-impact-of-the-readonly-keyword/#comment-16</link>
		<dc:creator>Dew Drop - April 24, 2008 | Alvin Ashcraft's Morning Dew</dc:creator>
		<pubDate>Thu, 24 Apr 2008 15:04:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=46#comment-16</guid>
		<description>[...] Performance Impact of the readonly Keyword (Julien) [...]</description>
		<content:encoded><![CDATA[<p>[...] Performance Impact of the readonly Keyword (Julien) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Performance impact of the readonly keyword by Julien</title>
		<link>http://www.thedotnetfrog.com/2008/04/22/performance-impact-of-the-readonly-keyword/#comment-15</link>
		<dc:creator>Julien</dc:creator>
		<pubDate>Thu, 24 Apr 2008 12:32:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=46#comment-15</guid>
		<description>I certainly agree that the semantic aspect should be the determining reason to use the readonly keyword in 99,99% of the cases, specially after the benchmark I ran. However, the readonly keyword is not absolutely needed (you can have a "readonly" behavior without using the keyword if you want to) which is not the case of interfaces or virtual members. Therefore, if you're developping things that are extremely sensible to performances, I think it's worth keepnig in mind that this "optional" keyword can have a small impact in both positive or negative ways. But as I said, given the benchmarks, I think it's perfectly right to say that the semantics should drive your decision.</description>
		<content:encoded><![CDATA[<p>I certainly agree that the semantic aspect should be the determining reason to use the readonly keyword in 99,99% of the cases, specially after the benchmark I ran. However, the readonly keyword is not absolutely needed (you can have a &#8220;readonly&#8221; behavior without using the keyword if you want to) which is not the case of interfaces or virtual members. Therefore, if you&#8217;re developping things that are extremely sensible to performances, I think it&#8217;s worth keepnig in mind that this &#8220;optional&#8221; keyword can have a small impact in both positive or negative ways. But as I said, given the benchmarks, I think it&#8217;s perfectly right to say that the semantics should drive your decision.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Performance impact of the readonly keyword by Fredrik</title>
		<link>http://www.thedotnetfrog.com/2008/04/22/performance-impact-of-the-readonly-keyword/#comment-14</link>
		<dc:creator>Fredrik</dc:creator>
		<pubDate>Thu, 24 Apr 2008 11:38:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=46#comment-14</guid>
		<description>Although interresting to know about, to me the readonly keyword is more about semantics than performance. By making a field readonly, I'm explicitly saying that "this should never change", and as such it is an important tool that should be used liberally. In enterprise development, the performance implications of readonly, virtual, interfaces and all that stuff is mostly neglible anyways. My two cents :)</description>
		<content:encoded><![CDATA[<p>Although interresting to know about, to me the readonly keyword is more about semantics than performance. By making a field readonly, I&#8217;m explicitly saying that &#8220;this should never change&#8221;, and as such it is an important tool that should be used liberally. In enterprise development, the performance implications of readonly, virtual, interfaces and all that stuff is mostly neglible anyways. My two cents :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Performance impact of the readonly keyword by Sam</title>
		<link>http://www.thedotnetfrog.com/2008/04/22/performance-impact-of-the-readonly-keyword/#comment-13</link>
		<dc:creator>Sam</dc:creator>
		<pubDate>Wed, 23 Apr 2008 21:55:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=46#comment-13</guid>
		<description>This is fascinating to me. I do this kind of micro-benchmarking too. It helps me understand what is really happening with the code. That is far more useful than those 200 milliseconds. Great post.</description>
		<content:encoded><![CDATA[<p>This is fascinating to me. I do this kind of micro-benchmarking too. It helps me understand what is really happening with the code. That is far more useful than those 200 milliseconds. Great post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on lock(this): don’t! by test0191</title>
		<link>http://www.thedotnetfrog.com/2008/04/04/lockthis-dont/#comment-12</link>
		<dc:creator>test0191</dc:creator>
		<pubDate>Tue, 08 Apr 2008 08:47:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.lavigneducadet.com/wordpress/?p=28#comment-12</guid>
		<description>Thst surprised me too. I had a similar experience, I made a change to add a lock on a method that was only called from within lock on the same object, I expected the inner lock to fail, but it didn't. Reasonable enough, as it is the same as doing this:

lock (myLockObject)
{
        lock (myLockObject)
        {
                // do my stuff
        }
}

and we wouldn't expect that to fail.</description>
		<content:encoded><![CDATA[<p>Thst surprised me too. I had a similar experience, I made a change to add a lock on a method that was only called from within lock on the same object, I expected the inner lock to fail, but it didn&#8217;t. Reasonable enough, as it is the same as doing this:</p>
<p>lock (myLockObject)<br />
{<br />
        lock (myLockObject)<br />
        {<br />
                // do my stuff<br />
        }<br />
}</p>
<p>and we wouldn&#8217;t expect that to fail.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Yet another blogger on earth! by Max Pool</title>
		<link>http://www.thedotnetfrog.com/2008/04/04/yet-another-blogger-on-earth/#comment-11</link>
		<dc:creator>Max Pool</dc:creator>
		<pubDate>Sat, 05 Apr 2008 13:41:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.thedotnetfrog.com/?p=42#comment-11</guid>
		<description>Welcome to the blogosphere!  Looking forward to your posts!</description>
		<content:encoded><![CDATA[<p>Welcome to the blogosphere!  Looking forward to your posts!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
