티스토리 뷰

 세상에서 제일 열받는 이름 짓기. 코딩하는 시간보다 이름 짓는 시간이 더 길어서 올라오는 빡침.

 

[ 가장 도움되는 팁 ]

English language

Use English language when naming your variables and functions.

/* Bad */ 
const primerNombre = 'Gustavo' const amigos = ['Kate', 'John'] 

/* Good */ 
const firstName = 'Gustavo' 
const friends = ['Kate', 'John']

Like it or not, English is the dominant language in programming: the syntax of all programming languages is written in English, as well as countless documentations and educational materials. By writing your code in English you dramatically increase its cohesiveness.

Naming convention

Pick one naming convention and follow it. It may be camelCase, PascalCase, snake_case, or anything else, as long as it remains consistent. Many programming languages have their own traditions regarding naming conventions; check the documentation for your language or study some popular repositories on Github!

/* Bad */ const page_count = 5 const shouldUpdate = true /* Good */ const pageCount = 5 const shouldUpdate = true /* Good as well */ const page_count = 5 const should_update = true

S-I-D

A name must be short, intuitive and descriptive:

  • Short. A name must not take long to type and, therefore, remember;
  • Intuitive. A name must read naturally, as close to the common speech as possible;
  • Descriptive. A name must reflect what it does/possesses in the most efficient way.

/* Bad */ const a = 5 // "a" could mean anything const isPaginatable = a > 10 // "Paginatable" sounds extremely unnatural const shouldPaginatize = a > 10 // Made up verbs are so much fun! /* Good */ const postCount = 5 const hasPagination = postCount > 10 const shouldPaginate = postCount > 10 // alternatively

Avoid contractions

Do not use contractions. They contribute to nothing but decreased readability of the code. Finding a short, descriptive name may be hard, but contraction is not an excuse for not doing so.

/* Bad */ 
const onItmClk = () => {} 

/* Good */ 
const onItemClick = () => {}

Avoid context duplication

A name should not duplicate the context in which it is defined. Always remove the context from a name if that doesn't decrease its readability.

class MenuItem {
	/* Method name duplicates the context (which is "MenuItem") */ 
    handleMenuItemClick = (event) => { ... } 
    
    /* Reads nicely as `MenuItem.handleClick()` */ 
    handleClick = (event) => { ... } 
}

Reflect the expected result

A name should reflect the expected result.

/* Bad */ 
const isEnabled = itemCount > 3 
return <Button disabled={!isEnabled} /> 

/* Good */
const isDisabled = itemCount <= 3 
return <Button disabled={isDisabled} />

 

Naming functions

A/HC/LC Pattern

There is a useful pattern to follow when naming functions:

prefix? + action (A) + high context (HC) + low context? (LC)

Take a look at how this pattern may be applied in the table below.

Name Prefix Action High context (HC) Low context (LC)
getUser   get User  
getUserMessages   get User Messages
handleClickOutside   handle Click Outside
shouldDisplayMessage should Display Message  

Note: The order of context affects the meaning of a variable. For example, shouldUpdateComponent means you are about to update a component, while shouldComponentUpdate tells you that component will update on itself, and you are but controlling when it should be updated. In other words, high context emphasizes the meaning of a variable.

 

 

 * Reference

1. github.com/kettanaito/naming-cheatsheet : 이름 짓는 법, 위의 내용을 긁어온 것. naming rule만 긁어온 것.

2. dev.to/maikomiyazaki/beginner-s-cheat-sheet-commonly-used-verbs-for-naming-functions-methods-and-variables-509i : 이름 지을 때 자주 사용되는 동사와 그 의미 정리

3. docs.aws.amazon.com/IAM/latest/APIReference/welcome.html : API 예시

4. tistory.github.io/document-tistory-apis/apis/v1/post/list.html : 티스토리 API

5. docs.aws.amazon.com/ko_kr/quicksight/latest/APIReference/API_Reference.html : 아마존 API

 

[ bool 변수 이름 짓기 ]

  - is 용법

 - 조동사 용법

 - has 용법

 - 동사원형 용법

 

 * 정말 자세한 Reference ; https://soojin.ro/blog/naming-boolean-variables

 

[ commit message 이름 짓기 ]

 

 * Reference:

1. https://beomseok95.tistory.com/328

 

