I have a question for naming. fetchXXX VS getXXX V...
# codereview
c
I have a question for naming. fetchXXX VS getXXX VS retrieveXXX, when you get from API or Local DB. what do you use or when do you use them? any differences?
p
getX
when there is direct access to the resource in the same thread, and getX returns immediately.
retrieve/fetch/resolve
when the function returns a result but the result is not returned immediately in the thread. Either because of suspend, or asynch coroutine.
request
when the function doesn't return a result, and uses some callback mechanism to do so later on.
a
the Spring JPA repository naming conventions will have a strong influence on a lot of Spring based projects, as well as developers who used JPA repos (even if they don’t any more) https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#appendix.query.method.subject I half-remember that a method named
findXXX()
would return a nullable response, while
getXXX()
would return non-null, but throw an exception if it didn’t exist. It was nice having a standardised method naming structure.
c
getXXX
suggests to me the operation would be cheap.
request|fetchXXX
makes me think that a network request would be involved.
query|retrieveXXX
makes me think db or file based operation. No huge reason other than years of reinforcement.
s
@Pablichjenkov your statement looks solid 👍 Any other refs that support it?
p
Not that I am aware of. In my case it is just the day to day. Perhaps someone has written about it but I don't know.
👍 1