Skip to content

NamesAreOnlyMnemonic

Ben Christel edited this page Aug 8, 2021 · 2 revisions

One of my former coworkers loved to tell the story of how he ran across this code:

// Always returns true
function() {
  return false
}

Usually, this anecdote was followed by a reminder that Comments aren't to be trusted and we should instead use descriptive Identifier names.

However, names are just as fallible as comments. Neither the compiler nor the tests will necessarily complain about this code:

function alwaysTrue() {
  return false
}

Names are merely mnemonic: they can remind us what a thing is for, but if they're coupled to specifics they can go out of date just as well as comments can. The solution is to create Abstractions:

function always(v) {
  return function() { return v }
}
Clone this wiki locally