Reputation: 159
I can't find even couple of words about containing numbers in names of variables or on methods. Does anyone have any authoritative information about such cases:
Upvotes: 0
Views: 508
Reputation: 11377
I haven't found any information either but below are my own thoughts.
Using a digit in an identifier which happens 2 be pronounced in the same way as a word is just silly word play. It also makes the meaning of the identifier ambiguous - does char2old mean that a character is too old, is it an old version of char2 or is it a conversion? It's fun however to come up with names like a10sorFlow, the2lbox, my4mula but they are best avoided.
When it comes to using numbers 1 to N at the end of equally named identifiers, it is probably better to use an array instead if N > 2. Also, when N = 2 there are often clearer names that can be used, like leftCircle and rightCircle instead of circle1 and circle2, or currentChar and nextChar instead of char1 and char2.
Here is a good general guide for naming variables:
Identifier kind | Word class | Example |
---|---|---|
Boolean variable or pure function | Last word is an adjective | doorClosed, TablePrepared |
Non-boolean variable or pure function | Last word is a noun | closedDoor, PreparedTable |
Non-pure function (has side-effects) | First word is a verb | CloseDoor, PrepareTable |
Upvotes: 1