2. 왜? 형식을 맞추나?
코드 형식은 의사소통의 일환이다
시간이 지나 코드의 흔적을
더이상 찾아보기 어려울 정도로
코드가 바뀌어도 개발자의 스타일과 규
사라지지 않는다.
3. 적절한 행 길이
Vertical Formatting 77
Figure 5-1
File length distributions LOG scale (box height = sigma)
일반적으로 큰 파일보다는 작은 파일이 이해
Junit, FitNesse, and Time and Money are composed of relatively small files. None
are over 500 lines and most of those files are less than 200 lines. Tomcat and Ant, on the
other hand, have some files that are several thousand lines long and close to half are over
200 lines.
What does that mean to us? It appears to be possible to build significant systems
4. Consider, for example, Listing 5-1. There are blank li
Vertical Formatting 79
declaration, the import(s), and each of the functions. This ex
found effect on the visual layout of the code. Each blank lin
개념은 빈행으로 분리하라
a new and separate concept. As you scan down the listing,
line that follows a blank line.
Listing 5-2
Listing 5-1
BoldWidget.java BoldWidget.java
package fitnesse.wikitext.widgets; package fitnesse.wikitext.widgets;
import java.util.regex.*; import java.util.regex.*;
public class BoldWidget extends ParentWidget {
public static final String REGEXP = "'''.+?'''";
public class BoldWidget extends ParentWidget {
private static final Pattern pattern = Pattern.compile("'''(.+?)'''",Pattern pattern"'''.+?'''";
public static final String REGEXP =
private static final = Pattern.com
Pattern.MULTILINE + Pattern.DOTALL); Pattern.MULTILINE + Pattern.DOTALL
public BoldWidget(ParentWidget parent, String text) throws Exception {
);
super(parent); public BoldWidget(ParentWidget parent, String text
Matcher match = pattern.matcher(text); super(parent);
match.find(); Matcher match = pattern.matcher(text);
match.find();
addChildWidgets(match.group(1));} addChildWidgets(match.group(1));
public String render() throws Exception { }
StringBuffer html = new StringBuffer("<b>");
public String render() throws Exception {
html.append(childHtml()).append("</b>"); StringBuffer html = new StringBuffer("<b>");
return html.toString(); html.append(childHtml()).append("</b>");
} return html.toString();
}
} }
This effect is even more pronounced when you unfocus your eyes. Inlines first example
Taking those blank the out, as in Listing 5-2, has a remar
the different groupings of 일련의 행 묶음은 완결된 생각하나를 표현한다readability of the code.
lines pop out at you, whereas the second example looks like a
muddle. The difference between these two listings빈 bit of v ertical openness. 분리해야 마땅하
생각 사이는 is a 행을 넣어서
5. 종속함수
public void Make() {
String name = GetName();
if(name != null)
SendName(name);
else
PrintError();
}
public String GetName() {
}
public void SendName() {
}
public void PrintError() {
프로그램이 자연스럽게 읽힐수 있게 함수를 배
모듈 전체의 가독성도 높아진다.
6. 가로 정렬
private Socket socket;
private InputStream input;
private OutputStream output;
protected FitNesseContext context;
코드가 엉쭝한 부분을 강조해 진짜 의도가 가려
변수유형을 무시하고 변수 이름부터 읽게 된다.
private Socket socket;
private InputStream input;
private OutputStream output;
protected FitNesseContext context;
정렬이 필요할 정도로 목록이 길다면 문제는 목
7. 형식...
변수는 사용하는 위치에 최대한 가까이 선언한다.
인스턴스 변수는 잘 알려진 위치에 모은다.
비슷한 동작을 수행하는 함수들은 가까이 배치한다.
함수 호출 종속성을 아래 방향으로 유지한다.
들여쓰기를 사용하여 코드 구조가 한눈에 들어오게 한
8. 가장 중요한것.
팀에 속해서 프로그래밍을 한다면,
팀이 정한 규칙을 따라야 한다.
그래야 소프트웨어가 일관적인 스타일을 보인다