좋은 이름
1.의도가 드러나는 이름을 사용해라
int userAge; // 사용자의 나이
double accountBalance; // 계좌 잔고
String customerName; // 고객 이름
2.일관있게,의미있게 구분하라
double totalRevenue; // 총수익
double totalCost; // 총비용
double netProfit; // 순이익
3.발음하기 쉬운 이름 사용
int maxScore; // 최대 점수
int minScore; // 최소 점수
String firstName; // 이름
String lastName; // 성
4.검색하기 쉬운 이름 사용
int employeeCount; // 직원 수
String productDescription; // 제품 설명
double averageTemperature; // 평균 온도
5.클래스,객체 이름은 명사,명사구
class UserAccount {
String username;
String password;
}
class ShoppingCart {
List<Item> items;
}
6.메소드 이름은 동사,동사구
void saveUser() { /* 사용자 저장 */ }
void updateProfile() { /* 프로필 업데이트 */ }
boolean isAuthenticated() { /* 인증 여부 확인 */ }
7.한개념단어는 한개만 (controller, manager , driver 비슷한개념의 단어는 하나로만)
class UserController {
void manageUser() { /* 사용자 관리 */ }
}
class ProductController {
void manageProduct() { /* 제품 관리 */ }
}
'도서' 카테고리의 다른 글
[Clean Code] 주석 (0) | 2024.06.16 |
---|---|
[Clean Code] 함수 (1) | 2024.06.16 |