<?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: Challenge: Do You Truly Understand This Code?</title> <atom:link href="http://davybrion.com/blog/2009/02/challenge-do-you-truly-understand-this-code/feed/" rel="self" type="application/rss+xml" /><link>http://davybrion.com/blog/2009/02/challenge-do-you-truly-understand-this-code/</link> <description>inquisitive: adjective. given to inquiry, research, or asking questions; eager for knowledge; intellectually curious</description> <lastBuildDate>Wed, 08 Feb 2012 11:42:42 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>By: The Tests For The Readable Code Challenge</title><link>http://davybrion.com/blog/2009/02/challenge-do-you-truly-understand-this-code/comment-page-1/#comment-101277</link> <dc:creator>The Tests For The Readable Code Challenge</dc:creator> <pubDate>Sat, 10 Sep 2011 19:21:17 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=976#comment-101277</guid> <description>[...] commentsWritten on February 22nd, 2009 by Davy BrionCategories: Software DevelopmentAfter the uncommented code, and then the commented version of the code, you finally get to see the tests that verify that [...]</description> <content:encoded><![CDATA[<p>[...] commentsWritten on February 22nd, 2009 by Davy BrionCategories: Software DevelopmentAfter the uncommented code, and then the commented version of the code, you finally get to see the tests that verify that [...]</p> ]]></content:encoded> </item> <item><title>By: The Commented Version Of The Readable Code Challenge</title><link>http://davybrion.com/blog/2009/02/challenge-do-you-truly-understand-this-code/comment-page-1/#comment-101276</link> <dc:creator>The Commented Version Of The Readable Code Challenge</dc:creator> <pubDate>Sat, 10 Sep 2011 19:16:45 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=976#comment-101276</guid> <description>[...] Software DevelopmentBefore i post the tests and a further explanation of the code i listed in the readable code challenge, i wanted to post only the commented version of this code: public class Broadcaster : IBroadcaster [...]</description> <content:encoded><![CDATA[<p>[...] Software DevelopmentBefore i post the tests and a further explanation of the code i listed in the readable code challenge, i wanted to post only the commented version of this code: public class Broadcaster : IBroadcaster [...]</p> ]]></content:encoded> </item> <item><title>By: Once Again: Comments In Code Aren&#8217;t Necessarily Bad &#124; The Inquisitive Coder &#8211; Davy Brion&#039;s Blog</title><link>http://davybrion.com/blog/2009/02/challenge-do-you-truly-understand-this-code/comment-page-1/#comment-54694</link> <dc:creator>Once Again: Comments In Code Aren&#8217;t Necessarily Bad &#124; The Inquisitive Coder &#8211; Davy Brion&#039;s Blog</dc:creator> <pubDate>Wed, 18 Aug 2010 20:28:48 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=976#comment-54694</guid> <description>[...] back up my point, i&#8217;d like to point you to this challenge i posted over a year ago. That code is clean. But pretty much everyone could use some comments to [...]</description> <content:encoded><![CDATA[<p>[...] back up my point, i&#8217;d like to point you to this challenge i posted over a year ago. That code is clean. But pretty much everyone could use some comments to [...]</p> ]]></content:encoded> </item> <item><title>By: Using Copy-On-Write In Multithreaded Code To Reduce Locking Overhead &#124; The Inquisitive Coder &#8211; Davy Brion&#39;s Blog</title><link>http://davybrion.com/blog/2009/02/challenge-do-you-truly-understand-this-code/comment-page-1/#comment-31139</link> <dc:creator>Using Copy-On-Write In Multithreaded Code To Reduce Locking Overhead &#124; The Inquisitive Coder &#8211; Davy Brion&#39;s Blog</dc:creator> <pubDate>Mon, 08 Mar 2010 15:36:44 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=976#comment-31139</guid> <description>[...] leaves the copy-on-write pattern.&#160; I’ve used it before with success (though at the time, i didn’t know it was a known pattern) so this approach has [...]</description> <content:encoded><![CDATA[<p>[...] leaves the copy-on-write pattern.&#160; I’ve used it before with success (though at the time, i didn’t know it was a known pattern) so this approach has [...]</p> ]]></content:encoded> </item> <item><title>By: sl</title><link>http://davybrion.com/blog/2009/02/challenge-do-you-truly-understand-this-code/comment-page-1/#comment-9104</link> <dc:creator>sl</dc:creator> <pubDate>Mon, 23 Feb 2009 23:21:08 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=976#comment-9104</guid> <description>There&#039;s no such thing as self-documenting code.  Sure, you can always roll up your sleeves and study the code line by line. But when you have hundreds or quite commonly thousands of lines of code, it&#039;s impractical to go through all of them. Regardless of how clean your code is written, nothing beats a few lines of plain English sentences describing what your code does at a high-level (unless you&#039;re writing a &quot;hello world&quot; application).</description> <content:encoded><![CDATA[<p>There&#8217;s no such thing as self-documenting code.  Sure, you can always roll up your sleeves and study the code line by line. But when you have hundreds or quite commonly thousands of lines of code, it&#8217;s impractical to go through all of them. Regardless of how clean your code is written, nothing beats a few lines of plain English sentences describing what your code does at a high-level (unless you&#8217;re writing a &#8220;hello world&#8221; application).</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2009/02/challenge-do-you-truly-understand-this-code/comment-page-1/#comment-9092</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Mon, 23 Feb 2009 20:44:53 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=976#comment-9092</guid> <description>@JMthe importance of comments in certain situations, no matter what the purists might say. did you really read the 3 posts including the (post) comments? i kinda figured it&#039;d be clear (the point)</description> <content:encoded><![CDATA[<p>@JM</p><p>the importance of comments in certain situations, no matter what the purists might say. did you really read the 3 posts including the (post) comments? i kinda figured it&#8217;d be clear (the point)</p> ]]></content:encoded> </item> <item><title>By: JM</title><link>http://davybrion.com/blog/2009/02/challenge-do-you-truly-understand-this-code/comment-page-1/#comment-9090</link> <dc:creator>JM</dc:creator> <pubDate>Mon, 23 Feb 2009 20:32:25 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=976#comment-9090</guid> <description>This reminds me of a &quot;look how smart I am&quot; blog. Not sure what you were trying to get across in your three blogs on this code. The use of comments? The way foreach works? The I can code neat stuff, can you figure it out (I am in this camp)?</description> <content:encoded><![CDATA[<p>This reminds me of a &#8220;look how smart I am&#8221; blog. Not sure what you were trying to get across in your three blogs on this code. The use of comments? The way foreach works? The I can code neat stuff, can you figure it out (I am in this camp)?</p> ]]></content:encoded> </item> <item><title>By: vnaranjo</title><link>http://davybrion.com/blog/2009/02/challenge-do-you-truly-understand-this-code/comment-page-1/#comment-9088</link> <dc:creator>vnaranjo</dc:creator> <pubDate>Mon, 23 Feb 2009 20:08:30 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=976#comment-9088</guid> <description>Sure. You have a List of Clients, and to control the access to the list, you use a Monitor (dummy object, just to ensure threat Safety).</description> <content:encoded><![CDATA[<p>Sure. You have a List of Clients, and to control the access to the list, you use a Monitor (dummy object, just to ensure threat Safety).</p> ]]></content:encoded> </item> <item><title>By: Terry</title><link>http://davybrion.com/blog/2009/02/challenge-do-you-truly-understand-this-code/comment-page-1/#comment-9085</link> <dc:creator>Terry</dc:creator> <pubDate>Mon, 23 Feb 2009 15:17:13 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=976#comment-9085</guid> <description>Without a doubt, I would say that with no &quot;why&quot; style comments the context and the purpose of this code is unclear to say the least. It&#039;s obvious &quot;what&quot; the code does but &quot;why&quot;? Sadly mean code purists don&#039;t understand this fact.</description> <content:encoded><![CDATA[<p>Without a doubt, I would say that with no &#8220;why&#8221; style comments the context and the purpose of this code is unclear to say the least. It&#8217;s obvious &#8220;what&#8221; the code does but &#8220;why&#8221;? Sadly mean code purists don&#8217;t understand this fact.</p> ]]></content:encoded> </item> <item><title>By: James Hart</title><link>http://davybrion.com/blog/2009/02/challenge-do-you-truly-understand-this-code/comment-page-1/#comment-9079</link> <dc:creator>James Hart</dc:creator> <pubDate>Mon, 23 Feb 2009 10:41:20 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=976#comment-9079</guid> <description>One thing I would say that is overly obscure is the use of a collection initialiser:clients = new List(clients) { client };you&#039;re using the collection initialiser here to shorten the equivalent code:clients = new List(clients);
clients.Add(client);In this case, I&#039;d explcitly expand that out. The problem is that idiomatically, collection initialisers are typically used to populate a collection object after it has been constructed -empty-. Using it to append an item to a prepopulated collection is non-idiomatic, and distracts from noticing that the collection is prepopulated at all.Also, looking at your removal code, you might consider, instead of creating a list then removing an item, switching to:clients = clients.Where(c =&gt; c != client).ToList();though that maybe plays down the list creation; perhaps:clients = new List(clients.Where(c =&gt; c != client));</description> <content:encoded><![CDATA[<p>One thing I would say that is overly obscure is the use of a collection initialiser:</p><p>clients = new List(clients) { client };</p><p>you&#8217;re using the collection initialiser here to shorten the equivalent code:</p><p>clients = new List(clients);<br
/> clients.Add(client);</p><p>In this case, I&#8217;d explcitly expand that out. The problem is that idiomatically, collection initialisers are typically used to populate a collection object after it has been constructed -empty-. Using it to append an item to a prepopulated collection is non-idiomatic, and distracts from noticing that the collection is prepopulated at all.</p><p>Also, looking at your removal code, you might consider, instead of creating a list then removing an item, switching to:</p><p>clients = clients.Where(c =&gt; c != client).ToList();</p><p>though that maybe plays down the list creation; perhaps:</p><p>clients = new List(clients.Where(c =&gt; c != client));</p> ]]></content:encoded> </item> <item><title>By: Ben</title><link>http://davybrion.com/blog/2009/02/challenge-do-you-truly-understand-this-code/comment-page-1/#comment-9076</link> <dc:creator>Ben</dc:creator> <pubDate>Mon, 23 Feb 2009 09:26:39 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=976#comment-9076</guid> <description>I&#039;m not familiar enough with C#, but I would have expected the list variable to be marked as volatile. Otherwise, it can be cached and won&#039;t be seen by all threads until the CPU caches are flushed. At that point, its a standard CopyOnWriteList, and I&#039;d have just made a reusable data structure. This is pretty standard and straight-forward code, imho, and I&#039;ve written similar.</description> <content:encoded><![CDATA[<p>I&#8217;m not familiar enough with C#, but I would have expected the list variable to be marked as volatile. Otherwise, it can be cached and won&#8217;t be seen by all threads until the CPU caches are flushed. At that point, its a standard CopyOnWriteList, and I&#8217;d have just made a reusable data structure. This is pretty standard and straight-forward code, imho, and I&#8217;ve written similar.</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2009/02/challenge-do-you-truly-understand-this-code/comment-page-1/#comment-9074</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Mon, 23 Feb 2009 07:17:41 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=976#comment-9074</guid> <description>@Bobi believe comments are at least helpful in this case because the problem isn&#039;t obvious to everyone nor is the solutionand no, i don&#039;t want a pat on the back for this... it&#039;s funny you think of that. How much functionality would a class need before one deserves a pat on the back from you? ;)</description> <content:encoded><![CDATA[<p>@Bob</p><p>i believe comments are at least helpful in this case because the problem isn&#8217;t obvious to everyone nor is the solution</p><p>and no, i don&#8217;t want a pat on the back for this&#8230; it&#8217;s funny you think of that. How much functionality would a class need before one deserves a pat on the back from you? <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p> ]]></content:encoded> </item> <item><title>By: bob</title><link>http://davybrion.com/blog/2009/02/challenge-do-you-truly-understand-this-code/comment-page-1/#comment-9071</link> <dc:creator>bob</dc:creator> <pubDate>Mon, 23 Feb 2009 06:11:12 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=976#comment-9071</guid> <description>Creating a copy on write LIst is OK i guess, if your willing to put up with that kind of overhead.My confusion rests in your question about comments.  This class does almost nothing.
Why would comments be required?You really dont want a pat on the back for writing 50 lines of clear but essentially minimal functionality do you.</description> <content:encoded><![CDATA[<p>Creating a copy on write LIst is OK i guess, if your willing to put up with that kind of overhead.</p><p>My confusion rests in your question about comments.  This class does almost nothing.<br
/> Why would comments be required?</p><p>You really dont want a pat on the back for writing 50 lines of clear but essentially minimal functionality do you.</p> ]]></content:encoded> </item> <item><title>By: Justin Etheredge</title><link>http://davybrion.com/blog/2009/02/challenge-do-you-truly-understand-this-code/comment-page-1/#comment-9006</link> <dc:creator>Justin Etheredge</dc:creator> <pubDate>Fri, 20 Feb 2009 19:00:34 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=976#comment-9006</guid> <description>You are treating your Lists as immutable and concatenating the new item or removing the old item from a new list. You are doing this because if you are in the middle of a broadcast when a client is added or removed it will cause the list to be modified which will throw a &quot;collection was modified&quot; exception from the &quot;foreach&quot; loop since you modified the iterator. Wow that was one heck of a run-on sentence.</description> <content:encoded><![CDATA[<p>You are treating your Lists as immutable and concatenating the new item or removing the old item from a new list. You are doing this because if you are in the middle of a broadcast when a client is added or removed it will cause the list to be modified which will throw a &#8220;collection was modified&#8221; exception from the &#8220;foreach&#8221; loop since you modified the iterator. Wow that was one heck of a run-on sentence.</p> ]]></content:encoded> </item> <item><title>By: Ian Chamberlain</title><link>http://davybrion.com/blog/2009/02/challenge-do-you-truly-understand-this-code/comment-page-1/#comment-8990</link> <dc:creator>Ian Chamberlain</dc:creator> <pubDate>Fri, 20 Feb 2009 00:05:06 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=976#comment-8990</guid> <description>I think this is to manage concurrency. You cannot support enumeration (as in Broadcast) with write accesses (Add and Remove) at the same time as List instance members are not thread safe. All you would need to get a problem would be *one* add/remove happening at the same time as a broadcast to generate an exception. You either have to lock the List whilst enumerating or not modify it whilst a broadcast is in progress.
If the issue is thread safety I like to indicate that in the method name as in ThreadSafeAddxxx or ThreadSafeRemovexxx.</description> <content:encoded><![CDATA[<p>I think this is to manage concurrency. You cannot support enumeration (as in Broadcast) with write accesses (Add and Remove) at the same time as List instance members are not thread safe. All you would need to get a problem would be *one* add/remove happening at the same time as a broadcast to generate an exception. You either have to lock the List whilst enumerating or not modify it whilst a broadcast is in progress.<br
/> If the issue is thread safety I like to indicate that in the method name as in ThreadSafeAddxxx or ThreadSafeRemovexxx.</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2009/02/challenge-do-you-truly-understand-this-code/comment-page-1/#comment-8988</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Thu, 19 Feb 2009 22:47:24 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=976#comment-8988</guid> <description>i will post a full explanation of the problem, including the comments i added to the code and the tests that protect against the issue and then you can all decide what is more communicative: the comments or the testsbut seeing as how i&#039;m enjoying leaving you all in suspense (i&#039;m rather evil that way), i will do that on either saturday or sunday depending on when i have the time to write the post :)in the meantime, feel free to keep guessing :p</description> <content:encoded><![CDATA[<p>i will post a full explanation of the problem, including the comments i added to the code and the tests that protect against the issue and then you can all decide what is more communicative: the comments or the tests</p><p>but seeing as how i&#8217;m enjoying leaving you all in suspense (i&#8217;m rather evil that way), i will do that on either saturday or sunday depending on when i have the time to write the post <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>in the meantime, feel free to keep guessing :p</p> ]]></content:encoded> </item> <item><title>By: Ben</title><link>http://davybrion.com/blog/2009/02/challenge-do-you-truly-understand-this-code/comment-page-1/#comment-8986</link> <dc:creator>Ben</dc:creator> <pubDate>Thu, 19 Feb 2009 22:35:44 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=976#comment-8986</guid> <description>To me, the code is very readableI agree with Laila that seeing the tests fort his code would show more than comments.</description> <content:encoded><![CDATA[<p>To me, the code is very readable</p><p>I agree with Laila that seeing the tests fort his code would show more than comments.</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2009/02/challenge-do-you-truly-understand-this-code/comment-page-1/#comment-8985</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Thu, 19 Feb 2009 22:34:18 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=976#comment-8985</guid> <description>OK... one hint: in the worst possible scenario (from a load perspective), i&#039;m expecting maybe a couple of broadcasts _per minute_</description> <content:encoded><![CDATA[<p>OK&#8230; one hint: in the worst possible scenario (from a load perspective), i&#8217;m expecting maybe a couple of broadcasts _per minute_</p> ]]></content:encoded> </item> <item><title>By: Stijn Guillemyn</title><link>http://davybrion.com/blog/2009/02/challenge-do-you-truly-understand-this-code/comment-page-1/#comment-8984</link> <dc:creator>Stijn Guillemyn</dc:creator> <pubDate>Thu, 19 Feb 2009 22:04:23 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=976#comment-8984</guid> <description>@AyendeIndeed. As always, your explanation is more clear, but that&#039;s what I meant with:
&lt;i&gt;probably not something you want giving the fact you want the broadcast to act instantly&lt;/i&gt;You need a way to ensure your code doesn&#039;t break when broadcasting, due to a changing list.
You might lock every access, or use this approach that gives better broadcast performance (which is the main purpose of your class after all).To me, comments would be advisable. What&#039;s your take on this?</description> <content:encoded><![CDATA[<p>@Ayende</p><p>Indeed. As always, your explanation is more clear, but that&#8217;s what I meant with:<br
/> <i>probably not something you want giving the fact you want the broadcast to act instantly</i></p><p>You need a way to ensure your code doesn&#8217;t break when broadcasting, due to a changing list.<br
/> You might lock every access, or use this approach that gives better broadcast performance (which is the main purpose of your class after all).</p><p>To me, comments would be advisable. What&#8217;s your take on this?</p> ]]></content:encoded> </item> <item><title>By: Ayende Rahien</title><link>http://davybrion.com/blog/2009/02/challenge-do-you-truly-understand-this-code/comment-page-1/#comment-8983</link> <dc:creator>Ayende Rahien</dc:creator> <pubDate>Thu, 19 Feb 2009 21:50:28 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=976#comment-8983</guid> <description>I would say that the actual reason is performance.
You aren&#039;t likely to changing the broadcast list all that often.
By having an immutable value, you can avoid locking whenever you need to broadcast.</description> <content:encoded><![CDATA[<p>I would say that the actual reason is performance.<br
/> You aren&#8217;t likely to changing the broadcast list all that often.<br
/> By having an immutable value, you can avoid locking whenever you need to broadcast.</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 1/24 queries in 0.015 seconds using disk: basic
Object Caching 645/646 objects using disk: basic
Content Delivery Network via Amazon Web Services: CloudFront: d18sni7re4ly7f.cloudfront.net

Served from: davybrion.com @ 2012-02-08 19:25:29 -->
