    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: Hungarian Notation- Another View</title>
        <link>https://members.accu.org/index.php/journals/751</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>


        <h2>Journal Articles</h2>


<div class="xar-mod-head"><span class="xar-mod-title">CVu Journal Vol 11, #1 - Nov 1998 + Programming Topics</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/journals/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c77/">CVu</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c134/">111</a>
                    (19)
<br />

                                            <a href="https://members.accu.org/index.php/journals/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c13/">Topics</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c65/">Programming</a>
                    (877)
<br />

                                            <a href="https://members.accu.org/index.php/journals/c134-65/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/journals/c134+65/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Hungarian Notation- Another View</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 03 November 1998 13:15:28 +00:00 or Tue, 03 November 1998 13:15:28 +00:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e20" id="d0e20"></a></h2>
</div>
<p>Hungarian notation is one of those ideas used in software
development that is either loved or hated. Having been a commercial
software developer for a few years now, almost exclusively with
Microsoft development tools, I thought I would add a few comments
to this topic.</p>
<p>The purpose of Hungarian notation is to make it easier for a
human to read code by providing immediate feedback of an
identifier's type at any place in the code. Before asking whether
it achieves this objective it can be admitted immediately that the
major disadvantage of this is that it ties an identifier's name to
its type so that a change in the latter forces a change in the
former. This introduces a problem of code maintenance, though I
don't think this is quite so serious these days given the editing
facilities of current development tools.</p>
<p>But does Hungarian notation really make it easier to read code?
Many would answer that it does not, and that, in fact, it makes it
harder. My own view is that it does not particularly make it harder
to read, especially once you've got used to it. (Whether it makes
it easier to read is another matter.) The difficulty is more to do
with applying it consistently and remembering the often lengthy
prefixes (e.g., &quot;lpsz&quot;).</p>
<p>Before putting forward my own views on the merits or demerits of
Hungarian notation here is the policy I adopt towards it in
practice.</p>
<p>In general, I tend to fall in with the style of whatever code I
have to interface with. So if I'm using Microsoft C++, especially
MFC, and have to use Wizard-generated code then my extensions to
such code tend to adopt Hungarian so that the code looks
&quot;integrated.&quot;</p>
<p>If I'm doing maintenance work on code that's not written by me I
tend to adopt the notation of the original author. If he uses
Hungarian then I do. If he doesn't then I don't. If I'm writing
completely separate routines I may relax this and stick to my own
approach. This all assumes that there are no mandated coding
guidelines in force. In my experience, in regard to the use of
Hungarian, there usually aren't.</p>
<p>Now what do I think of Hungarian notation?</p>
<p>I think it is helpful but only to a certain extent. I think it
is helpful in regard to user interface widgets. For example, it is
very helpful to adopt it when referring to such things as list
boxes, buttons, tree view nodes, etc. But for simple data types and
objects that are not user interface widgets, I think only a very
restricted subset of Hungarian is necessary for readability.</p>
<p>In C++, it is helpful to adopt a convention such as using the
prefixes, &quot;p&quot; for a pointer, &quot;m_&quot; (or something similar) for a
class data member, perhaps &quot;g_&quot; for a global identifier, perhaps
&quot;s_&quot; for a static identifier. In addition it can be helpful to
adopt a convention for strings, where string objects and C-style
strings are being used together. So, maybe, a &quot;str&quot; prefix for a
string object and an &quot;sz&quot; prefix for a C-style null-terminated
string. And that's about it.</p>
<p>In Visual Basic, I adopt Hungarian for the UI widgets and not
for anything else. (If I have to use class modules then I follow my
C++ approach for data members and that's it.)</p>
<p>In practice, I'm not particularly fussed about extensions to
Hungarian notation beyond what I've outlined but I feel that they
do not add anything further to readability.</p>
<p class="c2"><span class="remark">I handed this to the Harpist for
his view and this is what I got back.</span></p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e47" id="d0e47"></a>The Harpist's
View</h2>
</div>
<p>There are several issues that should be considered when
discussing notations such as HN. Kevin has already touched on the
first when he mentions the problem of tracking changing type
information. He also mentions the problem of readability.</p>
<p>On the other hand there is some advantage in tracking the
purpose of an identifier even if we avoid the inclusion of type
specific coding. Kevin implicitly uses such when he prepends m_ or
g_ to an identifier.</p>
<p>To be honest, until recently I considered such elaboration of
identifiers to be silly. However I do read and try to learn from
the experiences and ideas of others. There is a real advantage in
using some coding convention to distinguish the scope of an
identifier, it helps to limit damage caused by unintended name
hiding. This can become a serious issue in C++ where we need to be
concerned with name hiding and how it interacts with function
overloading.</p>
<p>I want to take this opportunity to suggest an alternative set of
naming conventions that is less invasive while meeting most of the
more desirable objectives. My guidelines are:</p>
<p>Do not use prefixes. They get in the way of readability. Use a
suffix (i.e. append the elaboration).</p>
<p>Do not include specific type information. Only include context
and use information.</p>
<p>Only use any kind of elaboration in large projects.</p>
<p>Ensure that all members of a project team are committed to the
same scheme.</p>
<p>A few examples:</p>
<div class="informaltable">
<table border="1" cellspacing="0">
&lt;colgroup&gt;
&lt;col width=&quot;50%&quot;&gt;
&lt;col width=&quot;50%&quot;&gt;&lt;/colgroup&gt;
&lt;tbody&gt;
<tr>
<td><span class="bold"><b>node</b></span></td>
<td>a local variable</td>
</tr>
<tr>
<td><span class="bold"><b>node_S</b></span></td>
<td>a static variable (the existence of these causes problems if
the code is going to be used in a multi-threaded application. That
is why I have used an uppercase letter.</td>
</tr>
<tr>
<td><span class="bold"><b>node_m</b></span></td>
<td>a data member</td>
</tr>
<tr>
<td><span class="bold"><b>changeNode_m</b></span></td>
<td>a function member (note use of a verb)</td>
</tr>
<tr>
<td><span class="bold"><b>node_GLOBAL</b></span></td>
<td>yes, make these really visible. Breaking this convention should
be a serious coding offence.</td>
</tr>
<tr>
<td><span class="bold"><b>node_ptr</b></span></td>
<td>Obvious?</td>
</tr>
<tr>
<td><span class="bold"><b>node_mptr</b></span></td>
<td>member that is a pointer to a node</td>
</tr>
<tr>
<td><span class="bold"><b>node_mref</b></span></td>
<td>member that is a reference to a node</td>
</tr>
<tr>
<td><span class="bold"><b>Node_t</b></span></td>
<td>a <tt class="literal">typedef</tt>ed typename</td>
</tr>
<tr>
<td><span class="bold"><b>Node_tptr</b></span></td>
<td>a <tt class="literal">typedef</tt> for a pointer to node.</td>
</tr>
&lt;/tbody&gt;
</table>
</div>
<p>I think that is enough to start with. Perhaps readers would like
to give their reactions.</p>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
