-
[Clean Code] 형식 맞추기Dev/정리 2022. 5. 17. 21:03
포맷팅이 중요한 이유
1. 가독성에 필수적이다
코드를 수월하게 읽어나갈 수 있다.
아마추어처럼 보이지 않는다.
포맷팅으로 인해 코드를 잘못해석해 버그를 발생할 위험을 줄인다.
2. 200라인
협업에서의 대부분의 코드들도 200라인 정도를 유지한다
코드 길이가 200라인을 넘어간다면, 클래스가 여러 개의 일을 하고 있을 수 있다. SRP에 위배된다.
3. 밀접한 개념은 서로 가까이 둔다.
행 묶음은 완결된 생각 하나를 표현하기 때문에 개념은 빈 행으로 분리한다.
변수는 사용되는 위치에서 최대한 가까이 선언한다.
Java Class Declarations
Class 내부 코드 순서
1. static 변수
public -> protected -> package -> private 순서
2. instance 변수
public -> protected -> package -> private
3. 생성자
4. 메서드
public 메서드에서 호출되는 private 메서드는 그 아래에 둔다. 가독성 위주로 그룹핑하기
Coding Convention
팀의 코딩스타일에 관한 약속
예를 들어, MySql Convention 컬럼명은 snake_case로 네이밍한다.
Team Convention
enum 타입으로 사용하는 varchar 타입의 경우 컬럼명을 _type으로 끝나도록 네이밍한다.
참고할 만한 컨벤션
GoogleJavaStyleGuide
https://google.github.io/styleguide/javaguide.html
NaverHackdayJavaConvention
https://naver.github.io/hackday-conventions-java/
'Dev > 정리' 카테고리의 다른 글
[Spring Security] 스프링 시큐리티 주요 아키텍처 (0) 2023.01.20 [Clean Code] 함수 (0) 2022.05.15 [Clean Code] 깨끗한 코드, 의미 있는 이름 (0) 2022.05.14