<?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: 10 Rules to Code By</title>
	<atom:link href="http://www.camturner.com/2007/01/10-rules-to-code-by/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.camturner.com/2007/01/10-rules-to-code-by/</link>
	<description>A little bit of everything. My hobbies, ideas, family and career.</description>
	<lastBuildDate>Thu, 22 Jul 2010 22:49:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Jeffrey Sambells</title>
		<link>http://www.camturner.com/2007/01/10-rules-to-code-by/#comment-69</link>
		<dc:creator>Jeffrey Sambells</dc:creator>
		<pubDate>Thu, 25 Jan 2007 16:54:52 +0000</pubDate>
		<guid isPermaLink="false">http://blog.wecreate.com/articles/10-rules-to-code-by/#comment-69</guid>
		<description>&lt;p&gt;Matt, regarding the alert(document.getElementById(&#039;imgid&#039;).style.height); example. yes that is true, but the logic is slightly flawed. The style property on DOM elements only applies to inline style definitions. The style applied through a external style sheet will never appear in the example you lay out, regardless of when the CSS is applied to the document. Even after the page has finished loading,  a click event would revel the same.&lt;/p&gt;

&lt;p&gt;Your problem in this case is that you need to get the computed style. Try this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;getStyle(document.getElementById(&#039;imgid&#039;),height);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It will work on load using the following function:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;/* retrieve the computed style of an element */
function getStyle(element,property) {
    var camelProperty = property.replace(/\-(\w)/g, function (strMatch, p1){ return p1.toUpperCase(); });

    var value = element.style[camelProperty];
    if (!value) {
      if (document.defaultView &amp;&amp; document.defaultView.getComputedStyle) {
        var css = document.defaultView.getComputedStyle(element, null);
        value = css ? css.getPropertyValue(property) : null;
      } else if (element.currentStyle) {
        value = element.currentStyle[camelProperty];
      }
    }
    return value == &#039;auto&#039; ? &#039;&#039; : value;    
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The additional problem with using the CSS values to determine sizing is that it doesn&#039;t necessarily return a numeric number. It could just a easily be a percentage, or a non pixel number (12em). Yo may want to use properties such as offsetHeight though it not part of the DOM spec.&lt;/p&gt;

&lt;p&gt;That aside, you are correct, I shouldn&#039;t use the term &#039;Never&#039; as per your other arguments with the yahoo research.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Matt, regarding the alert(document.getElementById(&#8216;imgid&#8217;).style.height); example. yes that is true, but the logic is slightly flawed. The style property on DOM elements only applies to inline style definitions. The style applied through a external style sheet will never appear in the example you lay out, regardless of when the CSS is applied to the document. Even after the page has finished loading,  a click event would revel the same.</p>
<p>Your problem in this case is that you need to get the computed style. Try this:</p>
<p><code>getStyle(document.getElementById('imgid'),height);</code></p>
<p>It will work on load using the following function:</p>
<pre><code>/* retrieve the computed style of an element */
function getStyle(element,property) {
    var camelProperty = property.replace(/\-(\w)/g, function (strMatch, p1){ return p1.toUpperCase(); });

    var value = element.style[camelProperty];
    if (!value) {
      if (document.defaultView &amp;&amp; document.defaultView.getComputedStyle) {
        var css = document.defaultView.getComputedStyle(element, null);
        value = css ? css.getPropertyValue(property) : null;
      } else if (element.currentStyle) {
        value = element.currentStyle[camelProperty];
      }
    }
    return value == 'auto' ? '' : value;
}
</code></pre>
<p>The additional problem with using the CSS values to determine sizing is that it doesn&#8217;t necessarily return a numeric number. It could just a easily be a percentage, or a non pixel number (12em). Yo may want to use properties such as offsetHeight though it not part of the DOM spec.</p>
<p>That aside, you are correct, I shouldn&#8217;t use the term &#8216;Never&#8217; as per your other arguments with the yahoo research.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cam Turner</title>
		<link>http://www.camturner.com/2007/01/10-rules-to-code-by/#comment-65</link>
		<dc:creator>Cam Turner</dc:creator>
		<pubDate>Thu, 25 Jan 2007 12:22:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.wecreate.com/articles/10-rules-to-code-by/#comment-65</guid>
		<description>&lt;p&gt;Matt,&lt;/p&gt;

&lt;p&gt;Thank you for the link. I&#039;ve read over the stuff and I think I&#039;ll amend my statement to remove &quot;there is never a valid need&quot; to just &quot;there is never a need&quot; since there are valid reasons (as you&#039;ve shown) when mixing the two might be considered acceptable. However, I still maintain that there is no &quot;need&quot; here, the application will run just fine with a clean separation, even if it is slightly slower.&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Matt,</p>
<p>Thank you for the link. I&#8217;ve read over the stuff and I think I&#8217;ll amend my statement to remove &#8220;there is never a valid need&#8221; to just &#8220;there is never a need&#8221; since there are valid reasons (as you&#8217;ve shown) when mixing the two might be considered acceptable. However, I still maintain that there is no &#8220;need&#8221; here, the application will run just fine with a clean separation, even if it is slightly slower.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cam Turner</title>
		<link>http://www.camturner.com/2007/01/10-rules-to-code-by/#comment-64</link>
		<dc:creator>Cam Turner</dc:creator>
		<pubDate>Thu, 25 Jan 2007 11:53:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.wecreate.com/articles/10-rules-to-code-by/#comment-64</guid>
		<description>&lt;p&gt;The folks over at reddit are talking about this article too and since I don&#039;t feel like signing up for yet another account, I&#039;ll respond to the most flaring comment here.&lt;/p&gt;

&lt;p&gt;&quot;This advice is as dated as demanding that everyone allow for a rich experience with Lynx, or design for a 640x480 screen. Arguments about how the scripting doesn&#039;t improve the site, blah blah, are factless distractions -- it&#039;s a case by case decision, and universally saying that script-requiring sites are bad is inane.&quot;&lt;/p&gt;

&lt;p&gt;I think that if the commenter had read the other rules instead of flying off on a flame they might discovered that I also say don&#039;t expect that every visitor get the same experience, just a functional one. I don&#039;t expect people to avoid JavaScript because Lynx doesn&#039;t do it, I simply expect that -- if engineered correctly from the start -- an alternative method for accessing the content can be given to these visitors.&lt;/p&gt;

&lt;p&gt;&quot;Oh it&#039;s just 10% of people who don&#039;t have JS, so screw &#039;em!&quot; is a very amateur thing to say. Sure millions of sites on the net use exactly that method, but the ones at the top (GMail etc) provide alternative interfaces for their fringe users. They aren&#039;t as pretty or rich. They aren&#039;t as easy to use and definitely don&#039;t feel like desktop software... but they DO work, and they get the job done.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>The folks over at reddit are talking about this article too and since I don&#8217;t feel like signing up for yet another account, I&#8217;ll respond to the most flaring comment here.</p>
<p>&#8220;This advice is as dated as demanding that everyone allow for a rich experience with Lynx, or design for a 640&#215;480 screen. Arguments about how the scripting doesn&#8217;t improve the site, blah blah, are factless distractions &#8212; it&#8217;s a case by case decision, and universally saying that script-requiring sites are bad is inane.&#8221;</p>
<p>I think that if the commenter had read the other rules instead of flying off on a flame they might discovered that I also say don&#8217;t expect that every visitor get the same experience, just a functional one. I don&#8217;t expect people to avoid JavaScript because Lynx doesn&#8217;t do it, I simply expect that &#8212; if engineered correctly from the start &#8212; an alternative method for accessing the content can be given to these visitors.</p>
<p>&#8220;Oh it&#8217;s just 10% of people who don&#8217;t have JS, so screw &#8216;em!&#8221; is a very amateur thing to say. Sure millions of sites on the net use exactly that method, but the ones at the top (GMail etc) provide alternative interfaces for their fringe users. They aren&#8217;t as pretty or rich. They aren&#8217;t as easy to use and definitely don&#8217;t feel like desktop software&#8230; but they DO work, and they get the job done.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://www.camturner.com/2007/01/10-rules-to-code-by/#comment-61</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Thu, 25 Jan 2007 03:45:16 +0000</pubDate>
		<guid isPermaLink="false">http://blog.wecreate.com/articles/10-rules-to-code-by/#comment-61</guid>
		<description>&lt;p&gt;The link to the Yahoo guys page is here. I found it very informative.&lt;/p&gt;

&lt;p&gt;http://yuiblog.com/blog/2007/01/04/performance-research-part-2/&lt;/p&gt;

&lt;p&gt;I shows the break down of what elements are sent to the user and when. Now it is a study on empty cache vs full cache, but the results are quite surprising.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>The link to the Yahoo guys page is here. I found it very informative.</p>
<p><a href="http://yuiblog.com/blog/2007/01/04/performance-research-part-2/" rel="nofollow">http://yuiblog.com/blog/2007/01/04/performance-research-part-2/</a></p>
<p>I shows the break down of what elements are sent to the user and when. Now it is a study on empty cache vs full cache, but the results are quite surprising.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nelz</title>
		<link>http://www.camturner.com/2007/01/10-rules-to-code-by/#comment-59</link>
		<dc:creator>Nelz</dc:creator>
		<pubDate>Thu, 25 Jan 2007 02:08:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.wecreate.com/articles/10-rules-to-code-by/#comment-59</guid>
		<description>&lt;p&gt;While reading this article, and then the comments I went through a couple of phases.  (Especially in reference to &quot;#7: Document or Die&quot;.&lt;/p&gt;

&lt;p&gt;The first phase was of regret.  I used to document up a storm via comments in the old programming language I used for work. (Don&#039;t ask, it wasn&#039;t pleasant...)  When I switch jobs, and languages concurrently, I fell out of the habit.  Yeah, I can partially blame the team environment which didn&#039;t stress/emphasize the commenting, but &lt;em&gt;I&lt;/em&gt; am a member of that team and could have helped to modify that stance.  Lately I have been trying to influence the lack of comments through some coding metrics (JavaNCSS) and publishing the results.&lt;/p&gt;

&lt;p&gt;The second phase was one of contrarianism, spurred on by Peter&#039;s comments.  I am a HUUUGE fan of automated testing.  One of the coolest ideas I ever came across was that though comments may become stale, tests (especially in a Continuous Integration environment) will serve as &lt;em&gt;living&lt;/em&gt; comments.&lt;/p&gt;

&lt;p&gt;Ideally, I would love to see both good comments, and tests serving as living documentation.  On my team, I am striving for that ideal state, but in the meantime our tests will have to do...&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>While reading this article, and then the comments I went through a couple of phases.  (Especially in reference to &#8220;#7: Document or Die&#8221;.</p>
<p>The first phase was of regret.  I used to document up a storm via comments in the old programming language I used for work. (Don&#8217;t ask, it wasn&#8217;t pleasant&#8230;)  When I switch jobs, and languages concurrently, I fell out of the habit.  Yeah, I can partially blame the team environment which didn&#8217;t stress/emphasize the commenting, but <em>I</em> am a member of that team and could have helped to modify that stance.  Lately I have been trying to influence the lack of comments through some coding metrics (JavaNCSS) and publishing the results.</p>
<p>The second phase was one of contrarianism, spurred on by Peter&#8217;s comments.  I am a HUUUGE fan of automated testing.  One of the coolest ideas I ever came across was that though comments may become stale, tests (especially in a Continuous Integration environment) will serve as <em>living</em> comments.</p>
<p>Ideally, I would love to see both good comments, and tests serving as living documentation.  On my team, I am striving for that ideal state, but in the meantime our tests will have to do&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cam Turner</title>
		<link>http://www.camturner.com/2007/01/10-rules-to-code-by/#comment-58</link>
		<dc:creator>Cam Turner</dc:creator>
		<pubDate>Thu, 25 Jan 2007 01:36:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.wecreate.com/articles/10-rules-to-code-by/#comment-58</guid>
		<description>&lt;p&gt;One last point I&#039;d like to make to everyone:&lt;/p&gt;

&lt;p&gt;This article is a SHORT PRIMER. I could easily have written a full 2000 word feature on any of these topics individually, and may do so in the future (the comments here are inspiring). Keep in mind that it&#039;s impossible to cover all aspects of an issue in 3 paragraphs (or less) and I agree with Matt when he says &quot;In programming never say never.&quot;&lt;/p&gt;

&lt;p&gt;In this case I define &quot;never&quot; as &quot;Don&#039;t break one of these rules without another developer on your own team backing up the decision&quot;... which fits nicely with rule #10 :^)&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>One last point I&#8217;d like to make to everyone:</p>
<p>This article is a SHORT PRIMER. I could easily have written a full 2000 word feature on any of these topics individually, and may do so in the future (the comments here are inspiring). Keep in mind that it&#8217;s impossible to cover all aspects of an issue in 3 paragraphs (or less) and I agree with Matt when he says &#8220;In programming never say never.&#8221;</p>
<p>In this case I define &#8220;never&#8221; as &#8220;Don&#8217;t break one of these rules without another developer on your own team backing up the decision&#8221;&#8230; which fits nicely with rule #10 :^)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cam Turner</title>
		<link>http://www.camturner.com/2007/01/10-rules-to-code-by/#comment-57</link>
		<dc:creator>Cam Turner</dc:creator>
		<pubDate>Thu, 25 Jan 2007 01:31:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.wecreate.com/articles/10-rules-to-code-by/#comment-57</guid>
		<description>&lt;p&gt;Hi Pete,&lt;/p&gt;

&lt;p&gt;I had no idea you were reading this too! (Pete was a roommate of mine at UW).&lt;/p&gt;

&lt;p&gt;I know we&#039;ve argued this exact point in the past and I agree in theory with many of your arguments.. things like having exceptional comments stand out, using smaller helper functions instead of bigger ones and having the small ones self-document. I agree and that is an alternative practice that can be equally good, and it would be excellent in a system modeled on MVC especially. In top-down script design I still favour my proposed #7.&lt;/p&gt;

&lt;p&gt;On your &quot;comments lie and 80% is maintenance&quot;, that is true for applications like those you work on. In our case 90% of the scripts we write are written, tested, tweaked, delivered and forgotten. The clients are almost always happy with things as they end up on delivery. The problem arises two years down the road when they want a small change and someone new goes in to make the modification. Provided they ALSO keep the comments current, it does help greatly to use my method (as we&#039;ve Proven at We-Create). Your method might help equally well however.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi Pete,</p>
<p>I had no idea you were reading this too! (Pete was a roommate of mine at UW).</p>
<p>I know we&#8217;ve argued this exact point in the past and I agree in theory with many of your arguments.. things like having exceptional comments stand out, using smaller helper functions instead of bigger ones and having the small ones self-document. I agree and that is an alternative practice that can be equally good, and it would be excellent in a system modeled on MVC especially. In top-down script design I still favour my proposed #7.</p>
<p>On your &#8220;comments lie and 80% is maintenance&#8221;, that is true for applications like those you work on. In our case 90% of the scripts we write are written, tested, tweaked, delivered and forgotten. The clients are almost always happy with things as they end up on delivery. The problem arises two years down the road when they want a small change and someone new goes in to make the modification. Provided they ALSO keep the comments current, it does help greatly to use my method (as we&#8217;ve Proven at We-Create). Your method might help equally well however.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter McCurdy</title>
		<link>http://www.camturner.com/2007/01/10-rules-to-code-by/#comment-56</link>
		<dc:creator>Peter McCurdy</dc:creator>
		<pubDate>Thu, 25 Jan 2007 01:14:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.wecreate.com/articles/10-rules-to-code-by/#comment-56</guid>
		<description>&lt;p&gt;Regarding my comment above, notice the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Your business logic is now perfectly obvious, so much so that I removed its description from the function header description due to utter redundancy.&lt;/li&gt;
&lt;li&gt;Your business logic function doesn&#039;t use any global variables.&lt;/li&gt;
&lt;li&gt;Your global variables are declared next to the code that uses them (PS: is $conn global or not?)&lt;/li&gt;
&lt;li&gt;You now have some helper routines for dealing with OTTs in the future, to pre-emptively get rid of code duplication.&lt;/li&gt;
&lt;li&gt;You don&#039;t need any comments inside functions; the comments became the function names.  You might want to put in descriptions of the parameters and return values, but it&#039;s not ultra-critical.&lt;/li&gt;
&lt;li&gt;It&#039;s obvious which parts of the code use the OTT itself, and which use its database values.  This was particularly non-obvious in your original code (I didn&#039;t notice the extract() at first, and had to go rewrite some of this).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The get_ott_data function is a bit ugly in how it&#039;s used, but I didn&#039;t feel like writing a OneTimeTicket class or anything crazy.&lt;/p&gt;

&lt;p&gt;Reasonable people could disagree on this, I suppose.  But 80% of programming is maintenance, and my experience maintaining large programs is that comments lie, large functions are buggy, and small functions let you skim code faster and see what&#039;s going on.  Plus if you save comments for the truly exceptional, weird situations, then they really stand out and you don&#039;t gloss over them.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Regarding my comment above, notice the following:</p>
<ol>
<li>Your business logic is now perfectly obvious, so much so that I removed its description from the function header description due to utter redundancy.</li>
<li>Your business logic function doesn&#8217;t use any global variables.</li>
<li>Your global variables are declared next to the code that uses them (PS: is $conn global or not?)</li>
<li>You now have some helper routines for dealing with OTTs in the future, to pre-emptively get rid of code duplication.</li>
<li>You don&#8217;t need any comments inside functions; the comments became the function names.  You might want to put in descriptions of the parameters and return values, but it&#8217;s not ultra-critical.</li>
<li>It&#8217;s obvious which parts of the code use the OTT itself, and which use its database values.  This was particularly non-obvious in your original code (I didn&#8217;t notice the extract() at first, and had to go rewrite some of this).</li>
</ol>
<p>The get_ott_data function is a bit ugly in how it&#8217;s used, but I didn&#8217;t feel like writing a OneTimeTicket class or anything crazy.</p>
<p>Reasonable people could disagree on this, I suppose.  But 80% of programming is maintenance, and my experience maintaining large programs is that comments lie, large functions are buggy, and small functions let you skim code faster and see what&#8217;s going on.  Plus if you save comments for the truly exceptional, weird situations, then they really stand out and you don&#8217;t gloss over them.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cam Turner</title>
		<link>http://www.camturner.com/2007/01/10-rules-to-code-by/#comment-55</link>
		<dc:creator>Cam Turner</dc:creator>
		<pubDate>Thu, 25 Jan 2007 01:13:31 +0000</pubDate>
		<guid isPermaLink="false">http://blog.wecreate.com/articles/10-rules-to-code-by/#comment-55</guid>
		<description>&lt;p&gt;Hi Matt,&lt;/p&gt;

&lt;p&gt;We&#039;re usually paying attention to this blog in the morning and evenings.. between we&#039;re busy writing software so please don&#039;t take offense.&lt;/p&gt;

&lt;p&gt;I&#039;d love to see this article from Yahoo. Can you post a link? Until you can back up the numbers I&#039;m going to reserve judgment entirely, as you are arguing quite well. &lt;/p&gt;

&lt;p&gt;Your points above are valid and they even jive with rule #2 which in a nut shell says: if something has to be either hard on the user or hard on the developer then it should always be hard on the developer since we have an easier time understanding why, and the phone rings less :)&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi Matt,</p>
<p>We&#8217;re usually paying attention to this blog in the morning and evenings.. between we&#8217;re busy writing software so please don&#8217;t take offense.</p>
<p>I&#8217;d love to see this article from Yahoo. Can you post a link? Until you can back up the numbers I&#8217;m going to reserve judgment entirely, as you are arguing quite well. </p>
<p>Your points above are valid and they even jive with rule #2 which in a nut shell says: if something has to be either hard on the user or hard on the developer then it should always be hard on the developer since we have an easier time understanding why, and the phone rings less <img src='http://www.camturner.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter McCurdy</title>
		<link>http://www.camturner.com/2007/01/10-rules-to-code-by/#comment-54</link>
		<dc:creator>Peter McCurdy</dc:creator>
		<pubDate>Thu, 25 Jan 2007 01:09:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.wecreate.com/articles/10-rules-to-code-by/#comment-54</guid>
		<description>&lt;p&gt;I have to say, I disagree about #7.  The fundamental problem is that a comment (a) only describes what you &lt;em&gt;think&lt;/em&gt; the code does and (b) only at the time you wrote the comment.  In any sort of long-term maintenance situation, almost all comments turn into lies.  The function header comments are sort of nice, if they&#039;re high-level enough.  But I&#039;ve pretty much decided that if you need a comment to describe your actual code, your code isn&#039;t legible enough.&lt;/p&gt;

&lt;p&gt;Compare your function to:&lt;/p&gt;

&lt;pre&gt;
/**
 * Validate the authenticity of a 32-character MD5 one time ticket.
 *
 * Used primarily in the login function before comparing hashes sent by the user.
 *
 * @param resource $conn The connection to the database
 * @param string $ott The one time ticket hash
 * @return boolean true if valid, false otherwise
 * @author Cam Turner 
 * @see http://en.wikipedia.org/wiki/Cryptographic_nonce
 */ 
function validate_one_time_ticket($conn,$ott) {
    if (!check_type($ott,&#039;MD5&#039;)) { return false; }

    $ott_data = get_ott_data($ott);

    if ($ott_data == array()) { return false; }
    if (!consume_ott($ott)) { return false; }
    if (is_ticket_expired($ott_data) { return false; }    

    return true;
}

function get_ott_data($ott) {
    global $conn;
    $query = db_query($conn,&quot;SELECT * FROM one_time_tickets WHERE one_time_ticket=&#039;$ott&#039;&quot;);
    if ((!$query) &#124;&#124; (db_numrows($query) != 1)) { return array(); }
    return db_fetch_array($query,0);
}

function consume_ott($ott) {
    global $conn;
    $query = db_query($conn,&quot;DELETE FROM one_time_tickets WHERE one_time_ticket=&#039;$ott&#039;&quot;);
    return !!$query;
}

function is_ticket_expired($ott_arr) {
    global $AUTHENT_CONFIG;
    $ttl = $AUTHENT_CONFIG[&#039;ttl&#039;]; // integer seconds
    $expiry = strtotime($ott_arr[&#039;time_issued&#039;]) + $ttl;
    $now = time();
    return ($expiry &lt;= $now);
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I have to say, I disagree about #7.  The fundamental problem is that a comment (a) only describes what you <em>think</em> the code does and (b) only at the time you wrote the comment.  In any sort of long-term maintenance situation, almost all comments turn into lies.  The function header comments are sort of nice, if they&#8217;re high-level enough.  But I&#8217;ve pretty much decided that if you need a comment to describe your actual code, your code isn&#8217;t legible enough.</p>
<p>Compare your function to:</p>
<pre>
/**
 * Validate the authenticity of a 32-character MD5 one time ticket.
 *
 * Used primarily in the login function before comparing hashes sent by the user.
 *
 * @param resource $conn The connection to the database
 * @param string $ott The one time ticket hash
 * @return boolean true if valid, false otherwise
 * @author Cam Turner
 * @see <a href="http://en.wikipedia.org/wiki/Cryptographic_nonce" rel="nofollow">http://en.wikipedia.org/wiki/Cryptographic_nonce</a>
 */
function validate_one_time_ticket($conn,$ott) {
    if (!check_type($ott,'MD5')) { return false; }

    $ott_data = get_ott_data($ott);

    if ($ott_data == array()) { return false; }
    if (!consume_ott($ott)) { return false; }
    if (is_ticket_expired($ott_data) { return false; }    

    return true;
}

function get_ott_data($ott) {
    global $conn;
    $query = db_query($conn,"SELECT * FROM one_time_tickets WHERE one_time_ticket='$ott'");
    if ((!$query) || (db_numrows($query) != 1)) { return array(); }
    return db_fetch_array($query,0);
}

function consume_ott($ott) {
    global $conn;
    $query = db_query($conn,"DELETE FROM one_time_tickets WHERE one_time_ticket='$ott'");
    return !!$query;
}

function is_ticket_expired($ott_arr) {
    global $AUTHENT_CONFIG;
    $ttl = $AUTHENT_CONFIG['ttl']; // integer seconds
    $expiry = strtotime($ott_arr['time_issued']) + $ttl;
    $now = time();
    return ($expiry < = $now);
}
</pre>
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>
