Function Name Convention - General or Specific names?

First I would say choose a style you like and stick with it. Quite frankly I love snake case for function names, so that is what I use. You might like something else, whatever, use it!

One of the things that annoyed me about GO is they defined how the GO code should look and the tools kept bitching at me. To make matters worse the atom plugin kept re-enabling code formatting so I’d save a file and it would “pretty” it up for me and ignore how I wanted it to look, very annoying. I will say having a common coding style when multiple people are working on the same code does make sense. However in this situation I prefer to put people on different modules define the APIs between those modules and then let people own their code.

As for naming, I would recommend going for the shortest name that still describes what the function is doing. I think creating a generate() function sounds fine. As for the ! suffix on functions, I’ve found that wonky. Why write doesn’t have the suffix but push does, I’ll never know. Both functions are “adding” something to the underlying “object”. So I’d say use it or don’t use it, just be consistent on when you use it.

Really all your naming conventions are to help you read the code (and possibly other people). Try to ensure that if you walk away from the code for a year when you come back, your code will still make sense. For me that really means adding comments at the top of each function that document what the function does, what it expects for input, what it returns, and what state it changes. Julia really helps with this and their triple quote comments for method, I would highly recommend using that feature.

3 Likes