Meaningful concise method naming guidelines

naming

Recently I started releasing an open source project, while I was the only user of the library I did not care about the names, but know I want to assign clever names to each methods to make it easier to learn, but I also need to use concise names so they are easy to write as well.

I was thinking about some guidelines about the naming, I am aware of lots of guidelines that only care about letters casing or some simple notes. Here, I am looking after guidelines for meaningful but yet concise naming.

For example, this could be part of the guidelines I am looking after:

  • Use Add when an existing item is going to be added to a target, Use
    Create when a new item is being created and added to a target.
  • Use Remove when an existing item is going to be removed from a target,
    Use delete when an item is going to be removed permanently.
  • Pair AddXXX methods with RemoveXXX and Pair CreateXXX methods with
    DeleteXXX methods, but do not mix them.

As the above samples show,I would like to find some online material helping me with naming methods and other item complying with English grammar and word meanings.

The above guidance may be intuitive for native English speakers, but for me that English is my second language I need to be told about things like this.

Best Answer

Naming. One of the hardest things about software development :)

When I name something, here is my set of priorities:

  • Follow the idioms of the language. Ruby likes underscores. JavaScript likes camel case. Whatever language you're in is the convention to follow.
  • Reveal the intent of the API. It's not "send_http_data" it's "post_twitter_status".
  • Avoid leaking implementation details. Say, prefixing a variable with a type.
  • Do not use more characters than necessary without breaking the previous guidelines.

Obviously this is a rather simplistic approach. Naming is nuanced.

For further research, I would recommend reading The Art of Readable Code, as it provides some excellent, succinct advise on method naming. For even more research I cannot more highly recommend Bob Martin's Clean Code.