// 빈 행을 넣지 않을 경우
package fitnesse.wikitext.widgets;
import java.util.regex.*;
public class BoldWidget extends ParentWidget {
public static final String REGEXP = "'''.+?'''";
private static final Pattern pattern = Pattern.compile("'''(.+?)'''",
Pattern.MULTILINE + Pattern.DOTALL);
public BoldWidget(ParentWidget parent, String text) throws Exception {
super(parent);
Matcher match = pattern.matcher(text); match.find();
addChildWidgets(match.group(1));}
public String render() throws Exception {
StringBuffer html = new StringBuffer("<b>");
html.append(childHtml()).append("</b>");
return html.toString();
}
}
// 빈 행을 넣을 경우
package fitnesse.wikitext.widgets;
import java.util.regex.*;
public class BoldWidget extends ParentWidget {
public static final String REGEXP = "'''.+?'''";
private static final Pattern pattern = Pattern.compile("'''(.+?)'''",
Pattern.MULTILINE + Pattern.DOTALL
);
public BoldWidget(ParentWidget parent, String text) throws Exception {
super(parent);
Matcher match = pattern.matcher(text);
match.find();
addChildWidgets(match.group(1));
}
public String render() throws Exception {
StringBuffer html = new StringBuffer("<b>");
html.append(childHtml()).append("</b>");
return html.toString();
}
}
// 의미 없는 주석으로 두 인스턴스 변수를 떨어져있는 경우
public class ReporterConfig {
/**
* 의미 없는 주석 1
*/
private String m_className;
/**
* 의미 없는 주석 2
*/
private List<Property> m_properties = new ArrayList<Property>();
public void addProperty(Property property) {
m_properties.add(property);
}
}
// 의미 없는 주석을 제거
public class ReporterConfig {
private String m_className;
private List<Property> m_properties = new ArrayList<Property>();
public void addProperty(Property property) {
m_properties.add(property);
}
연관성이 깊을수록 세로로 가까이 둬야 한다
시스템이 무엇을 하는지 이해하고 싶은데, 이 조각 저 조각 어디에 있는지 찾고 기억하느라 시간과 노력을 소모하지 말자
호출 되는 함수를 호출하는 함수보다 나중에 배치한다
private void measureLine(String line) {
lineCount++;
int lineSize = line.length(); // 할당 연산자를 강조하기위해 앞뒤에 공백을 준다
totalChars += lineSize;
lineWithHistogram.addLine(lineSize, lineCount);
recordWidestLine(lineSize);
}
// 코드의 엉뚱한 부분을 강조해 진짜 의도가 가려진다
// 선언문과 할당문을 굳이 별도로 정리할 필요가 없다
public class FitNesseExpediter implements ResponseSender {
private Socket socket;
private InputStream input;
private OutputStream output;
private Reques request;
private Response response;
private FitNesseContex context;
protected long requestParsingTimeLimit;
private long requestProgress;
private long requestParsingDeadline;
private boolean hasError;
...
}
// after
public class FitNesseExpediter implements ResponseSender {
private Socket socket;
private InputStream input;
private OutputStream output;
private Reques request;
private Response response;
private FitNesseContex context;
protected long requestParsingTimeLimit;
private long requestProgress;
private long requestParsingDeadline;
private boolean hasError;
...
}
팀으로 하는 프로젝트일수록 가독성과 유지보수를 생각하며 팀 규칙인 코드 형식을 지키는건 중요하다. 내 코드를 읽는 다른사람을 생각하며...