<?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: C# tips, tricks and things you should know</title>
	<atom:link href="http://www.webdevbros.net/2007/11/14/c-tips-tricks-and-things-you-should-know/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webdevbros.net/2007/11/14/c-tips-tricks-and-things-you-should-know/</link>
	<description>hot talk about web development</description>
	<lastBuildDate>Tue, 10 May 2011 13:11:20 +0200</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Michal</title>
		<link>http://www.webdevbros.net/2007/11/14/c-tips-tricks-and-things-you-should-know/#comment-11007</link>
		<dc:creator>Michal</dc:creator>
		<pubDate>Tue, 18 Aug 2009 03:51:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.webdevbros.net/2007/11/14/c-tips-tricks-and-things-you-should-know/#comment-11007</guid>
		<description>Jonathan I really appreciate your extended feedback and agree with most of the things however keep in mind that this book is focused on component development/usage .

Just some things to add from my side:

&lt;pre&gt;
Instead you should always implement the IDisposable pattern.
&lt;/pre&gt;

It&#039;s already mentioned ... &quot;best way is to implement both&quot;

&lt;pre&gt;
This will actually not compile unless the object already implements IDisposable, so this is entirely incorrect.
&lt;/pre&gt;

Hmm, actually it will compile as there is a defensive cast (see 2.) within the using statement. If IDisposable is not implemented then the cast results in null and dispose is not called. Therefore &quot;defensive&quot; and fully legal.

&lt;pre&gt;
The provided example goes against every best practice known to .NET programmer.

* Fail Fast
* Never eat unhandled exceptions
* Never catch exceptions just to rethrow.

Utter garbage, ignore this one
&lt;/pre&gt;

Totally agree with you on this and am not 100% sure why they do it that way but I guess it has to do with components development. Will look that up again as soon as I am home and have access to the book. 

&lt;pre&gt;
&gt;1. Static objects as keys a static object
&lt;/pre&gt;

