<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>What makes some code confusing?</title><link>http://weblogs.asp.net/jcogley/archive/2008/02/23/what-makes-some-code-confusing.aspx</link><description>Developers look at code for hour upon hour every day.&amp;#160; After some years of doing this, you can just look at something and almost intuitively understand what it is doing - assuming that some effort has been made by the developers to keep the code</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>re: What makes some code confusing?</title><link>http://weblogs.asp.net/jcogley/archive/2008/02/23/what-makes-some-code-confusing.aspx#5906705</link><pubDate>Mon, 03 Mar 2008 16:45:57 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5906705</guid><dc:creator>Snacks</dc:creator><author>Snacks</author><description>&lt;p&gt;This really isn't an issue. The fact that is confused you so much to the point of writing a blog post probably means that you shouldn't be a C# MVP. Pay attention to your code. Reading code is like reading a book, one thing at a time.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5906705" width="1" height="1"&gt;</description></item><item><title>re: What makes some code confusing?</title><link>http://weblogs.asp.net/jcogley/archive/2008/02/23/what-makes-some-code-confusing.aspx#5862507</link><pubDate>Tue, 26 Feb 2008 10:30:43 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5862507</guid><dc:creator>tahseen</dc:creator><author>tahseen</author><description>&lt;p&gt;@Ben Well said :)&lt;/p&gt;
&lt;p&gt;I wonder when we will have a communication medium as good as a face2fact chat.&lt;/p&gt;
&lt;p&gt;Your other point on IsSaved is also true, thats why it may have been better to have the (id &amp;gt; 0) encapsulated behind a method that expresses the intent.&lt;/p&gt;
&lt;p&gt;My professional experience is pretty limited and I'm still trying to find the right boundary for breakdown in methods.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5862507" width="1" height="1"&gt;</description></item><item><title>re: What makes some code confusing?</title><link>http://weblogs.asp.net/jcogley/archive/2008/02/23/what-makes-some-code-confusing.aspx#5862368</link><pubDate>Tue, 26 Feb 2008 09:41:55 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5862368</guid><dc:creator>Ben</dc:creator><author>Ben</author><description>&lt;p&gt;Okay, fair enough. Every time I've heard that comment stated by a high-level language developer the tone is as an insult. That's not to say they don't appreciate it at the right level, but in their programming language it means that the developer is incompetent.&lt;/p&gt;
&lt;p&gt;I guess it comes down to it being hard to judge the tone of the written word very well...&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5862368" width="1" height="1"&gt;</description></item><item><title>re: What makes some code confusing?</title><link>http://weblogs.asp.net/jcogley/archive/2008/02/23/what-makes-some-code-confusing.aspx#5859865</link><pubDate>Mon, 25 Feb 2008 16:10:08 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5859865</guid><dc:creator>Leo K. Scott</dc:creator><author>Leo K. Scott</author><description>&lt;p&gt;The first problem is the name of the method. The calling code &amp;quot;if (MayUserChangeEntry) ...&amp;quot; does not read well and it implies that you should be passing in which User to check. A much better name would be ChangeAllowed(). After getting the name right, the next step is to encapsulate the the &amp;quot;magic numbers&amp;quot; into methods that capture the meaning assigned to the numbers. After that either one-line works for me.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5859865" width="1" height="1"&gt;</description></item><item><title>re: What makes some code confusing?</title><link>http://weblogs.asp.net/jcogley/archive/2008/02/23/what-makes-some-code-confusing.aspx#5859067</link><pubDate>Mon, 25 Feb 2008 11:46:46 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5859067</guid><dc:creator>thycotic</dc:creator><author>thycotic</author><description>&lt;p&gt;@Simon: &amp;nbsp;We have a team policy of not using negatives in method names - mostly because someone will then do !notSaved which starts to get silly.&lt;/p&gt;
&lt;p&gt;I like the way your change reads better though.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5859067" width="1" height="1"&gt;</description></item><item><title>re: What makes some code confusing?</title><link>http://weblogs.asp.net/jcogley/archive/2008/02/23/what-makes-some-code-confusing.aspx#5859056</link><pubDate>Mon, 25 Feb 2008 11:43:29 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5859056</guid><dc:creator>thycotic</dc:creator><author>thycotic</author><description>&lt;p&gt;Ben,&lt;/p&gt;
&lt;p&gt;I don't think calling someone a &amp;quot;bit lover&amp;quot; is defaming someone. &amp;nbsp;Most &amp;quot;bit lovers&amp;quot; that I know are incredibly smart developers who just happen to be comfortable with more bitwise complexity than most developers. &lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5859056" width="1" height="1"&gt;</description></item><item><title>re: What makes some code confusing?</title><link>http://weblogs.asp.net/jcogley/archive/2008/02/23/what-makes-some-code-confusing.aspx#5858397</link><pubDate>Mon, 25 Feb 2008 08:33:37 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5858397</guid><dc:creator>Simon</dc:creator><author>Simon</author><description>&lt;p&gt;I would go further and remove the negation of isSaved() from the ternary&lt;/p&gt;
&lt;p&gt;public bool MayUserChangeEntity()&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;return notSaved() || Security.GetCurrentAccount().IsSpecialUser() || IsEntityDraft();&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;private bool notSaved()&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;return !(Id &amp;gt; 0);&lt;/p&gt;
&lt;p&gt;} &lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5858397" width="1" height="1"&gt;</description></item><item><title>re: What makes some code confusing?</title><link>http://weblogs.asp.net/jcogley/archive/2008/02/23/what-makes-some-code-confusing.aspx#5858054</link><pubDate>Mon, 25 Feb 2008 07:18:35 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5858054</guid><dc:creator>Ben</dc:creator><author>Ben</author><description>&lt;p&gt;I have no problem with self-documenting code. As I said, either are fine with me and at over 3 arguments I definately would have made the changes to - 3 is my tolerance limit. I agree 100% with Squid's remark.&lt;/p&gt;
&lt;p&gt;One concern, having seen this happen, is poor refactorings. It may not be true that (id &amp;gt; 0) means saved, which could cause further confusion. When changing code you don't understand, you need to be extra careful and be due diligent. Eagerly refactoring can be dangerous.&lt;/p&gt;
&lt;p&gt;To be honest, my main negativity was (1) the immediate assumption that the original is bad or was done for inept performance, and (2) trying to defame the author of a comment who disagreed with him. While Sam could have been a tad nicer, the blog auther should be the most professional here because he isn't anonymous. He needs to have a thick skin and take critics openly - developers are a pretty abusive bunch!&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5858054" width="1" height="1"&gt;</description></item><item><title>re: What makes some code confusing?</title><link>http://weblogs.asp.net/jcogley/archive/2008/02/23/what-makes-some-code-confusing.aspx#5857626</link><pubDate>Mon, 25 Feb 2008 05:28:51 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5857626</guid><dc:creator>John Bäckstrand</dc:creator><author>John Bäckstrand</author><description>&lt;p&gt;I would have refactored this in an instant. I also have trouble &amp;quot;seeing&amp;quot; what it does in less than 10 seconds, and thats is enough to know it needs some love. :)&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5857626" width="1" height="1"&gt;</description></item><item><title>re: What makes some code confusing?</title><link>http://weblogs.asp.net/jcogley/archive/2008/02/23/what-makes-some-code-confusing.aspx#5857475</link><pubDate>Mon, 25 Feb 2008 04:54:06 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:5857475</guid><dc:creator>tahseen</dc:creator><author>tahseen</author><description>&lt;p&gt;John, I think the major improvement in the refactored version of the code is that it expresses the business intend. The IsSaved method hides the implementation detail that id = 0 for new unsaved object and same goes for the other method you introduced.&lt;/p&gt;
&lt;p&gt;Sam and Ben, I think all most any reasonable programmer would understand both version and equally everybody will understand the later version faster. Why would somebody waste time jumping through codes to understand (id &amp;gt; 0) means saved? You can say that somebody needs to document that fact which is exactly what the IsSaved method is doing. Self documented code is the best kind of documentation that you can get, cause its never going to be stale.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5857475" width="1" height="1"&gt;</description></item></channel></rss>