Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: To use or not to use Hungarian Notation, this is the question (o.t)

Author: Daniel Clausen

Date: 03:05:47 03/05/04

Go up one level in this thread


Hi

Apart from a few exceptions (for pointers) I don't use HN-notation at all. (I
know it's religion, so all I'm doing here is presenting my POV)

For most projects it's enough for me to give good/descriptive names to
variables. From the name alone I can derive the 'basic type' of the variable.
With basic type I mean things like, string ('fileName'), integral type
('numberOfEntries'), floating point type (almost never use that anyway :),
boolean ('isEmpty'). For many projects it's not that important to always know
the 'subtype', that is whether the integral type is now int, or short or long,
especially not if you only want to understand the code. For hardware-near
projects it's different I agree. (whether chess programming is such a case is an
open question for me, most think it's hardware-near)

In C/C++ I use the postfix 'P' for pointers, since there's typically no way to
tell from a descriptive variable name, whether it is a pointer or not. And in
C/C++ you have to know this in order to use it. ('.' instead of '->')


>The main thing for me is to distinguish between signed/unsigned integers, see
>pointers ('p') and to avoid having to describe a variable type by other means.

About the signed/unsigned thing: in my projects, it's usually clear what it is:
if the domain of the variable excludes negative numbers, it will be unsigned,
otherwise signed. For example "numberOfEntries" will be unsigned, since a
negative number simply doesn't make any sense.


>By the latter, an example would be a bit of code which is dealing with a file,
>where we have the file name and a handle. The name is stored as a string, the
>handle as an int. If using hungarian I might use strFile and nFile, otherwise
>I'd probably use FileName and FileHandle.

I would *definitely* use 'fileName' and 'fileHandle'. If someone uses 'strFile'
and 'nFile' since one is a string and the other an integer, how would you call
another string-like property about the file, say permissions or the path? I
would call the 'filePermissions' and 'filePath'. 'strFile' and 'nFile' are
simply not descriptive enough. So HN here solves a problem I wouldn't have
anyway.


>The use of Hungarian notation is one of those computer-religous issues that
>people get very worked up about.

Agreed. :) Nevertheless I had sensible discussions with people from both camps
and I could understand their reasoning behind the choice.


>It probably doesn't help that it was named after a Microsoft guy!

I tend to agree. ;)

Sargon



This page took 0.01 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.