Hungarian Notation (헝가리안표기법)

10, 15년전 Microsoft의 개발자중 헝가리 사람의 프로그래머가 쓰던 변수 명명법.

MS내부에서 따라쓰기 시작하던 것이 점차 전세계의 프로그래머들에게 널리 퍼져 이젠 프로그램 코딩시 변수 명명의 표준적인 관례가 되었다.

그러나 실제로 현장에서 일하다 보면 헝가리안 표기법을 제대로 지키는 개발자는 그리 많지 않다. 어느정도 개발 경험을 가지고 있는 프로그래머는 물론 심지어 시중의 프로그래밍 서적에서 조차 저자마다 변수명을 개인에 따라 가지각색으로 짓고 있어서 처음 프로그램을 배우는 입문자들들이 변수 명명에 대한 기준을 제대로 잡지 못하고 있는 실정이다.

솔직히 필자도 얼마전까지 이런 변수 명명에 대한 관례를 잘 지키지 않았다. 그러나 변수 명명에 관한 표준화된 관례를 지켜주면 코드의 가독성을 높여줄 뿐 아니라 예를 들어 카운터 변수를 count라고 지을지 cnt라고 지을지 고민하지 않아도 되는 편리함을 누릴 수 있다.

--------------------------------------------------------------------------------
x_xXxxxxxx
0123456789

0 : 변수의 위치를 지정한다. g(전역변수), m(멤버변수), 없음(지역변수)
1 : 0 위치에 g 나 m 을 지정한 경우 _ 을 기술한다.
2 : 자료형의 종류를 나타낸다.
n, i : 정수형(n은 카운트 목적, i는 인덱스 목적)
l : long 형
u : 부호없는 정수형
w : 부호없는 2byte 정수형
dw : 부호없는 4byte 정수형
p : 포인터 타입
f, d : 실수형(f는 float, d는 double)
sz : char 배열(문자열 표현)
클래스 이름에 대해서는 관습적으로 자음축약형을 사용한다.
3 ~ : 변수의 의미 있는 이름을 기술하며, 3 위치는 대문자를 사용한다. 변수 이름이 너무 긴 경우 자음만을 기술한다. 예) g_nCnt

======================================================================================
:Prefix :Type :Description :Example
:b :bool :any boolean type :bool bTrue;
:c :char :character type :char cLetter;
:i :int :integer :int iCars;
:l :long :long type :long lDistance;
:u :unsigned :unsigned type
:f :float :floating point :float fPercent;
:d :double :double floating point :double dPercent;
:s :static :a static variable :static short ssChoice;
:rg :array :stands for range :float rgfTemp[16];
:p :* :any pointer :int *piAddr;
:sz :* :null terminated string of characters :char szText[16];
:pfn :* :function pointer :int (*pifnFunc1)(int x, int y);
:t :struct :a user defined type
:e :enum :variable which takes enumerated values
:E :enum :Enumerated type
:g_ :Global :Global Variable :String *g_psBuffer
:m_ :Member :class private member variable :
:k :constant formal parameter :void vFunc(const long klGalaxies)
:r :reference formal parameter :void vFunc(long &rlGalaxies)
:str :String :string class(C++) :String strName;
:prg :dynamically allocated array :char *prgGrades;
:h :handle :handle to something :hMenu
:n : :number, quantity :int nNum;
:x/y : :used as size :int xWitdth, yHeight;

======================================================================================

Example of type specific variable naming

unsigned char ucByte; :한 바이트 데이타
char cChar; :한 문자
unsigned char rgucByte[10]; :바이트 데이타 10개
char rgcChar[10]; :문자 데이터 10개
char szChar[16 +1]; :문자 16개를 저장할 수 있는 문자열 공간


:Data Type :Description
BYTE unsigned char type
WORD unsigned short type
DWORD unsigned long type

+ Recent posts