Συμβουλές για Καλύτερο Κώδικα

Posted by Χρίστος Ευαγγέλου Fri, 26 Nov 2004 12:09:40 EET

Μερικές δαιμονικές συμβουλές για να γράφετε "καλύτερο" κώδικα:

http://mindprod.com/unmain.html

Να μερικά που μου αρέσαν:

CapiTaliSaTion

Randomly capitalize the first letter of a syllable in the middle of a word. For example: ComputeRasterHistoGram().

Bedazzling Names

Choose variable names with irrelevant emotional connotation. e.g.:

      marypoppins = ( superman + starship ) / god;

This confuses the reader because they have difficulty disassociating the emotional connotations of the words from the logic they're trying to think about.

When To Use i

Never use i for the innermost loop variable. Use anything but. Use i liberally for any other purpose especially for non-int variables. Similarly use n as a loop index.

Misleading names

Make sure that every method does a little bit more (or less) than its name suggests. As a simple example, a method named isValid(x) should as a side effect convert x to binary and store the result in a database.

Use Plural Forms From Other Languages

A VMS script kept track of the "statii" returned from various "Vaxen". Esperanto, Klingon and Hobbitese qualify as languages for these purposes. For pseudo-Esperanto pluraloj, add oj. You will be doing your part toward world peace.

Obscure film references

Use constant names like LancelotsFavouriteColour instead of blue and assign it hex value of 0x0204FB. The color looks identical to pure blue on the screen, and a maintenance programmer would have to work out 0204FB (or use some graphic tool) to know what it looks like. Only someone intimately familiar with Monty Python and the Holy Grail would know that Lancelot's favorite color was blue. If a maintenance programmer can't quote entire Monty Python movies from memory, he or she has no business being a programmer.

Thesaurus Surrogatisation

To break the boredom, use a thesaurus to look up as much alternate vocabulary as possible to refer to the same action, e.g. display, show, present. Vaguely hint there is some subtle difference, where none exists.

However, if there are two similar functions that have a crucial difference, always use the same word in describing both functions (e.g. print to mean "write to a file", "put ink on paper" and "display on the screen"). Under no circumstances, succumb to demands to write a glossary with the special purpose project vocabulary unambiguously defined. Doing so would be an unprofessional breach of the structured design principle of information hiding.

no comments