[ Mapper ]

 - 중간에서 데이터를 전달하는 역할과 동시에 DB에 접근하니까 그걸 생각해서 이름을 짓는 게 좋겠다.

 - Action + High context + Low context + By + Used parameter

 - List 같은 단어를 붙여서 복수를 표현하지 말고 복수형 명사를 사용할 것. 그리고 반환타입에 List<E>식으로 보일 텐데 굳이 붙일 필요가 있나 모르겠다. 아니면 차라리 List를 동사로 사용해서 ListUsers 같은 게 낫겠다.

 - Action은 insert, read, delete, update로 다 통일

 

 - listPosts, readPosts 두 가지 경우로 나눠야겠다. list + 복수명사는 말 그대로 리스트를 만들 때 사용한다. 리스트의 경우 post 내의 모든 내용이 필요하지 않다. 번호, 제목, 작성자, 작성 날짜, 조회수 정도만 필요하다. getPosts를 쓸 땐 post의 모든 내용이 필요할 때로 정하자.

 - 바로 위 내용에 대한 추가 견해이다. 굳이 저렇게 구분하지 말고 어떤 설정값에 따라 가져오는 내용을 다르게 하도록 함수를 구현하는 것이 더 좋지 않을까 생각한다. 일단은 모든 내용을 다 가져온다 가정하고 복수형을 붙여 이름을 짓도록 한다.

 - 이거 계속 생각해보니 get, list 두 개를 이용해서 구분하는 것이 좋지 않다는 근거가 계속 생각난다. 다른 사람들이 getUsers, ListUsers를 봤을 때 이 둘의 차이점을 인지할 수 있는 방법이 없다. 따로 레퍼런스를 정리해서 보여주는 것이 아니라면. 반면에 어떤 설정값을 통해 가져오는 내용에 차이를 두게 하면 그 설정값의 이름을 통해 어떤 정보를 가져올지 예측할 수 있도록 도와준다. 그리고 확장에도 좀 더 유리한 구조가 될 것 같다. 그런데 이런 함수는 service에서 구현하는 게 낫지 않을까 생각한다. 어떤 로직을 유연하게 처리하려면 Mybatis 내장 기능보단 java로 짜는 것이 더 편하니까. 이런 점을 고려해서 프로그램을 개선해야겠다.

 

 -  어떤 객체들을 얻을 때 필요한 조건들을 전달하는 객체가 있으면 parameter type이 같아서 method overloading이 안 되는 경우를 다 커버할 수 있을 것 같다. 조건에 따라 걸러낸다는 느낌으로 Filter라는 이름으로 객체를 정의하면 될 것 같은데 ? getPosts(PostFilter filter) 같은 방식으로 데이터를 얻어오면 되지 않을까 싶다. 조건 붙이는 방법은 mybatis 동적 sql 참고해서 작업하면 될 것 같다. 일단은 이렇게 해두고 나중에 테스트 책이랑 리팩토링 책 같이 보면서 싹 다 뜯어고쳐봐야겠다.

 

[ Service ]

 - 요청을 직접 처리한다는 의미가 강하다. 제공하는 서비스에 따라 적당히 CRUD를 정하고 맨 위의 규칙을 지킨다.

 - method overloading으로 함수 길이를 줄일 수 있을까 생각했지만 안 된다. getUser(String userId)와 getUser(String nickname)만 봐도 같은 String이기 때문에 구별할 방법이 없다.

 - post, user : register, get, modify, delete로 통일

 

 

[ Controller ]

 - 이름 붙일 때 규칙은 HTTP request method name + 기능으로 이름 붙이면 될 것 같다.

 - ex) getLoginForm : Login form을 달라는 요청에 대한 처리, postLoginForm : Login form을 제출하는 요청에 대한 처리

 

[ JSP file ]

 - camel case로 이름 지을 것

 - 사용자가 무엇을 입력한 걸 처리하는 형식이면 마지막에 form을 붙여야겠다. "게시판 등록 서류 제출 할게요 ~", "회원등록 서류 제출할게요 ~" 같은 느낌이라 직관적이다. 서류 처리한다는 이미지로 생각하고 이름 붙이면 자연스러울 것 같다.

 - 기능을 기준으로 이름을 짓는다. ex) 로그인 - login.jsp, 회원가입 - signup.jsp

 

 

 * Reference

1. pythonq.com/so/jsp/242071

2. www.oracle.com/technical-resources/articles/javase/code-convention.html : JSP Names를 검색하면 자료가 나옴.

 

[ HTML ]

 - 하다 하다 HTML class 이름까지 붙이게 생겼네.

 - BEM 참고할 것. HTML, 디자인 글에 해당 내용 링크가 있음. 나중에 보고 정리할 것.

 

 

