Difference between revisions of "Hungarian notation"

From Free Pascal wiki
Jump to navigationJump to search
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
Hungarian notation in a coding style adopted by MS for C development under Windows. This variable naming technique claims to harmonize, to improve the readability of the existing variables, so to save time when a project grows. Here is an example list, neither official nor fixed (the prefixes are usually based on the information theory, which concludes that consonants can be inferred in the middle of vowels. It uses too, the Camel case notation a lot). The name refection tool is perfect to use this technique easily.
+
Hungarian notation in a coding style adopted by MS for C development under Windows. This variable naming technique claims to harmonize, to improve the readability of the existing variables, so to save time. Here is an example list, neither official nor fixed (the prefixes are usually based on the information theory, which concludes that consonants can be inferred in the middle of vowels. It uses too, the Camel case notation a lot). The name refection tool is perfect to use this technique easily.
  
 
<br><br><br>
 
<br><br><br>
Line 32: Line 32:
 
chk      TCheck Box
 
chk      TCheck Box
 
cbx      TComboBox
 
cbx      TComboBox
cmp      TComponent
 
 
db        TDatabase
 
db        TDatabase
 
dts      TDataSource
 
dts      TDataSource
Line 40: Line 39:
 
               sgrd  TString Grid
 
               sgrd  TString Grid
 
               dbgrd  TDBGrid
 
               dbgrd  TDBGrid
hdr      THeader
 
 
img      Image
 
img      Image
 
itm      TMenuItem
 
itm      TMenuItem
Line 52: Line 50:
 
tabs      TTabset
 
tabs      TTabset
 
tabnotbk  Tabbed Notebook
 
tabnotbk  Tabbed Notebook
outl      TOutline2
+
hdr      THeader
 +
stb      TStatusBar
 +
outl      TOutline
 
pnl      TPanel
 
pnl      TPanel
 
tbl      TTable
 
tbl      TTable
Line 65: Line 65:
 
[[Components \ Objects:]]
 
[[Components \ Objects:]]
 
<pre>
 
<pre>
oSL      String List; ex.: oSLfoo
+
cmp      TComponent
 +
oSL      TStringList; ex.: oSLfoo
 
oStrm    TStream; ex.: oStrmFoo
 
oStrm    TStream; ex.: oStrmFoo
 
...\...
 
...\...
Line 80: Line 81:
 
<pre>
 
<pre>
 
o  means, from a memory scope management, that oMyObj must be freed within the scope of its declaration; ex.: oMyObject; ex.: goMyObject
 
o  means, from a memory scope management, that oMyObj must be freed within the scope of its declaration; ex.: oMyObject; ex.: goMyObject
o_ means, from a memory scope management, that o_myObj must not be freed here, i.e. must not be freed in the scope of its declaration!; ex: o_myObj
+
o_ means, from a memory scope management, that o_myObj must not be freed here, i.e. must not be freed in the scope of its declaration, but elsewhere, in a remote scope, where there is an statement declaration of oMyObj, which is the one where this object was created!; ex: o_myObj
 +
</pre>
 +
 
 +
 
 +
[[Constants:]]<br>
 +
<br>
 +
Constants are often written in uppercase ( like in C):
 +
<pre>
 +
const LF_WINDOWS = #13#10;
 +
const LF_LINUX = #10;
 +
</pre>
 +
Another notation could consist of mixing a lowercase c - for constant - followed by its basic type:
 +
<pre>
 +
const ciIndex = 1;
 +
const csPathHome = '/home';
 +
const ccNull = #0
 +
...\...
 
</pre>
 
</pre>

Latest revision as of 09:24, 12 November 2020

Hungarian notation in a coding style adopted by MS for C development under Windows. This variable naming technique claims to harmonize, to improve the readability of the existing variables, so to save time. Here is an example list, neither official nor fixed (the prefixes are usually based on the information theory, which concludes that consonants can be inferred in the middle of vowels. It uses too, the Camel case notation a lot). The name refection tool is perfect to use this technique easily.




Miscellaneous types:

F       Property Variable
T       Type
P       Type of pointer to another type
On      Event


Basic types:

b       Boolean
c       Char
s       String
d       for all reals\floats as Double, Extended, ...
i       for all integers as Integer, Long Integer, Smallint, ...
p       Generic Pointer
pz      PChar
...\...


Published name (controls):

btn       TButton; ex.: btnFoo1
               bbtn    TBitmap Button
               optbtn  TOption Button
               sbtn    TSpeedButton
chk       TCheck Box
cbx       TComboBox
db        TDatabase
dts       TDataSource
edt       TEdit Box
frm       TForm
grd       TDrawGrid
               sgrd   TString Grid
               dbgrd  TDBGrid
img       Image
itm       TMenuItem
lbl       TLabel
lbx       TListbox2
               dblbx  TDBListbox
mnu       TMainMenu
               pmnu   TPopup Menu
mem       TMemo
notbk     TNotebook
tabs      TTabset
tabnotbk  Tabbed Notebook
hdr       THeader
stb       TStatusBar 
outl      TOutline
pnl       TPanel
tbl       TTable
qry       TQuery
timr      Timer
fld       TField
inif      TIniFile
...\...


Components \ Objects:

cmp       TComponent
oSL       TStringList; ex.: oSLfoo
oStrm     TStream; ex.: oStrmFoo
...\...


Miscellaneous notable scope:

g  means Global, wheras its type (simple or object)


Memory scope management:

o  means, from a memory scope management, that oMyObj must be freed within the scope of its declaration; ex.: oMyObject; ex.: goMyObject
o_ means, from a memory scope management, that o_myObj must not be freed here, i.e. must not be freed in the scope of its declaration, but elsewhere, in a remote scope, where there is an statement declaration of oMyObj, which is the one where this object was created!; ex: o_myObj


Constants:

Constants are often written in uppercase ( like in C):

const LF_WINDOWS = #13#10;
const LF_LINUX = #10;

Another notation could consist of mixing a lowercase c - for constant - followed by its basic type:

const ciIndex = 1;
const csPathHome = '/home';
const ccNull = #0 
...\...