<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3608450286130756743</id><updated>2011-04-21T22:46:10.265-07:00</updated><title type='text'>Cuddle Your Braces</title><subtitle type='html'>Arguments in favor of the 1TBS</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://cuddleyourbraces.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3608450286130756743/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://cuddleyourbraces.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Bossk</name><uri>http://www.blogger.com/profile/05493114038186689735</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>4</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3608450286130756743.post-8892791251315878842</id><published>2007-10-10T06:26:00.000-07:00</published><updated>2007-10-10T06:59:08.779-07:00</updated><title type='text'>Variable Names in C Function Prototypes: Not a Good Idea</title><content type='html'>It seems that some neophyte C programmers are unaware that variable names are not required (let alone not desired) in function prototypes. This also seems to happen when lazy programmers cut-and-paste the function head from the .c to the .h file and neglect to edit out the names.&lt;br /&gt;&lt;br /&gt;The most obvious problem with this practice is that the names will need to be maintained in two separate files and can very easily get out of sync. Another is the general clutter the additional identifiers will create in the header files.&lt;br /&gt;&lt;br /&gt;It is also poor documentation style to document a function twice, and variable names are a form of documentation--at least to those who pay attention to cultivating good documentation practices. This would be akin to providing a book with both footnotes at the bottom of each page and chapter notes at the end of each chapter containing redundant information. And what's worse still, is that the documentation process of code is usually integral with the programming of it: since the definitions are undergoing rapid changes during the process while the prototypes are relatively stable, the two tend to diverge significantly.&lt;br /&gt;&lt;br /&gt;In addition to the maintenance nightmares caused by using variable names in two places, one must critically examine the purposes of the documentation, to whom it is addressed, and where the addressee goes to find it. The purposes will not be discussed here, but we do need to take a look at the last two. Documentation is addressed typically to clients and developers. The former will typically look to the manuals (either electronic or print media). To suggest they look in the header files is absurd--e.g. how many users of stdio.h look in that file for information on how to use &lt;code&gt;printf()&lt;/code&gt;? Of course the developers would naturally document a function where it is defined rather than prototyped.&lt;br /&gt;&lt;br /&gt;QED&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3608450286130756743-8892791251315878842?l=cuddleyourbraces.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cuddleyourbraces.blogspot.com/feeds/8892791251315878842/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3608450286130756743&amp;postID=8892791251315878842' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3608450286130756743/posts/default/8892791251315878842'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3608450286130756743/posts/default/8892791251315878842'/><link rel='alternate' type='text/html' href='http://cuddleyourbraces.blogspot.com/2007/10/variable-names-in-c-function-prototypes.html' title='Variable Names in C Function Prototypes: Not a Good Idea'/><author><name>Bossk</name><uri>http://www.blogger.com/profile/05493114038186689735</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3608450286130756743.post-1051337151350294757</id><published>2007-09-28T11:19:00.001-07:00</published><updated>2007-09-28T11:48:43.152-07:00</updated><title type='text'>Why the postfix increment operator in for loops is a bad idea</title><content type='html'>The naive programmer writes:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;for (i=0; i&amp;lt;100; i++)&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;to count from 0 to 99 while those who know better write&lt;br /&gt;&lt;br /&gt;&lt;code&gt;for (i=0; i&amp;lt;100; ++i)&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;There are two reasons for doing so. The first is on the grounds of efficiency: the postfix increment requires the creation of a temporary variable. Since the runtime value of &lt;code&gt;i++&lt;/code&gt; must different from &lt;code&gt;i&lt;/code&gt; (&lt;code&gt;i&lt;/code&gt; cannot be both values), the compiler will need to set aside space for a new variable and copy the original value of &lt;code&gt;i&lt;/code&gt; to it.&lt;br /&gt;&lt;br /&gt;Not only is it more efficient to use the prefix operator, but it is more elegant and semantically correct.  The postfix increment says fetch me the value (which I don't have any need whatsoever for) of &lt;code&gt;i&lt;/code&gt; and then when I'm done with it, then increment it; the prefix version simple says "increment the value of &lt;code&gt;i&lt;/code&gt;."&lt;br /&gt;&lt;br /&gt;It also translates better into proper English: &lt;code&gt;++i&lt;/code&gt; translates to "increment i" while &lt;code&gt;i++&lt;/code&gt; translates to the ungrammatical "i and increment" or the clumsy "evaluate i and then increment it."&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3608450286130756743-1051337151350294757?l=cuddleyourbraces.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cuddleyourbraces.blogspot.com/feeds/1051337151350294757/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3608450286130756743&amp;postID=1051337151350294757' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3608450286130756743/posts/default/1051337151350294757'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3608450286130756743/posts/default/1051337151350294757'/><link rel='alternate' type='text/html' href='http://cuddleyourbraces.blogspot.com/2007/09/why-postfix-increment-operator-in-for_28.html' title='Why the postfix increment operator in for loops is a bad idea'/><author><name>Bossk</name><uri>http://www.blogger.com/profile/05493114038186689735</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3608450286130756743.post-4451927256890325221</id><published>2007-09-27T11:41:00.000-07:00</published><updated>2007-09-27T11:59:45.225-07:00</updated><title type='text'>The Evils of the while(true) loop</title><content type='html'>There has been a disgusting tendency among some alleged programmers to write an endless loop as:&lt;br /&gt;&lt;br /&gt;while (true) {&lt;br /&gt;    // do something&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;rather than the classic:&lt;br /&gt;&lt;br /&gt;for (;;) {&lt;br /&gt;    // do something smarter than the above loop&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The first form is not only an abuse of logic but an abuse of notation. Logically it suggests a loop that will go on forever because of some tautology--which has absolutely nothing to do with the logic of the program--used as its condition. In pseudocode:&lt;br /&gt;&lt;br /&gt;while (all Greeks are Men) {&lt;br /&gt;    ...&lt;br /&gt;    if (pigs can fly)&lt;br /&gt;        break;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;In other words the condition in the while statement has nothing to do with the condition for exiting the loop. It is an abuse of notation since a while loop is really a syntactic sugar for the more general for loop in which a condition is expected to be false at some time during its execution.&lt;br /&gt;&lt;br /&gt;Now, consider the beautiful, elegant:&lt;br /&gt;&lt;br /&gt;for (;;) {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;not only is it much more succinct than the former, but there is no need for some bogus condition for the loop check expression. It simply and clearly states that a loop will continue to iterate until  some internal condition dictates that it is now time to break out.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3608450286130756743-4451927256890325221?l=cuddleyourbraces.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cuddleyourbraces.blogspot.com/feeds/4451927256890325221/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3608450286130756743&amp;postID=4451927256890325221' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3608450286130756743/posts/default/4451927256890325221'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3608450286130756743/posts/default/4451927256890325221'/><link rel='alternate' type='text/html' href='http://cuddleyourbraces.blogspot.com/2007/09/evils-of-whiletrue-loop.html' title='The Evils of the while(true) loop'/><author><name>Bossk</name><uri>http://www.blogger.com/profile/05493114038186689735</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3608450286130756743.post-7574859019340080898</id><published>2007-09-25T12:47:00.000-07:00</published><updated>2007-09-25T13:29:30.405-07:00</updated><title type='text'>Why it is important to cuddle your braces when writing code</title><content type='html'>The Fundamental Theorem of Formatting states that the visual layout should show the logical structure of the program. As Steve McConnell says in his classic &lt;em&gt;Code Complete&lt;/em&gt; the coding style where opening braces occur alone on a line beneath the conditional or loop statement they belong to (that if one is allowed certain liberties with the meaning of the word "style") violates this principle in that it suggests that the body of the conditional or loop is subordinate to the brace, rather than the &lt;em&gt;for&lt;/em&gt; or the &lt;em&gt;if&lt;/em&gt; statement that it belongs to!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3608450286130756743-7574859019340080898?l=cuddleyourbraces.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cuddleyourbraces.blogspot.com/feeds/7574859019340080898/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3608450286130756743&amp;postID=7574859019340080898' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3608450286130756743/posts/default/7574859019340080898'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3608450286130756743/posts/default/7574859019340080898'/><link rel='alternate' type='text/html' href='http://cuddleyourbraces.blogspot.com/2007/09/why-it-is-important-to-cuddel-your.html' title='Why it is important to cuddle your braces when writing code'/><author><name>Bossk</name><uri>http://www.blogger.com/profile/05493114038186689735</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry></feed>
