<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/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>Pointless Blathering : Code</title><link>http://blogs.msdn.com/peterwie/archive/tags/Code/default.aspx</link><description>Tags: Code</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Pedantic Coder: Hungarian Notation</title><link>http://blogs.msdn.com/peterwie/archive/2008/10/13/pedantic-coder-hungarian-notation.aspx</link><pubDate>Mon, 13 Oct 2008 18:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8994682</guid><dc:creator>PeterWie</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/peterwie/comments/8994682.aspx</comments><wfw:commentRss>http://blogs.msdn.com/peterwie/commentrss.aspx?PostID=8994682</wfw:commentRss><description>&lt;p&gt;I generally dislike &lt;a href="http://en.wikipedia.org/wiki/Hungarian_notation"&gt;Hungarian Notation&lt;/a&gt;.&amp;#160; I particularly dislike what Wikipedia calls &amp;quot;System Hungarian&amp;quot;, where the prefix indicates data type, as it adds almost no value for me.&amp;#160; I dislike the more semantically oriented form of Hungarian notation where the prefix implies some broader attribute (like &amp;quot;safety&amp;quot;) because, though that does provide some value - I'm generally not fond of terse prefixes.&amp;#160; If something is an unsafe X then call it &amp;quot;unsafeX&amp;quot;, not &amp;quot;uX&amp;quot; hoping that a reader will know u means unsafe.&lt;/p&gt;  &lt;p&gt;I have taken to including units in variable names when they're (a) beyond what the underlying C/C++ types can discriminate between and (b) too basic to warrant the creation of a class.&amp;#160; For example, when a timeout is in milliseconds or microseconds i'll name the variable &amp;quot;timeoutMs&amp;quot; or &amp;quot;timeoutUs&amp;quot; so that I know which units the value is in.&amp;#160; I don't think that a &amp;quot;time&amp;quot; class is adding enough value here to create one and deal with publishing it, making it available for all the public interfaces I define, figuring out how to make it usable for C developers, etc...&amp;#160; But the difference between Ms and Us is quite large (both literally and figuratively).&lt;/p&gt;  &lt;p&gt;When I do annotate variable names i tend to use suffixes - I find it's easier (for me) to parse a list of names if the real variable name comes first.&amp;#160; A block of variables named msX, msY, msZ, ... is simply harder to read.&amp;#160; &lt;/p&gt;  &lt;p&gt;Despite this there's one set of terse suffixes that I have started using religiously - Cb, Cch &amp;amp; Ce.&amp;#160; These are count-of-bytes, count-of-characters and count-of-elements.&amp;#160; I have started using these everywhere in place of more general terms like &amp;quot;length&amp;quot; or &amp;quot;size&amp;quot; to indicate a counter for another variable.&amp;#160; I think about these as another form of unit, and it has saved my butt a couple of times – particularly if you start using the safe-string functions since you can easily see that your “length” matches the same units as the string function you’re calling.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8994682" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/peterwie/archive/tags/Code/default.aspx">Code</category></item><item><title>Code</title><link>http://blogs.msdn.com/peterwie/archive/2008/02/05/code.aspx</link><pubDate>Wed, 06 Feb 2008 01:33:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7477302</guid><dc:creator>PeterWie</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/peterwie/comments/7477302.aspx</comments><wfw:commentRss>http://blogs.msdn.com/peterwie/commentrss.aspx?PostID=7477302</wfw:commentRss><description>&lt;p&gt;&lt;font size="+0"&gt;Perhaps I'm just out of ideas, but I've decided to write about my &lt;a href="http://blogs.msdn.com/peterwie/archive/tags/Code/default.aspx"&gt;coding style&lt;/a&gt;.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="+0"&gt;Coding style is usually a very personal thing, like any writing style.&amp;#160; And as it usually causes some to foam at the mouth when brought up, I also wanted to put out this little disclaimer before I start.&amp;#160; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="+0"&gt;You may agree with how I've chosen to do things, you may disagree, you may not care in the least.&amp;#160; Please just take this as writing by someone who has been writing code a while and who likes to think about the process of writing code and building software.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="+0"&gt;At the least this can help my blog live up to its name :)&lt;/font&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7477302" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/peterwie/archive/tags/Other/default.aspx">Other</category><category domain="http://blogs.msdn.com/peterwie/archive/tags/Code/default.aspx">Code</category></item><item><title>Pedantic Coder : Where do braces go?</title><link>http://blogs.msdn.com/peterwie/archive/2008/02/04/pedantic-coder-where-do-braces-go.aspx</link><pubDate>Tue, 05 Feb 2008 02:25:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7450391</guid><dc:creator>PeterWie</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/peterwie/comments/7450391.aspx</comments><wfw:commentRss>http://blogs.msdn.com/peterwie/commentrss.aspx?PostID=7450391</wfw:commentRss><description>&lt;p&gt;&lt;/p&gt;  &lt;p&gt;I've become rather pedantic about my coding style over the years.&amp;#160; I've worked in a number of people's code, and have always felt most comfortable in the core NT code because of the consistency of formatting, naming, etc...&amp;#160; This is a coding style that we often call &amp;quot;Cutler Normal Form&amp;quot; in deference to Dave Cutler.&lt;/p&gt;  &lt;p&gt;Despite this I recently made a change in the way I place my braces around blocks of code.&amp;#160; CNF says that braces go at the end of the line that will execute the code block, as follows:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;if&lt;/span&gt; (foo) {
    &lt;span class="kwrd"&gt;do&lt;/span&gt; something;
} &lt;span class="kwrd"&gt;else&lt;/span&gt; {
    &lt;span class="kwrd"&gt;do&lt;/span&gt; something &lt;span class="kwrd"&gt;else&lt;/span&gt;;
}&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;I used to really like this style.&amp;#160; It made it clear to me when the statement being evaluated was continued into the next block.&amp;#160; Of course I always use braces, even when I only want one statement in the if or else clause, so this was a quick way to look and be sure i'd set things up correctly.&lt;/p&gt;

