2007. 1. 22. 14:19

헝가리안 표기법 (Hungarian Notation)

팀 프로젝트를 수행할때 필요한것 중 하나가..
서로의 변수명과 함수명등을 결정하는 것이다.
팀 내의 규칙에 다라서 결정하는 방법도 있고..
그냥 자신의 습관에 따라 결정하는 방법도 있겠지만..

그래도 추후 타 독자의 이해를 도우면서 가독성을 높일 수 있는 방법이 가장 좋지 않을까?
그런 의미에서 헝가리안 표기법은 많은 도움을 줄 수 있다.
헝가리 태생 MS의 연구원 Charles Simonyi 가 고안한 것으로 알려져 있다.

현재 인터넷에 너무나 많은 관련 글 들이 있어.. 어디가 원본인지.. 찾아 보기 어려워..
몇군데의 내용을 모아서 정리를 해보고자 한다.. 거의 글어다 붙이기 정도지만... ㅎㅎㅎ

 

헝가리안 표기법의 목적은 개체에 대한 정보를 간결하고 효율적으로 전달하는 것이다.


헝가리안 표기법은 익숙해지려면 시간이 조금 걸리지만, 한번 익숙해지면, 그 다음부터는

아주 자연스럽게 되어 버린다.

헝가리안식 개체 이름의 형식은 다음과 같다.


[접두어] 태그 [기본이름 [접미어] ]


  * 꺾쇠괄호([])는 개체 이름에 있어서 선택적 사항임을 나타낸다.


다음은 각 항목에 대한 설명이다.


접두어 
 부가적인 의미를 나타내기 위해 태그를 보조한다. 접두어는 모두 소문자이다.
 이들은 대개 이 문서에 나오는 표준적인 접두어들 중에서 선택된다. 
 
태그
 문자들의 준말로서 그 개체의 형식을 나타낸다. 모두 소문자로 이루어지고
 마찬가지로 이 문서에 나오는 표준적인 태그들 중에서 선택된다.
 
기본이름
 개체가 무엇을 나타내는 지를 알려주는 한 두 개의 단어.
 각 단어의 첫 문자는 대문자로 만든다.
 
접미어
 기본이름의 의미를 부수적으로 도와준다. 접미어의 각 단어의 첫 문자는
 대문자로 만든다. 그리고 접미어는 이 문서에서 나오는 표준적인 접미어들
 중에서 선택된다.
 

개체 이름으로서 필수적으로 요구되는 항목은 태그이다.
이것은 조금 이상하게 보일 수 있다; 여러분은 기본이름이 개체 이름 중에 가장
중요한 요소라고 느낄 것이다. 하지만, 임의의 폼 상의 한 프로시저를 생각해 보자.
이 프로시저가 중요하긴 하지만, 그 폼 전체를 나타내는 것은 아니다.
이 프로시저가 다른 많은 형식의 폼 상에서 작동될 수 있기 때문에, 여러분이
필수적으로 기본이름을 가져야만 하는 것은 아니다.
어쨌든, 만일 여러분이 프로시저 내에서 하나 이상의 참조되는 개체를 가지고 있다면,
그들을 구분하기 위해 기본이름이 필요하다.


실 생활에서 사용되는 헝가리안 표기법은 다음과같다


a           배열
b           또는 f BOOL형 변수(b는 "bool",f는 "flag"의 약자)
by         BYTE(unsigned char)형 변수
c           카운터로 사용되는 변수
ch         char형 변수
cx,cy     x,y길이를 나타내기 위해 사용되는 변수
d           날짜형 변수
dbl        double형 변수
h          핸들(HANDLE)형 변수
n 또는 i   int형 변수
l            long형 변수
p          포인터 변수
lp          long(far)포인터 변수(32비트 프로그래밍에서는 일반 포인터와 같음)
s          문자열
sz        널(NULL)로 끝나는 문자열
u          unsigned int형 변수
w          WORD(unsigned short)형 변수
dw        DWORD(unsigned long)형 변수
str        CString형 변수
m_       멤버 변수

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


