Coding/Naming convention


#1

Do we have a coding convention/guideline for rust programs? Getting names right is hard but in my opinion it is of utmost importance. The concept of abstraction depends on using a good name as a mnemonic/handle to a larger concept. Also mistakes in choosing good names are hard to rectify down the line.

I propose the following rules to begin with the process of creating such a document (assuming it does not exist)…

  1. Struct names should be nouns.
  2. Trait names should be adjectives.
  3. Method names should be verbs.

#2

I’m not sure if there are any guidelines on that currently.

I know that in the new io module though, all of the structs seem to have been named nouns, the traits have been named verbs, and the methods have been named verbs or plural nouns.

For example:

  • Write, the trait for something to write to - similarly BufWrite, the trait for something that writes in a buffered way
  • BufWriter, an implementation of BufWrite.
  • Write::write, a method to write something to the Write.
  • or in a different method name case, Read::chars, a method to produce a character iterator from a Read.

But, in another case, structs have also been called verbs. The ones in the io trait using this convention are all iterators, which take the name directly from the methods which produce them.

For example:

  • Using io::repeat(u8) will produce a Repeat struct
  • Using BufReader::split(self, u8) will produce a Split struct

Besides those trends, I don’t know of any specific guidelines. I think the general consensus is just to go with something which will give the user an idea of what the function will do, and not to have it in any specific part of speech.


#3

This WIP guide is probably what you’re looking for. Certain things do have naming conventions but it depends. I don’t know of anything dictating verbs vs nouns and such.

[EDITED] Apparently the original guide was moved to here.