헤써니 2015. 12. 24. 00:23

Magic number

Magic number ->

constants, array sizes, character positions, conversion factors,
and other literal numeric values that appear in programs.

Give names to magic numbers.

raw number in program source gives no indication of its importance or derivation, making the program harder tounderstand and modify.

Define numbers as constants, not macros.

in C: #define int MAXROW = 24. MAXCOL = 80;

in C++: const int MAXROW = 24. MAXCOL = 80;

in JAVA: static final int MAXROW = 24, MAXCOL = 80;

 

 

A related issue is that the number 0 appears often in programs, in many contexts.

So, don't write
? str = 0;
? name[i]=0;
? x=0;


but rather:
str = NULL;
name[il = '\0';
x = 0.0;
We prefer to use different explicit constants, reserving 0 for a literal integer zero,
because they indicate the use of the value and thus provide a bit of documentation.

 

 

W O R D

constant 정수

conversion factors

opaque 불투명한, 이해하기 힘든

derivation 어원

blunt 무딘, 뭉툭한

lexical 어휘의

underfoot 발밑에