Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

복수형 data fetching을 위한 함수명은 어떻게 작성해야할까#488

gorjs3540 started this conversation inA vs B
Discussion options

배열의 값을 받아오는 data fetching을 위한 함수를 구현하다 고민이 하나 생겼습니다. 예를 들면,
저는 보통getGames와 같은 형식으로{http method}+{목적 단위}+{정렬이나 필터}로 정의해서 사용하고 있었는데요, 다른 코드를 보았을 땐getGameList와 같은 형식으로도 사용하더라구요. 또, BE쪽에서는findAll 같은 형식을 사용한다고도 들어서 어떤 방식이 직관적인지, 의미적으로 알맞은지 궁금하기도 합니다. 다들 어떻게 사용하시나요?

// service, frontend API 호출 시exportconstgetGames=()=>{ ...};// UI, state, hook으로 작성 시 -> UI의 의미를 포함exportconstuseGameList=()=>{ ...};// DB, resource 직접 접근 시exportconstfindAllGames=()=>{ ...};

제 나름대로 구분을 지어보긴 했는데 일관성이 없다는 생각도 조금 들고 고민이 되네요.

여러 함수명 중 어떤걸 사용하시나요?
"단위" + s 형식으로 작성한다.
76%
"단위" + List 형식으로 작성한다.
23%
"findAll"과 같은 형식으로 작성한다.
0%

13 votes

You must be logged in to vote

Replies: 2 comments 1 reply

Comment options

과거에는 ~~list보다는 ~~s를 선호했어요. 다수가 사용하는 컨벤션을 사용한다면 장점이 많기 때문에 코드리뷰에서 변경을 요청받은 경우도 있었습니다.
반면에 s보다는 list가 더 직관적이라는 이유로 list를 사용한경우도 있어요.

findAll같은건 주로 ORM에서 많이 사용했던 것 같아요.

결국 팀 컨벤션에 맞춰 일관성 있게 사용하는 게 가장 중요한 것 같아요. 어떤 방식이든 팀 전체가 동일하게 사용한다면 문제없을 듯 합니다~

You must be logged in to vote
0 replies
Comment options

팀원들과 자주하는 고민 같습니다. 저는'단위' + s 파 입니다.

이런 경우의 함수 이름은 되도록 데이터 및 타입와 연관 지으려고 노력하는 편인데요.
~List와 ~s는 아래의 차이가 아닐까 생각해봅니다.

interfaceGame{// ...}// case 1. Game의 배열을 그냥 Game[] 자체로 사용하는 경우constgetGames=(options?:unknown)=>{// ..constfetchedGames:Game[]=response.data;returnfetchedGames}// case 2. Game의 배열을 별도의 타입(~List)로 관리하는 경우interfaceList<D>{data:D;pagination:{currentPage:number;totalPages:number;nextPage:number;previousPage:number;}}typeGameList=List<Game>;constgetGameList=(options?:unknown)=>{// ...returnresponse.data;}

위 처럼, 모델로 관리하는Game에 대해서 그냥 배열 자체로 관리한다면Games가,Game이 모여있는 것을List라고 별도 관리하고 있다면GameList가 좋지않을까? 라고 생각해봅니다.

You must be logged in to vote
1 reply
@YOOGOMJA
Comment options

굳이 pagination이 포함된 List 같은게 아니고,Game[]type GameList = Game[]이라고 재정의해서 사용하는 경우라도 같을 것이라 생각합니다.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
A vs B
Labels
None yet
3 participants
@gorjs3540@YOOGOMJA@yoonminsang

[8]ページ先頭

©2009-2025 Movatter.jp