On naming collections:
Naming collections: Plural names for arrays, lists, etc; single names for dictionaries, hash maps, etc. From Perl Best Practices:
- Because hash entries are typically accessed individually, it makes sense for the hash itself to be named in the singular. That convention causes the individual accesses to read more naturally in the code. … On the other hand, array values are more often processed collectively … So it makes sense to name them in the plural, after the group of items they store. … If, however, an array is to be used as a random-access look-up table, name it in the singular, using the same conventions as a hash.
Naming convetions for key-value maps: For dictionaries, name things {{ValueType}}s_by_{{KeyType}}s, e.g. counts_by_words, sizes_by_filenames. Use plural for describing keys or values (e.g. "counts").
On naming functions/methods:
Functions, by definition, de-duplicate code into one reusable place. There will be more call sites than the singular definition, so names should reflect how *callers* use the function, and maximize readability in the caller's context. See also: Functions your brain loves: functions should replace logic with cognitive blocks/single ideas. E.g.
notify_all(registered_clients, about=the_new_version)