<?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>What does style look like, part 6</title><link>http://blogs.msdn.com/larryosterman/archive/2004/11/16/258322.aspx</link><description>Previously in the series, I've touched on indentation and commenting , The next aspect of "style" that I want to talk about is variable (and function) naming conventions. Upon reflection, I hungarianized the code way too early in the series, it properly</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: What does style look like, part 6</title><link>http://blogs.msdn.com/larryosterman/archive/2004/11/16/258322.aspx#258455</link><pubDate>Tue, 16 Nov 2004 20:22:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:258455</guid><dc:creator>Mike Dunn</dc:creator><description>&amp;quot;good names describe semantics, not type&amp;quot; [and therefore do not use Hungarian]&lt;br&gt; &lt;br&gt;*sigh* Where to start with that one...</description></item><item><title>re: What does style look like, part 6</title><link>http://blogs.msdn.com/larryosterman/archive/2004/11/16/258322.aspx#258456</link><pubDate>Tue, 16 Nov 2004 20:23:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:258456</guid><dc:creator>Larry Osterman</dc:creator><description>Mike, I'm just the messenger :)&lt;br&gt;&lt;br&gt;I agree with the comment otoh - good variable names SHOULD describe semantics.&lt;br&gt;</description></item><item><title>re: What does style look like, part 6</title><link>http://blogs.msdn.com/larryosterman/archive/2004/11/16/258322.aspx#258458</link><pubDate>Tue, 16 Nov 2004 20:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:258458</guid><dc:creator>damien morton</dc:creator><description>Everyone pooh poohs Pascal, but Wirth got a lot right. I would say that Java and C# owe more to Pascal, in some ways, than to C.</description></item><item><title>re: What does style look like, part 6</title><link>http://blogs.msdn.com/larryosterman/archive/2004/11/16/258322.aspx#258473</link><pubDate>Tue, 16 Nov 2004 21:07:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:258473</guid><dc:creator>Eric Newton</dc:creator><description>I didnt see the part of the CLR guidelines that discourages prefixes for member variables, and if so, that's stupid.&lt;br&gt;&lt;br&gt;There should be a differentiation between member variables, parameters and local variables, if desired.  &lt;br&gt;&lt;br&gt;&lt;br&gt;I typically prefix member variables with the &amp;quot;_&amp;quot; underscore prefix, and to some degree I also qualify references with &amp;quot;this&amp;quot; so you'd see in my code&lt;br&gt;&lt;br&gt;&amp;quot;this._name = value;&amp;quot;&lt;br&gt;&amp;quot;this._id = value;&amp;quot;&lt;br&gt;&lt;br&gt;The added benefit is intellisense once you type &amp;quot;this._&amp;quot; you see all your class member variables lined up.  Why this is explicitly discouraged in the CLR guidelines is dumb, and goes against what Microsoft's own programmers apply to a good 75% of the classes.&lt;br&gt;&lt;br&gt;Additionally, related to naming conventions/clashes with member variable names/etc, I have a problem with people writing methods that are more than 10-20 lines.&lt;br&gt;&lt;br&gt;IMO, If you have a function with 15 local variables, (which incidentally slows down CLR efficiency, I hear because of certain IL instructions are optimized for the first 5 locals), then you've got a function that is too broad in scope and should be refactored.  &lt;br&gt;&lt;br&gt;Consider when running release builds of your methods, and an Null reference exception happens on a 100 line method.  No line number, just the method name.  Figure that one out.&lt;br&gt;&lt;br&gt;Frankly, I dont care how your internals look.  Just please follow the public interface guidelines so I understand the semantics of calling the public functions: parameter names and function names that define what they do. &lt;br&gt;&lt;br&gt;I just find it amusing (to the tune of Daily WTF) of just how little common sense devs apply to their code.</description></item><item><title>re: What does style look like, part 6</title><link>http://blogs.msdn.com/larryosterman/archive/2004/11/16/258322.aspx#258474</link><pubDate>Tue, 16 Nov 2004 21:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:258474</guid><dc:creator>Larry Osterman</dc:creator><description>Eric,&lt;br&gt;  That's pretty much what I do - members get an _ in front of the name to differentiate them.&lt;br&gt;&lt;br&gt;  I don't use visual studio for my editor (I use Epsilon), so I don't have the benefit of intellisense :(&lt;br&gt;&lt;br&gt;</description></item><item><title>re: What does style look like, part 6</title><link>http://blogs.msdn.com/larryosterman/archive/2004/11/16/258322.aspx#258482</link><pubDate>Tue, 16 Nov 2004 21:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:258482</guid><dc:creator>Larry Osterman</dc:creator><description>CLR == Common Language Runtime - Also known as the .Net framework.&lt;br&gt;</description></item><item><title>re: What does style look like, part 6</title><link>http://blogs.msdn.com/larryosterman/archive/2004/11/16/258322.aspx#258512</link><pubDate>Tue, 16 Nov 2004 22:13:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:258512</guid><dc:creator>David A. Mellis</dc:creator><description>In all this talk about indenting, naming conventions, and comment standards, I think you've ignored the most important aspects of this code's style.&lt;br&gt;&lt;br&gt;First, there's cleary some global state involved (otherwise, what's the call to initNodes() do?).    Second, there seems to be some trickery with the default next node for new nodes.  Otherwise, how does the linked list end up as a circle?  Third, what does DeleteNextNode do?  If it sets node-&amp;gt;next to node-&amp;gt;next-&amp;gt;next, it's badly named, as &amp;quot;delete&amp;quot; is associated with memory deallocation, not removal from a list.  Fourth, what's the Josephus problem?  I'd prefer a brief description to the comments for each section of code.&lt;br&gt;&lt;br&gt;I know that you're just using this piece of code as an example, but it's difficult to evaluate the effectiveness of these surface changes when more fundamental problems remain.&lt;br&gt;&lt;br&gt;BTW, you have some typos in your final snippet.  In the line:&lt;br&gt;&lt;br&gt;while (newNode != Next(currentNode))&lt;br&gt;&lt;br&gt;the &amp;quot;newNode&amp;quot; should be &amp;quot;currentNode&amp;quot;.  You're missing a semi-colon after the &amp;quot;int i&amp;quot; and you've forgotten to change the variable names in the comments.</description></item><item><title>re: What does style look like, part 6</title><link>http://blogs.msdn.com/larryosterman/archive/2004/11/16/258322.aspx#258523</link><pubDate>Tue, 16 Nov 2004 22:25:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:258523</guid><dc:creator>Larry Osterman</dc:creator><description>David,&lt;br&gt;  Your point is valid, there IS global state.  This may be a poor example, as I said in the first post, it was chosen by opening a textbook at random and picking the nearest sample code fragment with significant amounts of code in it (I was lazy and didn't want to spend the time working on a good example :))&lt;br&gt;&lt;br&gt;I'll fix the typos.&lt;br&gt;&lt;br&gt;</description></item><item><title>re: What does style look like, part 6</title><link>http://blogs.msdn.com/larryosterman/archive/2004/11/16/258322.aspx#258585</link><pubDate>Wed, 17 Nov 2004 00:14:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:258585</guid><dc:creator>Alex</dc:creator><description>One thing to keep in mind is that C++ specifications reserve leading underscores for the implementation.&lt;br&gt;&lt;br&gt;So calling a local variable _foo is a no-no in C++, and calling a local variable m_foo in C# is discouraged.&lt;br&gt;&lt;br&gt;Interesting.&lt;br&gt;&lt;br&gt;Myself, I like the camelCase and _local style when writing C++.  I'm just not disciplined enough for true Hungarian sadly, so I've stopped trying to half-ass it with strFoo and iFoo.</description></item><item><title>re: What does style look like, part 6</title><link>http://blogs.msdn.com/larryosterman/archive/2004/11/16/258322.aspx#258594</link><pubDate>Wed, 17 Nov 2004 00:42:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:258594</guid><dc:creator>Norman Diamond</dc:creator><description>&amp;gt; The first thing that's clear is that&lt;br&gt;&amp;gt; abbreviations are out,&lt;br&gt;&lt;br&gt;So the typedef formerly known as I has to be INTEGER?&lt;br&gt;&lt;br&gt;&amp;gt; and that variables should represent full&lt;br&gt;&amp;gt; English words.&lt;br&gt;&lt;br&gt;Not Hungarian?  Of course the language keywords are English, but why should variables be?  Actually I think the C committee went too far when they allowed non-Italian characters in variable names, I think those should stay in comments and character strings, but it seems rather reasonable to have variable names using Italian characters to represent Hungarian or Japanese words.&lt;br&gt;&lt;br&gt;Sometimes it seems kind of irrelevant, for example Gosa could be named ErrorRange instead of Gosa, but sometimes it's highly relevant.  Consider an IME that recognizes ConversionKey and NonConversionKey and others in deciding how to convert among ItalianCharacters and JapanesePhoneticCharactersUsuallyUsedForPartsOfJapaneseWords and JapanesePhoneticCharactersUsuallyUsedForForeignWords and ChineseCharacters.  It would be more readable to recognize the HenkanKey and MuHenkanKey and others in deciding how to convert among Romaji and Hiragana and Katakana and Kanji.  (By the way, Microsoft's English language help files for the IME would also be more readable if they did the same.  Some months after trying to guess what kind of key is a conversion key and what kind of key is a non conversion key, I finally figured out that Microsoft meant the keyboard's henkan key and muhenkan key.)</description></item><item><title>re: What does style look like, part 6</title><link>http://blogs.msdn.com/larryosterman/archive/2004/11/16/258322.aspx#258604</link><pubDate>Wed, 17 Nov 2004 01:24:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:258604</guid><dc:creator>Larry Osterman</dc:creator><description>Norman,  I'm describing the CLR conventions, which are pretty clearly anti-hungarian.&lt;br&gt;</description></item><item><title>re: What does style look like, part 6</title><link>http://blogs.msdn.com/larryosterman/archive/2004/11/16/258322.aspx#258795</link><pubDate>Wed, 17 Nov 2004 12:53:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:258795</guid><dc:creator>Guenter Tschech</dc:creator><description>For reading code from other people, I do prefer the CLR style, because it's much more &amp;quot;human&amp;quot; readable (versus &amp;quot;developer&amp;quot; readable in the hungarian notation).&lt;br&gt;But I see that in some cases you need to have prefixes to know what you have to expect from that variable.&lt;br&gt;But when programming with classes, you will sooner or later run out of prefixes that are short enough to be typed in (at least that's what I find), so the hungarian paradigm seems to fit more to the funcional world than to the OO-World (where the .net citizens _should_ live).&lt;br&gt;By using .net (and Visual Studio as your editor), you really don't need to put this into the name, because IntelliSense will pop up the type just when moving the mouse over the variable and just entering a period (hopefully in whidbey at any character) the list of members and locals will appear, so you get instant information about the type.&lt;br&gt;&lt;br&gt;(maybe you missed that because you're hooked to Epsilon ?)&lt;br&gt;</description></item><item><title>re: What does style look like, part 6</title><link>http://blogs.msdn.com/larryosterman/archive/2004/11/16/258322.aspx#258844</link><pubDate>Wed, 17 Nov 2004 14:43:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:258844</guid><dc:creator>Larry Osterman</dc:creator><description>Guenter,&lt;br&gt;  Even if I used visual studio, I wouldn't have the benefit of intellisense.  The NT build environment (or the Exchange build environment) doesn't run from within visual studio, and the browser database that intellisense uses isn't generated.&lt;br&gt;&lt;br&gt;  And, like source level debugging, intellisense is a crutch, you shouldn't depend on it.</description></item><item><title>re: What does style look like, part 6</title><link>http://blogs.msdn.com/larryosterman/archive/2004/11/16/258322.aspx#262799</link><pubDate>Thu, 18 Nov 2004 14:15:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:262799</guid><dc:creator>Guenter Tschech</dc:creator><description>Larry,&lt;br&gt;&lt;br&gt;if you refer to VStudio 6.0, you're perfectly right, but although I am a programmer since Windows 2.11 (using the MS C compiler) and did not use intellisense at all in C and C++, I instantly switched to this behavior when turning into C# development, as it works much more reliable than the VS6 thing did...&lt;br&gt;&lt;br&gt;Maybe this will get better inside MS when all code is ported to CLR, but I think this won't be too soon for Exchange and NT :-)</description></item></channel></rss>