Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: variable names: camel case or underscores? (even more o.t.)

Author: José Carlos

Date: 07:10:36 03/05/04

Go up one level in this thread


On March 05, 2004 at 09:52:37, Omid David Tabibi wrote:

>On March 05, 2004 at 06:05:47, Daniel Clausen wrote:
>
>>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.
>
>When we are at it, why does almost everyone today uses camel case for namnig
>variables?
>
>doYouThinkThatCamelCaseIsEasierForReading
>or_maybe_using_underscores_is_more_readable ?!
>
>The coding conventions of Windows API, MFC, Java, C# all use camel case for
>variables. STL is the only place where I can see underscores used.


  In my case the underscore has a particular meaning, it separates the scope
prefix from the variable itself. I find g_nNumberOfPawns easy to read: "a global
integer that contains the number of pawns".

  José C.



>>
>>
>>>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 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.