Code Convention - leegwichan/StackOverFlow_Refactoring GitHub Wiki
๊ธฐ๋ณธ์ ์ธ Code Convention
์ฐธ๊ณ ์๋ฃ
- ์์ธํ ๋ด์ฉ์ Google Java Style Guide ์ฐธ๊ณ
2. Source file basics
- 2.1 File name
- ๊ฐ์ฅ ์์์ ์์ฑ๋ class ์ด๋ฆ๊ณผ ๋์ผ, ํ์ฅ์๋ .java๋ฅผ ์ฌ์ฉ
- 2.2 File encoding: UTF-8
- 2.3 Special characters
- Whitespace characters
- ์์ค ํ์ผ์์๋ ASCII horizontal space character (0x20) ๋ง์ ์ฌ์ฉํ๋ค.
- Special escape sequences
- ํน์ ๋ฌธ์(\b, \t, \n, \f, ...)๋ค์ octal, Unicode ํ์์ด ์๋ "\n" ๊ณผ ๊ฐ์ ํ์์ ์ฌ์ฉํ๋ค.
- Non-ASCII characters
- ์๋์ ๊ฐ์ ๋ฐฉ๋ฒ์ ์ด์ฉํ๋ค.
// ๊ฐ์ฅ ์ข์ ๋ฐฉ๋ฒ String unitAbbrev = "ฮผs"; // ๋ํ๋ผ ์ ์๋ ๋ฌธ์์๋ Unicode๋ฅผ ์ฌ์ฉํ๊ณ ํ์ํ ๊ฒฝ์ฐ ์ฃผ์์ ๋ฌ ์ ์๋ค. return '\ufeff' + content; // byte order mark
- Whitespace characters
3. Source file structure
- ์๋์ ๊ฐ์ ์์๋๋ก ์์ฑํ๊ณ ๊ฐ ๋ถ๋ถ๋ง๋ค BLANK LINE์ ๋ง๋ ๋ค.
- 3.1 License or copyright information
- ์๋ค๋ฉด ์์ฑํ๊ณ ์๋๋ฉด ์์ฑํ์ง ์๋๋ค.
- 3.2 Package statement
- 3.3 Import Statement
- No wildcard imports : ๋ค์ "*"์ ์ด์ฉํด์ ์ฌ๋ฌ class, method๋ฅผ importํ์ง ์๋๋ค.
- Ordering and spacing : static imports ๋ฅผ ์ฐ์ ์ ์ผ๋ก ์ ๊ณ non-static imports๋ฅผ ํ์นธ ๋๊ณ ์ ์
- 3.4 Class declaration
4. Formatting
5. Naming
6. Programming Practices
๋ณด๊ธฐ ํธํ๊ธฐ ์ํ Code Convention
1. method
- ๋ฉ์๋์ ๊ธธ์ด๊ฐ 15๋ผ์ธ์ ๋์ด๊ฐ์ง ์๋๋ก ๊ตฌํํ๋ค.
- ๋ฉ์๋๊ฐ ํ ๊ฐ์ง ์ผ๋ง ํ๋๋ก ์ต๋ํ ์๊ฒ ๋ง๋ค์ด๋ผ.
- ๋ฉ์๋์ ํ๋ผ๋ฏธํฐ ๊ฐ์๋ ์ต๋ 3๊ฐ๊น์ง๋ง ํ์ฉํ๋ค.
2. ๋ฐ๋ณต๋ฌธ, ์กฐ๊ฑด๋ฌธ
- indent(์ธ๋ดํธ, ๋ค์ฌ์ฐ๊ธฐ) depth๋ฅผ 3์ด ๋์ง ์๋๋ก ๊ตฌํํ๋ค. 2๊น์ง๋ง ํ์ฉํ๋ค.
- ์๋ฅผ ๋ค์ด while๋ฌธ ์์ if๋ฌธ์ด ์์ผ๋ฉด ๋ค์ฌ์ฐ๊ธฐ๋ 2์ด๋ค.
- 3ํญ ์ฐ์ฐ์๋ฅผ ์ฐ์ง ์๋๋ค.
- else ์์ฝ์ด๋ฅผ ์ฐ์ง ์๋๋ค.
- switch/case๋ ์ต์ํ์ผ๋ก ์ฌ์ฉํ๋ค.
3. ํ ์คํธ
- JUnit 5์ AssertJ๋ฅผ ์ด์ฉํ์ฌ ๋ณธ์ธ์ด ์ ๋ฆฌํ ๊ธฐ๋ฅ ๋ชฉ๋ก์ด ์ ์ ๋์ํจ์ ํ ์คํธ ์ฝ๋๋ก ํ์ธํ๋ค.