User:Average/ZeroSuperfluousNames

From HackerspaceWiki
Jump to: navigation, search

Zero Superfluous Names means combining duplicate code into a single function. Taking many specialized functions that do mostly the same thing and generalizing it, making it even more useful.

You have a function factorial_1() that returns the value of the first factorial. You have another one, called factorial_2() that returns the second. And a third, factorial_7(). ZeroSuperfluousNames means to put that mostly duplicate code into a single function: factorial(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, like I/O operators, clone-object, and query-state.

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. The numbers are the "nouns" and the operator symbols, the "verbs".

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 be better, or even nothing at all, but an empty dot operator plus the method name.