Skip to content

ZeroSuperfluousNames

John Q Durden edited this page Jan 18, 2016 · 3 revisions

ZeroSuperfluousNames means to put duplicate code with equivalent functionality into a named function of its own.

You don't write factorial_10() that returns the value of the tenth factorial and factorial_20() that returns the twentieth. No, you see that you can utilize the duplicate code and simplify by writing factorial(n) for any value n.

But there's another interpretation of this directive: proper use of symbols (@#!&|}) vs. names. Visually, in your code a symbol is distinct, so your language should maximize this feature so that identifiers are completely distinguishable from your operators. Make common and meta operations into succinct symbols. Instead of addToSet and '+', use the symbol. Consider this rule for I/O operators, cloning objects, and querying the state of objects.

Math does this perfectly -- there's no confusion to what is a number and what is a symbol, even though they are both drawn in the same color on the page. Your mind lexes this "code" better and easier by the definition and utilization of these symbols.

As another example, Python uses the word "self" for referencing the object within class methods, yet there's nothing to distinguish this very special usage from any other identifier. A symbol like &, or @, would better, or even nothing but an empty dot operator plus the method name.

Clone this wiki locally