I am always a dedicated fan of writing naturally readable code – by “naturally readable” I mean, one can read a line of code as if it were a sentence of English (or maybe other human languages). It’s believed that the practice encourages more self-explainable code, as the code reads more like a human-composed article, instead of some gibberish only recognizable by machine.
The practice recommends to name functions or variables following the word order of human language, for English that is, subjects come after verbs, and adjectives go before nouns that being modified. The samples below showcase how it guides naming in a program (please hold your opinions about the casing)
append_to_list(lst, item)
. A function that appends an item to a list, which can read as “append to the list (specified by namelst
) with the item”.register_service_notifier(func)
. A function that registers another function as a service notifier, which can read as “register a service notifier with the functionfunc
“.UserFollowersListView
. The name of a web component which is a list view to display followers for a user.
It plays well and improves my developing experience most of the time, but there is no silver bullet, just like other practices or guidelines.Sometimes I found the readability even degrades. I kept skimming the lines and just couldn’t locate an item efficiently.