Naming convention for traits


#1

I think the names being used for traits in Rust fail basic English.

Here is how the word trait is defined in English :- trait treɪt,treɪ/ noun: trait; plural noun: traits a distinguishing quality or characteristic, typically one belonging to a person.

A quality or characteristic is what an adjective is. Hence I propose that only adjectives (or Nouns in a pinch) should be used as trait names.

If this proposal gathers some support I will start a new thread with suggestions for renaming existing traits which do not fit this proposal.

Failing basic English is not an option for any professional body of work.

Some examples of traits which are not adjectives…

  1. Iterator (noun)
  2. Borrow (usually a verb, sometimes can be used as a noun)
  3. Extend (verb, cannot be a noun or adjective) this is a proposed trait.

#2

There were some suggestions for Iterable, but that was suggested to be a trait with a function iter() that returns a type that implements Iterator.


#3

[quote=“SDX2000, post:1, topic:1796”] A quality or characteristic is what an adjective is. Hence I propose that only adjectives (or Nouns in a pinch) should be used as trait names. [/quote]You’re begging the question. In Rust a trait is not an adjective, it’s what Rust conventions say it is.

Appeal to the dictionary is at best a very weak motivation for renaming half of the standard library prior to release and stuffing the ‘-able’ suffix onto everything.


#4

No it is not. Use a different word if you mean something else altogether. What is the point of using any English language word if we go by this line of thought? Why not make up new words instead? Are you saying the + operator need not mean add in Rust? It can actually be used for division if the Rust convention says so?


#5

A programming language is a formal language rather than any natural language, and jargon whenever it matches natural language. As it is read and written by humans, whose first (and often second and third) language is a natural one, it should use natural language words when it aids understanding by those feeble humans, and conversely it should not use natural language words when it misleads humans.

But it does not need to slavishly adhere to Strunk & White or even English grammar. The program as a whole is not an English text. Any keyword taking after an English word is only taking after it, i.e., it indicates a formal-language-thingy that is intuitively close enough to a natural-language-thingy that using the same word is a useful mnemonic.

“Trait” captures the intuition about what a trait is. “Iterator” captures the intuition about what it means to have a next method. That the two clash grammatically when transported back into natural language land is a bit unfortunate, but completely irrelevant. In fact, it may even be useful, since it distinguishes the jargon from normal English. Furthermore, the concise names (no ubiquitous -able suffix) have their own readability advantages.

Finally, the English texts outside of the program proper (i.e. the technical writing and speech of Rustaceans) has no trouble being grammatically correct. When referring to the trait itself, the name is a proper name and thus above all criticism. When reading a bound like T: Iterator or T: Extend, we can unpack the trait name (T is an iterator, T can be extended) or we can be clinical and say “T implements Extend”.


#6

I am ok with this. I did say we can use nouns as trait names (in a pinch). But borrow and extend are asking for too much. A trait is sometimes compared to an interface in other languages (java, C#). Interfaces can have an is-a relationship with the classes implementing them. A noun can be used in this case but only if an is-a relationship makes sense.

I am conflicted about the name iterator. Iterator is someone/something which iterates it cannot be conflated with something which is iterable. See C#: IEnumerable, IEnumerator

Furthermore, the concise names (no ubiquitous -able suffix) have their own readability advantages.

I will always choose correctness over speed (of doing anything). Readability is a moot point if what you are reading is incorrect. You must understand not everybody will have the same level of commitment to Rust while coming in. Spelling and grammar look like minor issues only to amateurs.


#7

[quote=“SDX2000, post:6, topic:1796”] I am ok with this. [/quote]Wait, so is trait an adjective or are you stepping onto a slippery slope?

[quote=“SDX2000, post:6, topic:1796”] I did say we can use nouns as trait names [/quote]Is this the royal “we”?

[quote=“SDX2000, post:6, topic:1796”] Spelling and grammar look like minor issues only to amateurs. [/quote]Good, learn the grammar of this language then and stop confusing it with English.


#8

It is unfortunate that you do not see any merit in borrowing from a language millions of people are already familiar with and instead insist on cooking up new meaning for well known words. I do not see any merit in your argument. You are being different only for the sake of being different.


#9

@SDX2000, I think the “using verbs as trait names” convention persists because two reasons:

  1. Rust’s traits are based on Haskell type classes, and Haskell’s core type classes like Show, Read are not adjectives. Rust inherited them. (Show is now Debug, though.)
  2. The syntax impl Trait for Type flows naturally when Trait is a verb.

Also, I think your proposed changes are actually fine, but the status quo is also fine, and it is already too late to do such large scale breaking changes.


#10

OK, this makes sense. Thanks for the clarification.