[ 영단어 의미 정리 ]

 - get vs fetch vs obtain : get은 가장 넓은 의미로 거의 모든 상황에서 사용됨. fetch는 뭔가를 가지고 오도록 해서 얻는 것 (강아지 원반 던지기)

 

 - register vs enroll : There is a difference between registration and enrollment. The process of signing up for courses is called registering. Students are charged tuition and fees when they register. Students are enrolled after they pay the tuition and fees.

 

 - add, remove : 둘 다 어떤 group에(서) 하나를 추가하거나 제거하는 의미로 사용.

 

 - remove vs delete : remove는 일부만 제거, delete는 전체 제거

 

 - source vs resource : A source is a place or person from which you can obtain something useful or valuable. A resource is something that can be used to perform some function.

 

 - edit vs modify : Specifically a "modification" is any change. An "edit" is correction, revision, or preparation for publication.

 

 - point vs score : score의 뜻은 the number of points, goals, runs, etc. achieved in a game or by a team or an individual. 따라서 points라는 복수형 명사를 사용하지 말고 score를 사용하는 것이 더 좋다. DB column을 생각해 보면 더 그렇다. DB column은 단수 명사로 이루어져 있어야 한다.

 

 - inform vs notify : To inform someone is simply to tell something to that person. The "tell" can be in speech or in writing. Notify is to inform (above) but in an essentially official or formal manner (which basically means in writing in most cases).

 

[ method 이름 짓는 법 ]

 - CRUD 그대로 써서 짓지 말라는 글 보고 찾아보니 이런 예제 발견. 앞으로 많은 도움이 될 듯. 1번 Reference에서 긁어왔다.

 - 이건 이제 사용되는 단어 참고 용도로만 사용하면 될 것 같다.

 

 - 메소드(Method) 명명 규칙

메소드명에는 파스칼 표기법을 사용한다.
Ex) public void SendMessage(String message) {}

속성에 접근하는 메소드명의 접두사는 'get','set'을 사용한다.
Ex) public void setDisplayName
Ex) public void getDisplayName

데이터를 조회하는 메소드명의 접두사는 find를 사용한다.
Ex) public void findData(String data){}

데이터를 입력하는 메소드명의 접두사는 input을 사용한다.
Ex) public void inputData(HashMap data){}

데이터를 변경하는 메소드명의 접두사는 modify를 사용한다.
Ex) public void modifyData(HashMap data){}

데이터를 삭제하는 메소드명의 접두사는 delete를 사용한다.
Ex) public void deleteData(String data){}

데이터를 초기화 하는 메소드명의 접두사는 initialize을 사용한다.
Ex) public void initData(String data){}

반환값의 타입이 boolean인 메소드는 접두사로 is를 사용한다.
Ex) public void isData(String Data){}

데이터를 불러오는 메소드명의 접두사는 load를 사용한다.
Ex) public void loadData(){}

데이터가 있는지 확인하는 메소드명의 접두사는 has를 사용한다.
Ex) public void hasData(){}

보다 지능적인 set이 요구될때 사용하는 메소드명의 접두사는 register를 사용한다.
Ex) public void registerAccount(){}

새로운 객체를 만든뒤 해당 객체를 리턴해주는 메소드명의 접두사는 create를 사용한다.
Ex) public void createAccount(){}

해당 객체를 다른 형태의 객체로 변환해주는 메소드명의 접두사는 to를 사용한다.
Ex) public void toString(){}

해당 객체가 복수인지 단일인지 구분하는 메서드명의 접미사는 s를 사용한다.
Ex) public void getMembers(){}

B를 기준으로 A를 하겠다는 메소드명의 전치사는 By를 사용한다.
Ex) public void getUserByName(String name){}

반환값의 타입이 boolean인 메소드는 접두사로 is를 사용한다.
Ex) public void isData(String Data){}

데이터를 불러오는 메소드명의 접두사는 load를 사용한다.
Ex) public void loadData(){}

 

 

 * Reference

1. m.blog.naver.com/reona7140/221306141987

2. tyboss.tistory.com/entry/Java-%EC%9E%90%EB%B0%94-%EB%84%A4%EC%9D%B4%EB%B0%8D-%EA%B4%80%EC%8A%B5-java-naming-convention

3. devlsh.tistory.com/entry/Java-Naming-Convention

4. viiiin.tistory.com/49 

5. fluxens.com/javastyle.html

7. docs.microsoft.com/en-us/previous-versions/dotnet/netframework-1.1/xzf533w0(v=vs.71)?redirectedfrom=MSDN

 

'(구)게시판 프로젝트' 카테고리의 다른 글

권한 관련 작업  (0) 2021.05.05
(멀티)게시판  (0) 2021.05.04
메인 화면  (0) 2021.04.27
회원가입  (0) 2021.04.26
로그인  (0) 2021.04.16
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함