<div><span style="font-size:9pt;line-height:1.5;"><font face="맑은 고딕">최근에 자주 들어와서 되도않은 댓글을 좀 달아드리고 있는 사람입니다.</font></span></div> <div><font face="맑은 고딕">올려놓은 소스를 보다보니 재밌는 내용도 많고 잘 모르는 내용도 있어서</font></div> <div><font face="맑은 고딕">구글에서 검색해 보기도 하고 해서 재밌는데요.</font></div> <div><font face="맑은 고딕"><br></font></div> <div><font face="맑은 고딕">하나 같이 코딩컨벤션이나 style guide를 전혀 본 적이 없이 그냥 코드를 작성하고 있어서</font></div> <div><font face="맑은 고딕">이 참에 좀 도와드리고자 씁니다. 더 자세한 사항은 coding convention, c++ style guide, java style guide 이런 류를 검색해 보시면 더 자세한 내용을 보실 겁니다. </font></div> <div><font face="맑은 고딕"><br></font></div> <div><font face="맑은 고딕">coding convention은 소스코드를 구성하는 규칙이라고 생각하면 되고,</font></div> <div><font face="맑은 고딕">규칙들이 너무 많아서 전부다 설명해 드릴 수는 없고,</font></div> <div><font face="맑은 고딕">여러 convention 규칙 중에서 그나마 공통적인 부분을 뽑아내서 보니 아래 정도.</font></div> <div><font face="맑은 고딕">대다수 분들이 이 정도면 보기에 편하다고 느끼는 정도라고 생각하면 무난할 듯.</font></div> <div><font face="맑은 고딕"><br></font></div> <div><font face="맑은 고딕">- 한라인은 80자 이내.</font></div> <div><font face="맑은 고딕">- 변수 선언은 한라인에 하나만.</font></div> <div><font face="맑은 고딕">- 연산자 좌우로 space 추가. a + b</font></div> <div><font face="맑은 고딕">- unary 연산자는 붙임. ++a, i++, ~i, !i, &i, *i</font></div> <div><font face="맑은 고딕">- = assign 좌우로 space 추가. a = 10;</font></div> <div><font face="맑은 고딕">- ()는 (a + b) + 3</font></div> <div><font face="맑은 고딕">- 함수 호출은 callProc() </font></div> <div><font face="맑은 고딕">- 함수 선언도 function callProc() {</font></div> <div><font face="맑은 고딕">- for, if, switch, while 다음에 space. for (), if (), switch () { }</font></div> <div><font face="맑은 고딕">- indent는 tab = 4 정도인데, 구글은 2, linux kernel은 8</font></div> <div><font face="맑은 고딕">- indent에 tab 안쓰고 space char 사용이 추세.</font></div> <div><font face="맑은 고딕">- backspace가 unindent가 안되는 에디터는 tab 키 indent, shift-tab 키 unindent</font></div> <div><font face="맑은 고딕">- []는 변수명에 붙임 a[1][1], a[1], a[i + j + 1]</font></div> <div><font face="맑은 고딕">- 문장이 길어서 여러줄로 될 경우, operator 앞에서 끊고 다음줄로.</font></div> <div><font face="맑은 고딕">- 함수명은 동사로 시작, + 목적어로 주로 구성.</font></div> <div><font face="맑은 고딕">- 변수명은 주로 명사</font></div> <div><font face="맑은 고딕"><br></font></div> <div><font face="맑은 고딕">int a;</font></div> <div><font face="맑은 고딕">int b;</font></div> <div><font face="맑은 고딕">int a, b;<span class="Apple-tab-span" style="white-space:pre;"> </span>// avoid하라는 편이 많음.</font></div> <div><font face="맑은 고딕">int a, b[];<span class="Apple-tab-span" style="white-space:pre;"> </span>// - avoid</font></div> <div><font face="맑은 고딕">char ch, *ptr, charray[];<span class="Apple-tab-span" style="white-space:pre;"> </span>// 대표적인 avoid</font></div> <div><font face="맑은 고딕"><br></font></div> <div><font face="맑은 고딕">for (i = 0; i < MAX_LEN; i++) {</font></div> <div><font face="맑은 고딕">for(i=0;i<MAX_LEN;i++){<span class="Apple-tab-span" style="white-space:pre;"> </span>// avoid</font></div> <div><font face="맑은 고딕">for(i = 0; i < MAX_LEN; i++){<span class="Apple-tab-span" style="white-space:pre;"> </span>// avoid</font></div> <div><font face="맑은 고딕">for (i = 0, j = 0; i < MAX_LEN && j < MAX_LEN; i++, j++) {</font></div> <div><font face="맑은 고딕"><br></font></div> <div><font face="맑은 고딕">if(a == b){<span class="Apple-tab-span" style="white-space:pre;"> </span>// avoid</font></div> <div><font face="맑은 고딕">if (a == b) {<span class="Apple-tab-span" style="white-space:pre;"> </span></font></div> <div><font face="맑은 고딕">switch (a) {</font></div> <div><font face="맑은 고딕"><br></font></div> <div><font face="맑은 고딕">a = (b + c) * d + f++;<span class="Apple-tab-span" style="white-space:pre;"> </span></font></div> <div><font face="맑은 고딕">a = (b + c)</font></div> <div><font face="맑은 고딕"><span class="Apple-tab-span" style="white-space:pre;"> </span>* d + f++;<span class="Apple-tab-span" style="white-space:pre;"> </span>// 2라인으로 구분시 operator를 앞에 둠.</font></div> <div><font face="맑은 고딕"><br></font></div> <div><font face="맑은 고딕">char* ptr;</font></div> <div><font face="맑은 고딕">char *ptr;</font></div> <div><font face="맑은 고딕">char& ptr;</font></div> <div><font face="맑은 고딕">char &ptr;</font></div> <div><font face="맑은 고딕"><br></font></div> <div><font face="맑은 고딕">char * ptr; <span class="Apple-tab-span" style="white-space:pre;"> </span>// avoid</font></div> <div><font face="맑은 고딕">char & ptr; <span class="Apple-tab-span" style="white-space:pre;"> </span>// avoid</font></div> <div><font face="맑은 고딕"><br></font></div> <div><font face="맑은 고딕">if (cond1 && cond2 </font></div> <div><font face="맑은 고딕"><span class="Apple-tab-span" style="white-space:pre;"> </span>&& cond3 </font></div> <div><font face="맑은 고딕"><span class="Apple-tab-span" style="white-space:pre;"> </span>&& cond4) {</font></div> <div><font face="맑은 고딕"><span class="Apple-tab-span" style="white-space:pre;"> </span>a = b + c;</font></div> <div><font face="맑은 고딕">}</font></div> <div><font face="맑은 고딕"><br></font></div> <div><font face="맑은 고딕">대충 이정도만 지켜도 소스가 한결 보기 편하고 타인들도 이해하기가 쉬울 꺼임.</font></div> <div><font face="맑은 고딕">예전에는 나만의 코딩 스타일이 있어서 고수하려고 노력했는데,</font></div> <div><font face="맑은 고딕">팀으로 개발해야 하는 상황이 되다보니 인수인계나 소스 이해도 측면에서 자기 스타일을 고수하면 안되었음. </font></div> <div><font face="맑은 고딕">코딩 컨벤션은 절대적인 것이나 옳고 그름의 문제가 아니고 합의와 준수의 문제이므로 </font></div> <div><font face="맑은 고딕">나와 다르다고 우기거나 반대할 이유는 전혀 없음.</font></div> <div><font face="맑은 고딕"><br></font></div> <div><font face="맑은 고딕">제일 웃긴 코딩규칙 중에</font></div> <div><font face="맑은 고딕">for( i = 0; i < MAX_LEN; i++ ) { </font></div> <div><font face="맑은 고딕">preg_match( $a, $b );</font></div> <div><font face="맑은 고딕">이런 류가 있어서 머 이런 게 다 있나 했더니 php 소스 중에 이런 convention이 있었음.</font></div> <div><br></div>
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.