6

I understand the general Erlang conventions for functions are using snake case or camel case, but what about exported functions?

For example, say I have a gen_server module that defines a check to see if a username is in use:

  • I have a call along the lines of handle_function(is_username_in_use, UserName).

  • I also have an exported function named is_username_in_use that calls gen_server:call/2.

But internally I also define a method that checks a database. So I end up with something along the lines of check_if_username_is_in_use_in_db for internal use.

It quickly gets out of hand, and I end up with uncomfortably long names. Is there a common convention used to name functions like these? I was thinking something along the lines of is_username_in_use_internal

1

From official Erlang Programming Rules:

Function names:

  • The function name must agree exactly with what the function does. It should return the kind of arguments implied by the function name. It should not surprise the reader. Use conventional names for conventional functions (start, stop, init, main_loop).

  • Functions in different modules that solves the same problem should have the same name. Example: Module:module_info().

  • Some kind of naming convention is very useful when writing lots of different functions. For example, the name prefix "is_" could be used to signify that the function in question returns the atom true or false.

Also this project helps you programmatically to be compatible by those rules.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.