Let an unfamiliar reader think well over similarly named function printMessage: “Where does it put the message? To a printer or on the screen?”. And the function printText(text) will put the text on-screen.
#I ninja codes code
Note how much more interesting and diverse the code became.įor two functions with important differences – use the same prefix!įor instance, the function printPage(page) will use a printer. in his code, then Peter could use render., and Ann – paint. Make a pact with fellow ninjas of the team: if John starts “showing” functions with display. Insinuate that there’s a subtle difference between such functions, while there is none. And then if another function shows on the screen something else, like a user name, start it with show… (like showName). If a function shows a message on the screen – start it with display…, like displayMessage. Using similar names for same things makes life more interesting and shows your creativity to the public.įor instance, consider function prefixes. The name that can be named is not the eternal name. The Tao that can be told is not the eternal Tao.
And when there’s a typo… Ummm… We’re stuck for long, time to drink tea. One of the ways – use similar variable names, like date and data.Ī quick read of such code becomes impossible. Only a truly attentive programmer should be able to understand your code. …But what if there are no more such names? Just add a number: data1, item2, elem5… There’s just no way to figure out without a good meditation! But what’s the meaning of the variable? Which string/number does it store? The value type is easy to find out by debugging. But when an outsider tries to understand the code, they’ll be surprised to see that there’s actually no information at all! And will ultimately fail to alter your well-thought code. It says what’s inside the variable: a string, a number or something else. Sure, the variable name still means something. A young initiate may wonder – are such names really useful for a ninja? Indeed, they are! After all, a variable eventually gets a value.
…But what to do if data is already taken? Try value, it’s also universal. Indeed, every variable holds data, right? Like obj, data, value, item, elem and so on. While choosing a name try to use the most abstract word. Only a worthy person should be able to uphold the development of your code. Only the one with truly good intuition will be able to understand such names. If the team rules forbid the use of one-letter and vague names – shorten them, make abbreviations. Then if someone looks deep inside the loop, they won’t be able to quickly figure out that the variable named x is the loop counter. For instance, x or y.Īn exotic variable as a loop counter is especially cool if the loop body takes 1-2 pages (make it longer if you can). Look around, there are many more exotic letters. A real ninja will never use i as the counter in a "for" loop. And even if someone does, they won’t be able to “decipher” what the name a or b means. No one will be able to find it using “search” of the editor. Like a, b or c.Ī short variable disappears in the code like a real ninja in the forest. Only the Dao is well begun and wellĪnother way to code shorter is to use single-letter variable names everywhere.