I guess the big benefit here is type safety and intellisense. I am not sure about your explanation with the CLR and folding strings. Could you explain this in detail. Afaik strings are immutable and therefore each string exists once in the string pool. Static object would also exist only once. So I guess it would be pretty much the same from an performance point of view .. Unless the object is &quot;smaller&quot; than the string object... not sure if I am correct.</description>
		<content:encoded><![CDATA[<p>Jonathan I really appreciate your extended feedback and agree with most of the things however keep in mind that this book is focused on component development/usage .</p>
<p>Just some things to add from my side:</p>
<pre>
Instead you should always implement the IDisposable pattern.
</pre>
<p>It&#8217;s already mentioned &#8230; &#8220;best way is to implement both&#8221;</p>
<pre>
This will actually not compile unless the object already implements IDisposable, so this is entirely incorrect.
</pre>
<p>Hmm, actually it will compile as there is a defensive cast (see 2.) within the using statement. If IDisposable is not implemented then the cast results in null and dispose is not called. Therefore &#8220;defensive&#8221; and fully legal.</p>
<pre>
The provided example goes against every best practice known to .NET programmer.

* Fail Fast
* Never eat unhandled exceptions
* Never catch exceptions just to rethrow.

Utter garbage, ignore this one
</pre>
<p>Totally agree with you on this and am not 100% sure why they do it that way but I guess it has to do with components development. Will look that up again as soon as I am home and have access to the book. </p>
<pre>
>1. Static objects as keys a static object
</pre>
<p>I guess the big benefit here is type safety and intellisense. I am not sure about your explanation with the CLR and folding strings. Could you explain this in detail. Afaik strings are immutable and therefore each string exists once in the string pool. Static object would also exist only once. So I guess it would be pretty much the same from an performance point of view .. Unless the object is &#8220;smaller&#8221; than the string object&#8230; not sure if I am correct.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Holland</title>
		<link>http://www.webdevbros.net/2007/11/14/c-tips-tricks-and-things-you-should-know/#comment-11006</link>
		<dc:creator>Jonathan Holland</dc:creator>
		<pubDate>Tue, 18 Aug 2009 02:10:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.webdevbros.net/2007/11/14/c-tips-tricks-and-things-you-should-know/#comment-11006</guid>
		<description>Uh, this list is full of errors and bad advise.

&gt;implicit vs explicit cast

There is a bigger difference here that they don&#039;t touch on. Casting via

  lol = (foo)bar;

will throw a invalid cast exception if the cast can&#039;t happen. However the same this way:

 lol = bar as foo;

Will fail silently and just set lol to null. This means you need to be aware and check for nulls. Additionally, this cast is slower because it catches the invalidcast exception under the hood.

&gt;Destructors Best way is to implement both and channel the implementation to the method which does the cleanup

Garbage collection in .NET is non deterministic, so your destructor is not called when the object goes out of scope, but instead when there is heap pressure. Because of this, you should never free resources in a finalizer (They aren&#039;t officially called destructors either), otherwise your app could hold open resource handles indefinitely.

Instead you should always implement the IDisposable pattern.

&gt;use &quot;Using&quot; defensive This approach will only call Dispose() if the object implements IDisposeable. Good if you dont really know if the object needs to release resources or not and if you want to be ready for future changes. e.g. the server decides to implement IDisposeable.

This will actually not compile unless the object already implements IDisposable, so this is entirely incorrect.

&gt; 1. Always fire events in a try catch block You never know what the event handler method of the client does, so its good to put the firing into a try catch block. You could write your own EventsHelper class [COMP05, 144] for the purpose of firing event within your classes.

The provided example goes against every best practice known to .NET programmer.

    * Fail Fast
    * Never eat unhandled exceptions
    * Never catch exceptions just to rethrow.

Utter garbage, ignore this one.

&gt;1. Static objects as keys a static object is created to act as a key for e.g. collections (because every instance is unique - has its own identity!). The advantage in comparison to the &quot;old school&quot; version (key is a string) is that the key is already available in memory wheras the string needs to be created everytime. If you use this key in a lot of places it could save some time.

This would only make sense if the C# compiler and CLR didn&#039;t automatically fold strings, so that each string literal is only referenced once. This means that if you have a literal &quot;foo&quot; in your code, the CLR will create it once, and reuse the pointer to it under the hood.

This means that this &quot;performance gain&quot; is bogus, and just leaves really shitty code.

&gt;Containment 

This should be Composition.</description>
		<content:encoded><![CDATA[<p>Uh, this list is full of errors and bad advise.</p>
<p>&gt;implicit vs explicit cast</p>
<p>There is a bigger difference here that they don&#8217;t touch on. Casting via</p>
<p>  lol = (foo)bar;</p>
<p>will throw a invalid cast exception if the cast can&#8217;t happen. However the same this way:</p>
<p> lol = bar as foo;</p>
<p>Will fail silently and just set lol to null. This means you need to be aware and check for nulls. Additionally, this cast is slower because it catches the invalidcast exception under the hood.</p>
<p>&gt;Destructors Best way is to implement both and channel the implementation to the method which does the cleanup</p>
<p>Garbage collection in .NET is non deterministic, so your destructor is not called when the object goes out of scope, but instead when there is heap pressure. Because of this, you should never free resources in a finalizer (They aren&#8217;t officially called destructors either), otherwise your app could hold open resource handles indefinitely.</p>
<p>Instead you should always implement the IDisposable pattern.</p>
<p>&gt;use &#8220;Using&#8221; defensive This approach will only call Dispose() if the object implements IDisposeable. Good if you dont really know if the object needs to release resources or not and if you want to be ready for future changes. e.g. the server decides to implement IDisposeable.</p>
<p>This will actually not compile unless the object already implements IDisposable, so this is entirely incorrect.</p>
<p>&gt; 1. Always fire events in a try catch block You never know what the event handler method of the client does, so its good to put the firing into a try catch block. You could write your own EventsHelper class [COMP05, 144] for the purpose of firing event within your classes.</p>
<p>The provided example goes against every best practice known to .NET programmer.</p>
<p>    * Fail Fast<br />
    * Never eat unhandled exceptions<br />
    * Never catch exceptions just to rethrow.</p>
<p>Utter garbage, ignore this one.</p>
<p>&gt;1. Static objects as keys a static object is created to act as a key for e.g. collections (because every instance is unique &#8211; has its own identity!). The advantage in comparison to the &#8220;old school&#8221; version (key is a string) is that the key is already available in memory wheras the string needs to be created everytime. If you use this key in a lot of places it could save some time.</p>
<p>This would only make sense if the C# compiler and CLR didn&#8217;t automatically fold strings, so that each string literal is only referenced once. This means that if you have a literal &#8220;foo&#8221; in your code, the CLR will create it once, and reuse the pointer to it under the hood.</p>
<p>This means that this &#8220;performance gain&#8221; is bogus, and just leaves really shitty code.</p>
<p>&gt;Containment </p>
<p>This should be Composition.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jim Danby</title>
		<link>http://www.webdevbros.net/2007/11/14/c-tips-tricks-and-things-you-should-know/#comment-11005</link>
		<dc:creator>Jim Danby</dc:creator>
		<pubDate>Mon, 17 Aug 2009 21:11:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.webdevbros.net/2007/11/14/c-tips-tricks-and-things-you-should-know/#comment-11005</guid>
		<description>Point 8 is only useful if you do something with it. The code you have is essentially what would be generated for you.</description>
		<content:encoded><![CDATA[<p>Point 8 is only useful if you do something with it. The code you have is essentially what would be generated for you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tchakerian</title>
		<link>http://www.webdevbros.net/2007/11/14/c-tips-tricks-and-things-you-should-know/#comment-11004</link>
		<dc:creator>Tchakerian</dc:creator>
		<pubDate>Mon, 17 Aug 2009 17:55:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.webdevbros.net/2007/11/14/c-tips-tricks-and-things-you-should-know/#comment-11004</guid>
		<description>Great article!
Just a small thought: its Singelton or Singleton App?</description>
		<content:encoded><![CDATA[<p>Great article!<br />
Just a small thought: its Singelton or Singleton App?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kumana</title>
		<link>http://www.webdevbros.net/2007/11/14/c-tips-tricks-and-things-you-should-know/#comment-9490</link>
		<dc:creator>Kumana</dc:creator>
		<pubDate>Wed, 24 Sep 2008 23:15:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.webdevbros.net/2007/11/14/c-tips-tricks-and-things-you-should-know/#comment-9490</guid>
		<description>This is an impressive and very useful set of tips. Thanks for taking the time to post these.</description>
		<content:encoded><![CDATA[<p>This is an impressive and very useful set of tips. Thanks for taking the time to post these.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Easwaran</title>
		<link>http://www.webdevbros.net/2007/11/14/c-tips-tricks-and-things-you-should-know/#comment-9088</link>
		<dc:creator>Easwaran</dc:creator>
		<pubDate>Tue, 29 Jul 2008 07:33:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.webdevbros.net/2007/11/14/c-tips-tricks-and-things-you-should-know/#comment-9088</guid>
		<description>Really worthful tip and tricks on C#. :)</description>
		<content:encoded><![CDATA[<p>Really worthful tip and tricks on C#. :)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

