Home Web Design Programming Fairlight CMI Soap Box Downloads Links Biography About... Site Map


CA-Clipper Opportunities Tips and Tricks Networking Internal Errors Source Code CA-VO


Hungarian Notation is a naming convention that was popularized many years ago by Charles Simonyi at Microsoft. It is used throughout the source code of the Windows operating system. 
This is a coding convention that you will find quite useful, especially in CA-Clipper which is not a "strongly typed" language. I also recommend it for use in Java and JavaScript. 
Hungarian Notation provides some rules that make your code more understandable. It uses a combination of mixed case to describe a variable, plus a lower case character or two in front of the name to indicate its data type. 
For example, if there is a numeric variable for a yearly total, it would probably be called nYearTotal. Another example: cUserName is most likely a character variable that contains the User's name. Hungarian Notation allows you to determine quite a bit about the variable, just from its name. 
Some examples of Hungarian Notation are
• CharactercSomeAlpha := "ABCDEFGHIJ"
• Date dToday := date()
• Logical lFinished := CheckStatus()
• Numeric nYearTotal := 98765
• Array aDirection := {"N", "S", "E", "W"}
• Block bInitialize := {|| X:=0, Y:=0, Z:=0}
• Object oTable := tbrowsedb()
With arrays you can get a bit more specific. For instance, if you had an array of character strings you could say:
    acMenuItems := {"Add", "Edit", "Delete"} 
A two dimensional array of numbers might be expressed as:
    aanMatrix := { {1,2,3} , {4,5,6} , {7,8,9} } 
An interesting option is to precede names with "p" to indicate parameters:
    function ShowText ( pcText, pnRow, pnCol )
Another technique precedes static variable names with "s":
    function CheckPassword ( pcPassword )
       static snAttempt:=0
Static variables that are declared before the first procedure or function in a program file (.PRG) have file-wide scope and are sometimes prefixed with "g", which stands for "global". (Although the variables are not available throughout the entire program, just the one program file, the word "global" seems appropriate.)
    static gnPage

    function YearReport ( )
       gnPage := 1
I highly recommend Hungarian Notation. But note that it is just a convention that is generally agreed upon by programmers as the "right" way to name variables. It is not enforced by the CA-Clipper compiler -- it is just a good idea. 
Tip   Don't be afraid to use long names for variables if they are descriptive. CA-Clipper will only use the first 10 characters, so this portion has to be unique, but add more if it improves the readability. Names that are not unique within the first 10 characters will be detected by the compiler if they are declared in the same function or procedure.

To see how HN can work with Java, see my article Applying Hungarian Notation to Java programs Part 1 and Part 2 on the Gamelan site. If you are looking for other CA-Clipper conventions, then visit the Coding Guidelines section of my site.

Home Web Design Programming Fairlight CMI Soap Box Downloads Links Biography About... Site Map

Site Map Send comments about this site to Greg at gregh@ghservices.com
All pages copyright © 1996-1999 GH Services™   Created 1997/06/02   Last updated 1999/10/05
All trademarks contained herein are the property of their respective owners