<?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: Comments vs. Self Documenting Code</title>
	<atom:link href="http://cowboyprogramming.com/2007/02/14/comments-vs-self-documenting-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://cowboyprogramming.com/2007/02/14/comments-vs-self-documenting-code/</link>
	<description>Game Development and General Hacking by the Old West</description>
	<lastBuildDate>Tue, 20 Jul 2010 15:03:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Matt Kukowski</title>
		<link>http://cowboyprogramming.com/2007/02/14/comments-vs-self-documenting-code/comment-page-1/#comment-145768</link>
		<dc:creator>Matt Kukowski</dc:creator>
		<pubDate>Sat, 16 Jan 2010 22:55:11 +0000</pubDate>
		<guid isPermaLink="false">http://cowboyprogramming.com/2007/02/14/comments-vs-self-documenting-code/#comment-145768</guid>
		<description>I think the answer is simple. 

1) Write self documenting code _at all times, regardless.

2) Create javaDoc style long comments for each and every function/method. This way you can run a tool to autogenerate API documents, at the same time comment your code!

3) Do NOT comment every single line, or every other line. Instead, use point #2 I mentioned above. For a complex LOOP algorythm a couple lines of comments may be good. HOWEVER, if the LOOP or if/else code block is so non-obvious, maybe it needs to be refactored into a function/method! in which case point #2 will satisfy the commenting.</description>
		<content:encoded><![CDATA[<p>I think the answer is simple. </p>
<p>1) Write self documenting code _at all times, regardless.</p>
<p>2) Create javaDoc style long comments for each and every function/method. This way you can run a tool to autogenerate API documents, at the same time comment your code!</p>
<p>3) Do NOT comment every single line, or every other line. Instead, use point #2 I mentioned above. For a complex LOOP algorythm a couple lines of comments may be good. HOWEVER, if the LOOP or if/else code block is so non-obvious, maybe it needs to be refactored into a function/method! in which case point #2 will satisfy the commenting.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: acotvybuge</title>
		<link>http://cowboyprogramming.com/2007/02/14/comments-vs-self-documenting-code/comment-page-1/#comment-60945</link>
		<dc:creator>acotvybuge</dc:creator>
		<pubDate>Thu, 13 Nov 2008 21:59:13 +0000</pubDate>
		<guid isPermaLink="false">http://cowboyprogramming.com/2007/02/14/comments-vs-self-documenting-code/#comment-60945</guid>
		<description>&lt;a href=&quot;http://eleanoresc.canalblog.com&quot; rel=&quot;nofollow&quot;&gt;win super bowl tickets&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p><a href="http://eleanoresc.canalblog.com" rel="nofollow">win super bowl tickets</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cum</title>
		<link>http://cowboyprogramming.com/2007/02/14/comments-vs-self-documenting-code/comment-page-1/#comment-14346</link>
		<dc:creator>cum</dc:creator>
		<pubDate>Sun, 06 Apr 2008 07:01:23 +0000</pubDate>
		<guid isPermaLink="false">http://cowboyprogramming.com/2007/02/14/comments-vs-self-documenting-code/#comment-14346</guid>
		<description>Who are you more than you think i got out ofthe bus. And pushed &lt;a href=&quot;http://onfeet.blogair.net&quot; rel=&quot;nofollow&quot;&gt;cum on feet&lt;/a&gt; her. Who are you little flirt. Not &lt;a href=&quot;http://makeme.yourweblog.net&quot; rel=&quot;nofollow&quot;&gt;make me cum&lt;/a&gt;  very excited.</description>
		<content:encoded><![CDATA[<p>Who are you more than you think i got out ofthe bus. And pushed <a href="http://onfeet.blogair.net" rel="nofollow">cum on feet</a> her. Who are you little flirt. Not <a href="http://makeme.yourweblog.net" rel="nofollow">make me cum</a>  very excited.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DamionKutaeff</title>
		<link>http://cowboyprogramming.com/2007/02/14/comments-vs-self-documenting-code/comment-page-1/#comment-13635</link>
		<dc:creator>DamionKutaeff</dc:creator>
		<pubDate>Sat, 22 Mar 2008 20:00:25 +0000</pubDate>
		<guid isPermaLink="false">http://cowboyprogramming.com/2007/02/14/comments-vs-self-documenting-code/#comment-13635</guid>
		<description>Hello everybody, my name is Damion, and I&#039;m glad to join your conmunity, 
and wish to assit as far as possible.</description>
		<content:encoded><![CDATA[<p>Hello everybody, my name is Damion, and I&#8217;m glad to join your conmunity,<br />
and wish to assit as far as possible.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick</title>
		<link>http://cowboyprogramming.com/2007/02/14/comments-vs-self-documenting-code/comment-page-1/#comment-4838</link>
		<dc:creator>Nick</dc:creator>
		<pubDate>Tue, 23 Oct 2007 11:50:58 +0000</pubDate>
		<guid isPermaLink="false">http://cowboyprogramming.com/2007/02/14/comments-vs-self-documenting-code/#comment-4838</guid>
		<description>I think really what comments need to convey is your thought process whilst writing the code. I agree with the Pragmatic Programmer mantra. I comment my code because I often come back to something six months later and can’t remember why I wrote it exactly like that. What was I thinking that day? By the time you finish reading the code you should understand where the person who wrote it was going with it. Long, complex projects are often a learning experience and the simple concepts you used at the start may evolve. 

It’s interesting when people say they don’t need to comment their code. As mentioned earlier, in a small cohesive team, or solo, perhaps you can get away with this because you all talk so regularly and you’re sitting 6 feet away from the guy who wrote it. I’ve worked in teams like that and it does work if you can nudge that guy and ask him a question. But what if he leaves?

If you’re on a 50 programmer team, chances are on a big team everyone’s code is interleaved with everyone else, and then you’re in the position of perhaps trying VCS history to find who wrote those lines, etc, etc. And when you do find that person, will they remember why they wrote those lines? So the point is about communicating your ideas to other people, albeit concisely. If you need to write an essay, or convey user documentation to end users (e.g. designers or artists) then there is the wiki. If you based something on a paper or external web link, cite it.

It’s pointless (and distracting) when people explain exactly what the code that follows says (i.e. not why it was written). If it doesn’t add anything to what the source code says then a comment is almost worthless. What we need is the _purpose_ of the code. What were you _thinking_ when you typed those lines in. As we travel through the execution of the code what is the sequence of events?

Comments detailing the future plans for code are useful, perhaps to save wasted labour, or find out what you&#039;re getting into. E.g.

&lt;code&gt;
// Bob: Jim asked me to fix this function for milestone 4. Time was tight
//    so I&#039;ve gone for a simple fix and made the array bigger. Really this
//    should be made into a linked list but too much to do.

// Andy: I haven&#039;t written an algorithm like this before so I&#039;ve done my
//     best to keep it simple. Please let me know if you have any problems.

// Ted: I&#039;m going to rewrite this class when I get time. System X is
//      being refactored because it uses too much memory which means
//      this class needs changing.

// Fred: I fixed a threading glitch in here with a mutex but performance 
//      is terrible. Need to refactor this whole class.
&lt;/code&gt;

I think one of the main reasons people don&#039;t write good comments is they don&#039;t schedule for them, or under time pressure they are the first thing to get cut. Good commenting involves examples (code snippets) and samples (full programs) which takes a lot of time. Rapid explanation of what is there, after the fact, takes less time, and a lot of programmers would rather just program.

Also, as mentioned, a lot of people think their code doesn&#039;t need explanation. One trick I learnt is to go and get a coffee and when you come back, imagine you are sitting down to look at the code you wrote for the first time (as though you are someone else). Now fill the comments and examples you think you would like to see.</description>
		<content:encoded><![CDATA[<p>I think really what comments need to convey is your thought process whilst writing the code. I agree with the Pragmatic Programmer mantra. I comment my code because I often come back to something six months later and can’t remember why I wrote it exactly like that. What was I thinking that day? By the time you finish reading the code you should understand where the person who wrote it was going with it. Long, complex projects are often a learning experience and the simple concepts you used at the start may evolve. </p>
<p>It’s interesting when people say they don’t need to comment their code. As mentioned earlier, in a small cohesive team, or solo, perhaps you can get away with this because you all talk so regularly and you’re sitting 6 feet away from the guy who wrote it. I’ve worked in teams like that and it does work if you can nudge that guy and ask him a question. But what if he leaves?</p>
<p>If you’re on a 50 programmer team, chances are on a big team everyone’s code is interleaved with everyone else, and then you’re in the position of perhaps trying VCS history to find who wrote those lines, etc, etc. And when you do find that person, will they remember why they wrote those lines? So the point is about communicating your ideas to other people, albeit concisely. If you need to write an essay, or convey user documentation to end users (e.g. designers or artists) then there is the wiki. If you based something on a paper or external web link, cite it.</p>
<p>It’s pointless (and distracting) when people explain exactly what the code that follows says (i.e. not why it was written). If it doesn’t add anything to what the source code says then a comment is almost worthless. What we need is the _purpose_ of the code. What were you _thinking_ when you typed those lines in. As we travel through the execution of the code what is the sequence of events?</p>
<p>Comments detailing the future plans for code are useful, perhaps to save wasted labour, or find out what you&#8217;re getting into. E.g.</p>
<p><code><br />
// Bob: Jim asked me to fix this function for milestone 4. Time was tight<br />
//    so I've gone for a simple fix and made the array bigger. Really this<br />
//    should be made into a linked list but too much to do.</p>
<p>// Andy: I haven't written an algorithm like this before so I've done my<br />
//     best to keep it simple. Please let me know if you have any problems.</p>
<p>// Ted: I'm going to rewrite this class when I get time. System X is<br />
//      being refactored because it uses too much memory which means<br />
//      this class needs changing.</p>
<p>// Fred: I fixed a threading glitch in here with a mutex but performance<br />
//      is terrible. Need to refactor this whole class.<br />
</code></p>
<p>I think one of the main reasons people don&#8217;t write good comments is they don&#8217;t schedule for them, or under time pressure they are the first thing to get cut. Good commenting involves examples (code snippets) and samples (full programs) which takes a lot of time. Rapid explanation of what is there, after the fact, takes less time, and a lot of programmers would rather just program.</p>
<p>Also, as mentioned, a lot of people think their code doesn&#8217;t need explanation. One trick I learnt is to go and get a coffee and when you come back, imagine you are sitting down to look at the code you wrote for the first time (as though you are someone else). Now fill the comments and examples you think you would like to see.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eigenvector</title>
		<link>http://cowboyprogramming.com/2007/02/14/comments-vs-self-documenting-code/comment-page-1/#comment-2309</link>
		<dc:creator>Eigenvector</dc:creator>
		<pubDate>Mon, 09 Jul 2007 19:44:40 +0000</pubDate>
		<guid isPermaLink="false">http://cowboyprogramming.com/2007/02/14/comments-vs-self-documenting-code/#comment-2309</guid>
		<description>&lt;blockquote cite=&quot;Mick&quot;&gt;If you are implementing something described in comments, the comments may become partially redundant&lt;/blockquote&gt;

Of course comments describing the implementation will be redundant, but I totally disagree with the notion that this might be a bad thing.  

This seems to be the main argument behind the &quot;my code is self documenting&quot; camp:  comments = redundant = bad.

I don&#039;t care how clear anyone thinks their code is, it&#039;s always going to take more lines of code to explain something to a computer than it takes lines of English to explain the same thing to an English-speaker. The reason for this is that language can be vague, but code cannot be.

If you don&#039;t write comments, you are basically forcing everyone to run your code in their head, reverse engineering to understand it.  Good programmers ought to have the skill to do that, but nobody wants to have to read code when they can just have someone else explain it to them.  In fact I&#039;ve seen plenty of cases where people just go off and write a brand new version of the same code just because they didn&#039;t want to have to reverse engineer the original.  Usually because the original didn&#039;t have any comments and the guy who wrote it quit.

Please please please if you believe your code is so clean it does not need comment, step off the ego horse and help your fellow programmers out by putting some comments in anyhow.</description>
		<content:encoded><![CDATA[<blockquote cite="Mick"><p>If you are implementing something described in comments, the comments may become partially redundant</p></blockquote>
<p>Of course comments describing the implementation will be redundant, but I totally disagree with the notion that this might be a bad thing.  </p>
<p>This seems to be the main argument behind the &#8220;my code is self documenting&#8221; camp:  comments = redundant = bad.</p>
<p>I don&#8217;t care how clear anyone thinks their code is, it&#8217;s always going to take more lines of code to explain something to a computer than it takes lines of English to explain the same thing to an English-speaker. The reason for this is that language can be vague, but code cannot be.</p>
<p>If you don&#8217;t write comments, you are basically forcing everyone to run your code in their head, reverse engineering to understand it.  Good programmers ought to have the skill to do that, but nobody wants to have to read code when they can just have someone else explain it to them.  In fact I&#8217;ve seen plenty of cases where people just go off and write a brand new version of the same code just because they didn&#8217;t want to have to reverse engineer the original.  Usually because the original didn&#8217;t have any comments and the guy who wrote it quit.</p>
<p>Please please please if you believe your code is so clean it does not need comment, step off the ego horse and help your fellow programmers out by putting some comments in anyhow.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mick West</title>
		<link>http://cowboyprogramming.com/2007/02/14/comments-vs-self-documenting-code/comment-page-1/#comment-97</link>
		<dc:creator>Mick West</dc:creator>
		<pubDate>Thu, 22 Feb 2007 16:36:32 +0000</pubDate>
		<guid isPermaLink="false">http://cowboyprogramming.com/2007/02/14/comments-vs-self-documenting-code/#comment-97</guid>
		<description>&lt;blockquote&gt;The comment roughly said: “the comment you want to write to document a function shall be written before you write any code”. It makes sense, since you have no choice but to express your intent - you have no code to paraphrase, so it should be easier.&lt;/blockquote&gt;

That&#039;s fine in limited way.  But in practice there are a number of objections to that idea:
- If you are implementing something described in comments, the comments may become partially redundant
- Decisions in implementing a function may be made after the initial comment is written, which will require a change to the comment, or an additional comment.

In Poker there is a theory that says your ideal  bet should be what you would bet if you knew what your opponent&#039;s cards were.  While this is obviously impossible, it still serves as a yardstick to measure your actual bet by.  

Similarly with comments - perhaps the ideal comment would be one you would write before the code is written, but as if you knew exactly what code you were going to write, even if you actually write it after the code is written.</description>
		<content:encoded><![CDATA[<blockquote><p>The comment roughly said: “the comment you want to write to document a function shall be written before you write any code”. It makes sense, since you have no choice but to express your intent &#8211; you have no code to paraphrase, so it should be easier.</p></blockquote>
<p>That&#8217;s fine in limited way.  But in practice there are a number of objections to that idea:<br />
- If you are implementing something described in comments, the comments may become partially redundant<br />
- Decisions in implementing a function may be made after the initial comment is written, which will require a change to the comment, or an additional comment.</p>
<p>In Poker there is a theory that says your ideal  bet should be what you would bet if you knew what your opponent&#8217;s cards were.  While this is obviously impossible, it still serves as a yardstick to measure your actual bet by.  </p>
<p>Similarly with comments &#8211; perhaps the ideal comment would be one you would write before the code is written, but as if you knew exactly what code you were going to write, even if you actually write it after the code is written.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Emmanuel Deloget</title>
		<link>http://cowboyprogramming.com/2007/02/14/comments-vs-self-documenting-code/comment-page-1/#comment-96</link>
		<dc:creator>Emmanuel Deloget</dc:creator>
		<pubDate>Thu, 22 Feb 2007 13:43:24 +0000</pubDate>
		<guid isPermaLink="false">http://cowboyprogramming.com/2007/02/14/comments-vs-self-documenting-code/#comment-96</guid>
		<description>A GameDev.Net thread about comments that I missed! How blind I am! :)

I&#039;m also quite proud of my ability to write code that needs very little comments - but I&#039;m ashamed that when I need to write comments, they are often poor and uninformative. I blogged on this subject a while back (sorry, it&#039;s in French...) and I got a comment back (no pun intended) that I found quite interesting. The comment roughly said: &quot;the comment you want to write to document a function shall be written before your write any code&quot;. It makes sense, since you have no choice but to express your intent - you have no code to paraphrase, so it should be easier. Moreover, it&#039;s often when you need to write a function that you have the best comprehension of what it should do - once it is written, your brain doesn&#039;t keep track of the creation process, and most of the time you forget the original goal of the function. 

Of course, it&#039;s a bit difficult to apply this practice when you want to modify an existing function.</description>
		<content:encoded><![CDATA[<p>A GameDev.Net thread about comments that I missed! How blind I am! :)</p>
<p>I&#8217;m also quite proud of my ability to write code that needs very little comments &#8211; but I&#8217;m ashamed that when I need to write comments, they are often poor and uninformative. I blogged on this subject a while back (sorry, it&#8217;s in French&#8230;) and I got a comment back (no pun intended) that I found quite interesting. The comment roughly said: &#8220;the comment you want to write to document a function shall be written before your write any code&#8221;. It makes sense, since you have no choice but to express your intent &#8211; you have no code to paraphrase, so it should be easier. Moreover, it&#8217;s often when you need to write a function that you have the best comprehension of what it should do &#8211; once it is written, your brain doesn&#8217;t keep track of the creation process, and most of the time you forget the original goal of the function. </p>
<p>Of course, it&#8217;s a bit difficult to apply this practice when you want to modify an existing function.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mick West</title>
		<link>http://cowboyprogramming.com/2007/02/14/comments-vs-self-documenting-code/comment-page-1/#comment-67</link>
		<dc:creator>Mick West</dc:creator>
		<pubDate>Thu, 15 Feb 2007 19:54:10 +0000</pubDate>
		<guid isPermaLink="false">http://cowboyprogramming.com/2007/02/14/comments-vs-self-documenting-code/#comment-67</guid>
		<description>Nicely put.  Newbies of course don&#039;t get the big picture, and can be quite impressionable.  Which is why I get annoyed when I see what seems to be simplifications.  I&#039;ve worked with people where their initial exposure to some half-baked methodology has ossified into dogma.  This is why I place &quot;methodological&quot; below &quot;pragmatic&quot; (and only slightly above &quot;delusional&quot;) in my (tongue in cheek) &lt;a href=&quot;http://cowboyprogramming.com/2007/01/18/the-seven-stages-of-programming/&quot; rel=&quot;nofollow&quot;&gt;Seven Stages of the Programmer&lt;/a&gt;

Most newbies, unfortunately, are still at stage 3, &quot;Fumbling&quot;, poised for an inevitable journey through &quot;Delusional&quot;.  One can only help them avoid a few of the obstacles.</description>
		<content:encoded><![CDATA[<p>Nicely put.  Newbies of course don&#8217;t get the big picture, and can be quite impressionable.  Which is why I get annoyed when I see what seems to be simplifications.  I&#8217;ve worked with people where their initial exposure to some half-baked methodology has ossified into dogma.  This is why I place &#8220;methodological&#8221; below &#8220;pragmatic&#8221; (and only slightly above &#8220;delusional&#8221;) in my (tongue in cheek) <a href="http://cowboyprogramming.com/2007/01/18/the-seven-stages-of-programming/" rel="nofollow">Seven Stages of the Programmer</a></p>
<p>Most newbies, unfortunately, are still at stage 3, &#8220;Fumbling&#8221;, poised for an inevitable journey through &#8220;Delusional&#8221;.  One can only help them avoid a few of the obstacles.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Washu</title>
		<link>http://cowboyprogramming.com/2007/02/14/comments-vs-self-documenting-code/comment-page-1/#comment-66</link>
		<dc:creator>Washu</dc:creator>
		<pubDate>Thu, 15 Feb 2007 18:07:17 +0000</pubDate>
		<guid isPermaLink="false">http://cowboyprogramming.com/2007/02/14/comments-vs-self-documenting-code/#comment-66</guid>
		<description>&lt;blockquote&gt;I’m curious as to why you’ve spent years on gamedev.net giving your opinion regarding a field you have no interest in entering.&lt;/blockquote&gt;
Yeah, I get that question often enough. Ultimately the answer boils down to this: Developers come from all places, great and small. GameDev.Net tends to be one of the larger communities that is developer oriented (although we hope to change that such that its not just a programming haven but a haven to the full development process for games, any help or suggestions in getting us to achieve that end would be welcome). I also hang out in a lot of other places, such as comp.object, comp.lang.c++.moderated, and comp.std.c++ for example. But ultimately, the majority of newbies will be introduced to programming through something that they feel is fun. Games tend to be fun, so what better way to have fun than to develop your own games? Thus I try and dispense what knowledge I have to those newbies who visit gamedev.net in the hopes that those few of them with a real spark of potential will use that help to grow that spark into a full fledged conflagration.
&lt;blockquote&gt;I’m a big fan of readable code, especially meaningful names. Some people just seem to be adverse to typing, and abbreviate everything. However I see nothing wrong with using i for an iterator in the situation where it’s the sole iterator in the function. Also, x,y,z and w obviously have their usages when mirroring their algebraic equivalents.&lt;/blockquote&gt;
Indeed! There is nothing wrong with i as an iterator, x, y, and z as variables or vectors, heck, I’ve even used latex subscripting before when writing out mathematical expressions in various languages. The problem as I see it revolves around what we teach our young protégées though. Do we teach them to use meaningful names and to write code that is clean and readable? Or do we point them to books like “Game Programming All in One” or other such examples that claim to teach you everything you need?
&lt;blockquote&gt;But yes, code should be readable, and comments help. You seem to be vigorously arguing against comments, while at the same time saying they are sometimes useful. What your argument boils down to is “writing bad comments is harmful”, which is a tautology, and not particularly useful.&lt;/blockquote&gt;
It is hard to put exactly what I’m trying to say into words, but I’ll give it a shot: People often use comments as a means of excusing themselves from writing clean code. As code complete notes, your code should say HOW it works, but your comments should say why you’re doing it. But more often than not I encounter code that says nothing about the how or the why of the code, and a heck of a lot about why the previous programmers quit. It does tend to have plenty of comments though detailing the HOW of it.
That being said, a good comment can be worth a thousand lines of code, or an hours work of prototyping and testing to understand the various ways in which a piece of code will be applied. But it shouldn’t be detailing why you’ve decided to use a state pattern. That information should be more centralized, in a place easy for everyone to access. 
&lt;blockquote&gt;I’m not clear on what your position is on Doxygen style documentation. It seems optimal to me to keep the documentation in the function header comment. How is that bloating the file with useless information? &lt;/blockquote&gt;
It does? Imagine for a second that the MSDN documentation was embedded in the API headers, would this be optimal? Hardly, digging through those headers is already a pain, littering it with comments just exasperates the problem. Now, preliminary documentation, or interface documentation tends to be a good idea though. Sometimes you just right click -&gt; Go to definition. Which takes you to the function declaration and BAM, you’ve got a nice comment there that tells you what the parameters mean. I certainly wish ruby’s C interface had such niceties. But a full documentation of the function and its corner cases and the various other issues it might have tend to be outside the scope of a comment block. It just doesn’t belong there.
&lt;blockquote&gt;Developers log: How is this notebook going to help you? And why a physical notebook? It seems a little hard to share with the team.&lt;/blockquote&gt;
I actually keep both a document (that’s in source control), and a notebook as well. The notebook is nice because its something I can flip through while I’m in a design session with other architects, to look at past examples, and because I can scribble in it, make crude drawings and drafts next to various decisions. Those drafts can later be turned into nice diagrams which get embedded into the document. But scribbling around on paper is a lot faster than drawing in paint or Visio, and it gives me time to relax the hands.
&lt;blockquote&gt;Speaking of teams, I know you’ve worked in team environments, but it seems your strong adherence to few comments, and reliance on the self-documenting nature of your code, speaks to a very small cohesive team, or to solo work. In game development the team is often large, variegated and in flux. Code that is self documenting to you might be confusing to another team member. Explanatory comments are useful time savers here. Conversely, not everyone programs to your high standard, and you might appreciate some good comments in unfamiliar code.&lt;/blockquote&gt;
Depends, the projects we work on tend to be divided up such that many small teams can work independently with an architect per team. These teams produce artifacts that the architects write integration and feature tests for, thus ensuring that the end product both integrates properly, and that the features that the customer requires are in place. Since we involve the customer heavily in the process of feature determination throughout development, the customer ends up helping to write (and often actually writes a large chunk of) the acceptance tests (feature tests). We’ve found this method tends to help build a much more agile set of components, even when the application gets to be very large.

Actually, the reality is that refactoring can’t simplify all problems. It can make some particular design decisions clearer, it can make some code problems clearer, but it is not a silver bullet. Some problems resist refactoring simply because of the problem. In those cases, a good comment can save minutes of useless refactoring, and hours of a maintenance developer’s time. But yes, you are also right in that there are other cases where comments are appropriate. Let us take for instance the volume of a parallelepiped, it can be taken as either the absolute value of the scalar triple product, or as the absolute value of the determinant of a 3x3 matrix such that the row-vectors are the axis vectors of the parallelepiped. Now, which one do you choose? Which one is simpler to code, and which one is more efficient? It turns out that both reduce to basically the same code, so you can choose either and be equally as efficient. But which one is clearer to the viewer as to what you are trying to do? Who knows, but a nice comment explaining WHY you chose the determinant method over the scalar-triple-product would go a long way to clearing that up. This is a decision that really doesn’t belong in the developer’s log, as it is not really a design decision, more of an algorithmic one. These are things I would put comments in for as well. The same thing is true of your choices for data structures. Lets say you chose std::map over std::tr1::unordered_map, you would probably want to make note of the WHY there… “//Need worst case complexity of O(log n) for lookup” Perfectly acceptable, and in fact I would say that it should be encouraged.
But teaching people how to comment is hard. VERY hard. It is just like coding, but you have to be far more careful, since your comments may make or break another’s understanding of the code to which you have applied the comments. So, instead of saying “yeah, you should use comments” I would rather say “Write clean code. Then worry about comments.” However, I should really say is this “Write clean code, comment clean code, read code complete 2nd edition.” Except I’ve found that for most newbies that doesn’t work. They want to write their games starting in C++ and using “Learn C++ in 21 Days” and “Game Programming All in One”. But you are right, I should be clarifying how to comment more than just discouraging it.</description>
		<content:encoded><![CDATA[<blockquote><p>I’m curious as to why you’ve spent years on gamedev.net giving your opinion regarding a field you have no interest in entering.</p></blockquote>
<p>Yeah, I get that question often enough. Ultimately the answer boils down to this: Developers come from all places, great and small. GameDev.Net tends to be one of the larger communities that is developer oriented (although we hope to change that such that its not just a programming haven but a haven to the full development process for games, any help or suggestions in getting us to achieve that end would be welcome). I also hang out in a lot of other places, such as comp.object, comp.lang.c++.moderated, and comp.std.c++ for example. But ultimately, the majority of newbies will be introduced to programming through something that they feel is fun. Games tend to be fun, so what better way to have fun than to develop your own games? Thus I try and dispense what knowledge I have to those newbies who visit gamedev.net in the hopes that those few of them with a real spark of potential will use that help to grow that spark into a full fledged conflagration.</p>
<blockquote><p>I’m a big fan of readable code, especially meaningful names. Some people just seem to be adverse to typing, and abbreviate everything. However I see nothing wrong with using i for an iterator in the situation where it’s the sole iterator in the function. Also, x,y,z and w obviously have their usages when mirroring their algebraic equivalents.</p></blockquote>
<p>Indeed! There is nothing wrong with i as an iterator, x, y, and z as variables or vectors, heck, I’ve even used latex subscripting before when writing out mathematical expressions in various languages. The problem as I see it revolves around what we teach our young protégées though. Do we teach them to use meaningful names and to write code that is clean and readable? Or do we point them to books like “Game Programming All in One” or other such examples that claim to teach you everything you need?</p>
<blockquote><p>But yes, code should be readable, and comments help. You seem to be vigorously arguing against comments, while at the same time saying they are sometimes useful. What your argument boils down to is “writing bad comments is harmful”, which is a tautology, and not particularly useful.</p></blockquote>
<p>It is hard to put exactly what I’m trying to say into words, but I’ll give it a shot: People often use comments as a means of excusing themselves from writing clean code. As code complete notes, your code should say HOW it works, but your comments should say why you’re doing it. But more often than not I encounter code that says nothing about the how or the why of the code, and a heck of a lot about why the previous programmers quit. It does tend to have plenty of comments though detailing the HOW of it.<br />
That being said, a good comment can be worth a thousand lines of code, or an hours work of prototyping and testing to understand the various ways in which a piece of code will be applied. But it shouldn’t be detailing why you’ve decided to use a state pattern. That information should be more centralized, in a place easy for everyone to access. </p>
<blockquote><p>I’m not clear on what your position is on Doxygen style documentation. It seems optimal to me to keep the documentation in the function header comment. How is that bloating the file with useless information? </p></blockquote>
<p>It does? Imagine for a second that the MSDN documentation was embedded in the API headers, would this be optimal? Hardly, digging through those headers is already a pain, littering it with comments just exasperates the problem. Now, preliminary documentation, or interface documentation tends to be a good idea though. Sometimes you just right click -&gt; Go to definition. Which takes you to the function declaration and BAM, you’ve got a nice comment there that tells you what the parameters mean. I certainly wish ruby’s C interface had such niceties. But a full documentation of the function and its corner cases and the various other issues it might have tend to be outside the scope of a comment block. It just doesn’t belong there.</p>
<blockquote><p>Developers log: How is this notebook going to help you? And why a physical notebook? It seems a little hard to share with the team.</p></blockquote>
<p>I actually keep both a document (that’s in source control), and a notebook as well. The notebook is nice because its something I can flip through while I’m in a design session with other architects, to look at past examples, and because I can scribble in it, make crude drawings and drafts next to various decisions. Those drafts can later be turned into nice diagrams which get embedded into the document. But scribbling around on paper is a lot faster than drawing in paint or Visio, and it gives me time to relax the hands.</p>
<blockquote><p>Speaking of teams, I know you’ve worked in team environments, but it seems your strong adherence to few comments, and reliance on the self-documenting nature of your code, speaks to a very small cohesive team, or to solo work. In game development the team is often large, variegated and in flux. Code that is self documenting to you might be confusing to another team member. Explanatory comments are useful time savers here. Conversely, not everyone programs to your high standard, and you might appreciate some good comments in unfamiliar code.</p></blockquote>
<p>Depends, the projects we work on tend to be divided up such that many small teams can work independently with an architect per team. These teams produce artifacts that the architects write integration and feature tests for, thus ensuring that the end product both integrates properly, and that the features that the customer requires are in place. Since we involve the customer heavily in the process of feature determination throughout development, the customer ends up helping to write (and often actually writes a large chunk of) the acceptance tests (feature tests). We’ve found this method tends to help build a much more agile set of components, even when the application gets to be very large.</p>
<p>Actually, the reality is that refactoring can’t simplify all problems. It can make some particular design decisions clearer, it can make some code problems clearer, but it is not a silver bullet. Some problems resist refactoring simply because of the problem. In those cases, a good comment can save minutes of useless refactoring, and hours of a maintenance developer’s time. But yes, you are also right in that there are other cases where comments are appropriate. Let us take for instance the volume of a parallelepiped, it can be taken as either the absolute value of the scalar triple product, or as the absolute value of the determinant of a 3&#215;3 matrix such that the row-vectors are the axis vectors of the parallelepiped. Now, which one do you choose? Which one is simpler to code, and which one is more efficient? It turns out that both reduce to basically the same code, so you can choose either and be equally as efficient. But which one is clearer to the viewer as to what you are trying to do? Who knows, but a nice comment explaining WHY you chose the determinant method over the scalar-triple-product would go a long way to clearing that up. This is a decision that really doesn’t belong in the developer’s log, as it is not really a design decision, more of an algorithmic one. These are things I would put comments in for as well. The same thing is true of your choices for data structures. Lets say you chose std::map over std::tr1::unordered_map, you would probably want to make note of the WHY there… “//Need worst case complexity of O(log n) for lookup” Perfectly acceptable, and in fact I would say that it should be encouraged.<br />
But teaching people how to comment is hard. VERY hard. It is just like coding, but you have to be far more careful, since your comments may make or break another’s understanding of the code to which you have applied the comments. So, instead of saying “yeah, you should use comments” I would rather say “Write clean code. Then worry about comments.” However, I should really say is this “Write clean code, comment clean code, read code complete 2nd edition.” Except I’ve found that for most newbies that doesn’t work. They want to write their games starting in C++ and using “Learn C++ in 21 Days” and “Game Programming All in One”. But you are right, I should be clarifying how to comment more than just discouraging it.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.256 seconds -->