&lt;p&gt;I've now transitioned over to:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;if&lt;/span&gt; (foo) 
{
    &lt;span class="kwrd"&gt;do&lt;/span&gt; something;
} 
&lt;span class="kwrd"&gt;else&lt;/span&gt;
{
    &lt;span class="kwrd"&gt;do&lt;/span&gt; something &lt;span class="kwrd"&gt;else&lt;/span&gt;;
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;







.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;This was the preferred style of the folks in the UMDF group when I joined the project.&amp;#160; It took me a while to warm up to this.&amp;#160; However i eventually found two things that i like about it.&lt;/p&gt;

&lt;p&gt;First it leaves more open white space.&amp;#160; In my &amp;quot;old age&amp;quot; (i.e. mid thirties) i find that i like more whitespace in my code.&amp;#160; It improves the readability for me, and makes me work harder to keep my functions fitting on a single page - which is a good threshold for whether they're understandable or not.&lt;/p&gt;

&lt;p&gt;The second is that it makes it much, much easier to put part of the block under an IFDEF.&amp;#160; This to me was the winner.&amp;#160; Now i can do:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="preproc"&gt;#if&lt;/span&gt; bar
&lt;span class="kwrd"&gt;if&lt;/span&gt; (foo)
{
    &lt;span class="kwrd"&gt;do&lt;/span&gt; something specific to bar;
}
&lt;span class="kwrd"&gt;else&lt;/span&gt;
&lt;span class="preproc"&gt;#endif&lt;/span&gt;
{
    &lt;span class="kwrd"&gt;do&lt;/span&gt; something else;
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;







.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;style type="text/css"&gt;







.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Rather than:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="preproc"&gt;#if&lt;/span&gt; bar
&lt;span class="kwrd"&gt;if&lt;/span&gt; (foo) {
    &lt;span class="kwrd"&gt;do&lt;/span&gt; something specific to bar;
} &lt;span class="kwrd"&gt;else&lt;/span&gt; &lt;span class="rem"&gt;// note that there would otherwise be a { here&lt;/span&gt;
&lt;span class="preproc"&gt;#endif&lt;/span&gt;
{
    &lt;span class="kwrd"&gt;do&lt;/span&gt; something &lt;span class="kwrd"&gt;else&lt;/span&gt;;
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;







.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Or even worse:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="preproc"&gt;#if&lt;/span&gt; bar
&lt;span class="kwrd"&gt;if&lt;/span&gt; (foo) {
    &lt;span class="kwrd"&gt;do&lt;/span&gt; something specific to bar;
} &lt;span class="kwrd"&gt;else&lt;/span&gt; {
&lt;span class="preproc"&gt;#else&lt;/span&gt;
{
&lt;span class="preproc"&gt;#endif&lt;/span&gt;
    &lt;span class="kwrd"&gt;do&lt;/span&gt; something &lt;span class="kwrd"&gt;else&lt;/span&gt;;
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;







.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Perhaps it's a silly thing to change something as fundamental(ist) as brace formatting style to get around a little inconsistency in how you preprocess out part of a conditional.&amp;#160; But i like consistency ... the hairs on the back of my neck go up when i see code that's not in my normal format.&amp;#160; So in the end this made me more comfortable.&lt;/p&gt;

&lt;p&gt;This has come up quite a bit for me when debugging something or refactoring something.&amp;#160; When refactoring i'll frequently #if out a chunk of impacted non-critical functionality (usually replaced with a failure case) until i'm ready to deal with that chunk of code.&amp;#160; For debugging it can be useful to do the same thing if you're trying to track down the cause of a crash and are at your witts end.&lt;/p&gt;

&lt;p&gt;And I've come to find it prettier.&lt;/p&gt;

&lt;p&gt;-p&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7450391" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/peterwie/archive/tags/Code/default.aspx">Code</category></item></channel></rss>