hsunny study blog

1.1 Names 본문

book/The Practice of Programming

1.1 Names

헤써니 2015. 12. 21. 01:30

Use descriptive names for globals, short names for locals.


 Common name for local 

* for loop indices : i, j

*for pointer: p, q

*for string: s, t




Be consistent.


BAD CASE

class UserQueue {

int noOfIternsInQ, frontOiTheQueue, queuecapacity;

public int noOfUsersInQueue() {

...

}

...


why?

Because queues can only be accessed from a variable of type UserQueue. So, member names don't need to mention "queue" at all.


GOOD CASE

class UserQueue {

int  ⓐnitem, front, capacity;

public int nuser() {

...

}

...

}


in case

ⓐname : programmers are use capital of things. ex) n means number



Use active names for functions.


example

1.

now = date .getTime() ;

putchar('\n') ;


2. when return value is a boolean type.

if (isoctal(c)) ...


Be accurate.


A name not only labels, it conveys information to the reader. 

A misleading name can result in mystifying bugs.


BAD CASE

#define isoctal(c) ((c)>='0' && (c) <= '7');




  W O R D  

proud of ~을 자랑으로 여기는

casual reader 그때그때의 독자

excerpt 발췌, 인용

puzzling 당혹케 하는

evolves 발전시키다

crucial 결정적인, 중대한

straightforward 똑바른, 정직한, (일이)간단한

arbitrary 임의의

conventional 관습적인, 형식적인

neat formatting 깔끔한 배열하는 것(?)

clever 똑똑한, 숙련된

impose

edict 칙령, 포고; 명령

instructive 교훈〔교육〕적인, 본받을 점이 많은, 도움이 되는, 계발적인

distill 다듬다, 순화하다

brevity 간결

misrepresent 잘못 전하다

illustrate 설명하다

questionable 의심스러운, 수상한

nodep ?

pronounceable 발음할 수 있는

concise 간결한, 축양된

suffice 충분하다

overkill 불필요하게 강력한 방법, 과잉, 지나침

conventional 관습적인

be encouraged to ~라고 장려받다

regardless of ~에 상관없이

sweeping rules ?

suffices 충분하다

redundant 과다한

unambiguous 명백한

octal 8진법의

consistent 일치하는

implementation 수행

intent 의향, 목적, 의지, 의미

disguise 가장하다

contradiction 부인, 부정; 반박, 반대

imply 함축하다, 암시하다



'book > The Practice of Programming' 카테고리의 다른 글

1.6 Comment  (0) 2015.12.28
1.5 Magic Number  (0) 2015.12.24
1.4 Function Macros  (0) 2015.12.23
1.3 Consistency and Idioms  (0) 2015.12.22
1.2 Expressions and Statements  (0) 2015.12.21