find vs. get

This week, I spoke with Dave Liddament to record an upcoming episode of the Beyond Blocks podcast.

In that conversion, we started to talk about conventions, specifically unwritten conventions used within projects.

Dave mentioned on some of his projects, they have a convention for when to use get or find method prefix names.

For example, in a UserRepository class, a method like findUserByEmail() implies that a matching user may not be found.

Alternatively, getUserByEmail() implies that you're getting a user and will always be one found and returned.

This interested me and I found a blog post by Thomas Uhrig on find vs. get, which I've read since the recording.

In the context of the episode, we discussed how conventions like this can be codified and written down and checkable with static analysis tools, but it got me thinking about conventions I've consciously or unconsciously followed, as well as the impact of changing a small word in a method name on its behaviour.

What about you?

Do you have similar conventions that you follow in your applications?

- Oliver

Was this interesting?

Sign up here and get more like this delivered straight to your inbox every day.

About me

Picture of Oliver

I'm an Acquia-certified Drupal Triple Expert with 17 years of experience, an open-source software maintainer and Drupal core contributor, public speaker, live streamer, and host of the Beyond Blocks podcast.