public void horriblyFormattedMethod() {
System.out.println("First line");
System.out.println("Second line");
System.out.println("Third line");
for (int i = 0; i < 3; i++)
System.out.println("number " + i);
}
내 for 문은 뭐지..?
public void horriblyFormattedMethod() {
System.out.println("First line");
System.out.println("Second line");
System.out.println("Third line");
for (int i = 0; i < 3; i++) {
System.out.println("number " + i);
}
}
이제 이해하기 좋다!
~200 lines < 500 lines
static 변수
public → protected → package → private 순서
instance 변수
public → protected → package → private
생성자
메서드
public 메서드에서 호출되는 private 메서드는 그 아래에 둔다.
가독성 위주로 그룹핑한다!
/*
* @(#)Blah.java 1.82 99/03/18
*
* Copyright (C) 1994-1998 Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
* All rights reserved.
*
* This software is the confidential and proprietary information of Sun
* Microsystems, Inc. (*Confidential Information"). You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with Sun.
*/
package java.blah;
import java.blah.blahdy.BlahBlah;
/**
*
* Class description goes here.
*
* @version 1.82 18 Mar 1999
* @author Firstname Lastname
*/
public class Blah extends SomeClass {
public static int classVar1;
private static Object classVar2; // static 변수
public Object instanceVar1;
protected int instanceVar2;
private Object[] instanceVar3; // instance 변수
public Blah() { // 생성자
// ...implementation goes here...
}
public void doSomething() { // 메서드
// ...implementation goes here...
}
public void doSomethingElse(Object someParam) {
// ...implementation goes here...
}
}
개발 언어의 컨벤션이 우선이지만, 애매한 부분은 팀 컨벤션을 따른다.
없다면, 함께 만들어 가는 것도 좋다.
해당 포스팅은 제로 베이스 클린코드 한달한권을 수강 후 정리한 내용입니다.