When to use "get_" in function name?

So far, I’ve been following a personal convention: use get_foo() for anything that does work (3rd party API, database or disk read, etc), and foo() for anything held in memory.

Are there community standards around this? For example, if I have a Genserver Foo with some foos in state, do you prefer Foo.get_foo() or Foo.foo() for the external API?

1 Like

Most of the time a get_ function is paired with a put_ function and possibly an update_ function. If there’s only a get_ function, I think it’s fine to omit the prefix and have it “bare”.

1 Like

I always try to give name to functions that really reflects what they do, and depending on what the function really does, sometimes get_ is not right.

For the examples you gave, like getting a value from a database, getting a value from inside a given map, or even from a process state (which you said you don’t use get_) I would prefix with get_, because that’s what the function is doing: getting something from somewhere to the caller.

When not to prefix with get_? Well, when you’re not getting something. An example: when you’re transforming a map/list in another map/list, which is very common.

1 Like