웹개발자공부/etc

Id? ID? id? 어떻게 쓰는 것이 좋을까?(camelCase)

박더그 2023. 2. 9. 02:46

소스코드를 작성하다보면,

변수명을 어떻게 표기할 지 난해할 때가 종종 있습니다.

 

이름 자체를 잘 짓기도도 어렵지만,

naming convention(camelCase)을 지키려다보니 생기는 상황입니다.

 

id가 대표적인 케이스인 것 같습니다.

userId인지? userid인지? userID인지? 와 같이 말입니다.

 

그래서 구글링을 해봤더니,

선배 개발자들도 이미 같은 고민을 했던 것 같습니다.

 

몇 가지 포스트의 내용을 종합한 결과,

저는 아래와 같은 우선순위로 id를 표기하려 합니다.

 

1. 누군가 작성해둔 코드가 있다면 일관을 유지하기 위해 그것대로 사용할 것

2. Id로 사용 할 것(Javascript의 getElementById()를 참고)

3. 명확히 해야 할 경우에는 identifier 또는 identification을 그대로 사용할 것

 

제가 참고한 포스트 중, 

세 가지 포스트를 추려 공유합니다.

 

https://stackoverflow.com/questions/779929/id-id-or-id

 

ID, id, or Id?

I use camelCase in my code and database field names, etc, but with fields that have Id at the end, it always ends up being hard to read. For example, itemId, teacherId, unitId, etc. In these cases I

stackoverflow.com

https://softwareengineering.stackexchange.com/questions/186277/should-the-variable-be-named-id-or-id

 

Should the variable be named Id or ID?

This is a bit pedantic, but I've seen some people use Id as in: private int userId; public int getUserId(); and others use: private int userID; public int getUserID(); Is one of these a better ...

softwareengineering.stackexchange.com

https://briancaos.wordpress.com/2019/09/05/id-or-id-naming-conventions-in-code/

 

ID or Id? Naming conventions in code

This topic is not as toxic than the tabs-vs-spaces or 2 vs 4 indents discussion, but it’s still something every coder I have met have an opinion about, no matter the programming language: Whi…

briancaos.wordpress.com