-
Notifications
You must be signed in to change notification settings - Fork 3
Code Convention
๊ธฐ๋ณธ์ ์ผ๋ก ๊ณต์๋ฌธ์์ธ Kotlin Coding Conventions๊ณผ Kotlin style guide๋ฅผ ์ค์ํ๋ค.
์๋๋ก์ด๋ ์คํ๋์ค์ Optimize imports ๊ธฐ๋ฅ๊ณผ Reformat Code ๊ธฐ๋ฅ์ ์ด์ฉํ๋ค.
-
Optimize imports(Ctrl+Alt+O): ์ฌ์ฉํ์ง ์๋ Class๋ฅผ importํ๊ณ ์๋ ๊ฒฝ์ฐ ์ ๊ฑฐํด์ค๋ค. -
Reformat Code(Ctrl+Alt+L): ์ฝ๋์ Kotlin Style Guide๋ฅผ ์ ์ฉํ์ฌ Code๋ฅผ Reformatํ๋ค.
View ์ด๋ฆ์ ์ถ์ฝํ์ฌ Camel Case๋ก ๋ณํํ ๊ฒ์ Prefix๋ก ์ฌ์ฉํ๋ค.
<WHAT>_<DESCRIPTION>
| View | Prefix |
|---|---|
| TextView | text |
| ImageView | image |
| EditText | edit |
| Button, ImageButton | button |
| Toolbar | toolBar |
| ConstraintLayout | layout |
| LinearLayout | layout |
| BottomNavigationView | bottomNavi |
| .. | .. |
@+id/textLogin
@+id/editPassword
@+id/buttonLoginLayout์ xml ํ์ผ์ ์ด๋ฆ์ .kt .java์ Pascal Case๋ฅผ Snake Case๋ก ๋ณํํ์ฌ ์ฌ์ฉํ๋ค.
<WHAT>_<WHERE>
| View | Prefix |
|---|---|
| Activity | activity_ |
| Fragment | fragment_ |
| Dialog | dialog_ |
| CustomView | view_ |
| Item | item_ |
SignInActivity.kt -> activity_sign_in.xml
SignUpFragment.kt -> fragment_sign_up.xml
CustomCalendarView.kt -> view_custom_calendar.xml
item_user.xml
<WHAT_DESCRIPTION>
| Drawable | Prefix |
|---|---|
| Icon | ic_ |
| Image | img_ |
| Background | bg_ |
| Shape | <shape>_<color>_<radius>_<value> |
ic_error.xml
img_default_user.xml
bg_main.xml
rectangle_yellow_radius_20.xml
menu_
Color์ ์ด๋ฆ์ Camel Case๋ฅผ ์ด์ฉํด ์์ฑํ๋, ์ฌ์ดํธ๋ฅผ ์ฐธ๊ณ ํด Color๋ฅผ ์ง๊ด์ ์ผ๋ก ์ฐ์ํ ์ ์๋ ์ด๋ฆ + RGB ์ด๋ฆ์ ์กฐํฉํ์ฌ ์ฌ์ฉํ๋ค. ์ด๋ ์ค๋ณต๋๋ ๊ฒฝ์ฐ์๋ ์์ ๋๊ธ์๋ง ์ ๋๋ค.
<color name="blackFF000000">#FF000000</color>
<color name="whiteFF">#FFFFFFFF</color>
<color name="cornflowerBlue6195ED">#6195ED</color>View์ Pascal Case์ Style์ ๋ํ ์ค๋ช ์ ์กฐํฉํ์ฌ Style ๋ช ์ ์ง์ ํ๋ค.
<WHAT><Description>Style
<style name="LoginEditTextStyle"/>
<style name="MainDialogStyle"/>ํ์ฌ View์ด๋ฆ๊ณผ ํด๋นํ๋ String ์ค๋ช ์ ์กฐํฉํ์ฌ string๋ช ์ ์ง์ ํ๋ค. ์ด๋ lowerCamelCase๋ก ์ด๋ฆ์ ์์ฑํ๋ค.
<string name="homeCancel">
<string name="myPagePlus">## 3. Kotlin Naming Convention
ํด๋์ค ํ์ผ ์ด๋ฆ์ UpperCamelCase(ํ์ค์นผ ์ผ์ด์ค(PascalCase))๋ก ์์ฑํ๋ค.
<DESCRIPTION><WHAT>
Prefix๋ ํด๋น ํด๋์ค์ ๊ด๋ จ์ฑ์ด ๋์ ๊ฒ์ผ๋ก ์์๋ก ์์ฑํ๋ค.
MainActivity
UserViewModel
WriteFragment๋ฉ์๋ ์ด๋ฆ์ lowerCamelCase๋ก ์์ฑํ๋ค.
"๋์ฌ"๋ก ์์ํ๋ "๋์ฌ๊ตฌ" ํํ๋ฅผ ์ฌ์ฉํ๋, ๋์ฌ ์ํ๋ง์ ์ฌ์ฉํ๋ค.
์์ฃผ ์ฌ์ฉํ๋ ๋์ฌ๋ ์ฉ๋ฒ์ ๋ง๊ฒ ์ฌ์ฉํ๋ค.
| Word | Description |
|---|---|
| show | Invisibleํ ๊ฒ์ Visibleํ๊ฒ ๋ฐ๊พธ๋ ๋์ |
| check | ์ด๋ค ๊ฒ์ ํ์ธํ ํ boolean ๋๋ ๊ฐ์ผ๋ก ๋ฐํํ๋ ๋์ |
| is | ์ด๋ค ๊ฒ์ธ์ง ํ์ธํ ํ boolean์ผ๋ก ๋ฐํํ๋ ๋์ |
| has | ์ด๋ค๊ฒ์๊ฐ์ง๊ณ ์๋ ํ์ธ ํ boolean์ผ๋ก ๋ฐํํ๋ ๋์ |
showList
updateContacts๋ณ์ ์ด๋ฆ ๋ํ ๋ง์ฐฌ๊ฐ์ง๋ก lowerCamelCase๋ก ์์ฑํ๋ค.
isEnd
viewPagerAdapter