0 : 변수의 위치를 지정한다. g(전역변수), m(멤버변수), 없음(지역변수)
1 : 0 위치에 g 나 m 을 지정한 경우 _ 을 기술한다.
2 : 자료형의 종류를 나타낸다.


   n, i : 정수형(n 은 카운트 목적, i 는 인덱스 목적)
   l : long 형 (과거 int 와 구분하기 위해서 사용했다.)
   u : 부호없는 정수형
   w : 부호없는 2 byte 정수형
   dw : 부호없는 4 byte 정수형
   p : 포인터 타입
   f, d : 실수형(f 는 float, d 는 double)
   sz : char 배열(문자열 표현)
   클래스 이름에 대해서는 관습적으로 자음축약형을 사용한다.

3 ~ : 변수의 의미 있는 이름을 기술하며, 3 위치는 대문자를 사용한다. 변수 이름이 너무 긴 경우 자음만을 기술한다.
예) g_nCnt
_______________________________________________________________________________

사용자 삽입 이미지

Table 1. Some examples for procedure names

Name

Description

InitSy

Takes an sy as its argument and initializes it.

OpenFn

fn is the argument. The procedure will "open" the fn. No value is returned.

FcFromBnRn

Returns the fc corresponding to the bn,rn pair given. (The names cannot tell us what the types sy, fn, fc, and so on, are.)



Table 2. Standard type constructions

pX

Pointer to X.

dX

Difference between two instances of type X. X + dX is of type X.

cX

Count of instances of type X.

mpXY

An array of Ys indexed by X. Read as "map from X to Y."

rgX

An array of Xs. Read as "range X." The indices of the array are called:

iX
index of the array rgX.

dnX

(rare) An array indexed by type X. The elements of the array are called:

eX


(rare) Element of the array dnX.

grpX

A group of Xs stored one after another in storage. Used when the X elements are of variable size and standard array indexing would not apply. Elements of the group must be referenced by means other then direct indexing. A storage allocation zone, for example, is a grp of blocks.

bX

Relative offset to a type X. This is used for field displacements in a data structure with variable size fields. The offset may be given in terms of bytes or words, depending on the base pointer from which the offset is measured.

cbX

Size of instances of X in bytes.

cwX

Size of instances of X in words.



Table 3. Standard qualifiers

XFirst

The first element in an ordered set (interval) of X values.

XLast

The last element in an ordered set of X values. XLast is the upper limit of a closed interval, hence the loop continuation condition should be: X <= XLast.

XLim

The strict upper limit of an ordered set of X values. Loop continuation should be: X < XLim.

XMax

Strict upper limit for all X values (excepting Max, Mac, and Nil) for all other X: X < XMax. If X values start with X=0, XMax is equal to the number of different X values. The allocated length of a dnx vector, for example, will be typically XMax.

XMac

The current (as opposed to constant or allocated) upper limit for all X values. If X values start with 0, XMac is the current number of X values. To iterate through a dnx array, for example:

for x=0 step 1 to xMac-1 do ... dnx[x] ...

or

for ix=0 step 1 to ixMac-1 do ... rgx[ix] ...

XNil

A distinguished Nil value of type X. The value may or may not be 0 or -1.

XT

Temporary X. An easy way to qualify the second quantity of a given type in a scope.



Table 4. Some common primitive types

f

Flag (Boolean, logical). If qualifier is used, it should describe the true state of the flag. Exception: the constants fTrue and fFalse.

w

Word with arbitrary contents.

ch

Character, usually in ASCII text.

b

Byte, not necessarily holding a coded character, more akin to w. Distinguished from the b constructor by the capital letter of the qualifier in immediately following.

sz

Pointer to first character of a zero terminated string.

st

Pointer to a string. First byte is the count of characters cch.

h

pp (in heap).



- 참조 -

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvsgen/html/HungaNotat.asp

http://web.archive.org/web/20001018073323/www.strangecreations.com/library/c/naming.txt

http://ttongfly.net/bbs/view.php?id=windowsc&page=1&sn1=&divpage=1&sn=off&ss=on&sc=on&select_arrange=headnum&desc=asc&no=2

http://blog.naver.com/shadovv13?Redirect=Log&logNo=50012280887

http://blog.haz3.com/tag/%C7%EB%B0%A1%B8%AE%BE%C8%20%C7%A5%B1%E2%B9%FD

'Study Story > References' 카테고리의 다른 글

소프트웨어의 역량을 나타내는 말  (2) 2007.01.16