image provider

Naming


When I use a word, Humpty Dumpty said, in a rather scornful tone, It means just what I choose it to mean — neither more nor less.
~ Lewis Carroll (1832-01-27 1898-01-14 age:65) — Through the Looking Glass, Chapter 6

Much of the skill in writing unmaintainable code is the art of naming variables and methods. They don’t matter at all to the compiler. That gives you huge latitude to use them to befuddle the maintenance programmer.

  1. New Uses For Names For Baby

    :
    book cover recommend book⇒20,001 Names For Babyto book home
    by Carol McD. Wallace 978-0-380-78047-1 paperback
    publisher Harper
    published 1995-05-01
    Australian flag abe books anz abe books.ca Canadian flag
    German flag abe books.de amazon.ca Canadian flag
    German flag amazon.de Chapters Indigo Canadian flag
    Spanish flag amazon.es Chapters Indigo eBooks Canadian flag
    Spanish flag iberlibro.com abe books.com American flag
    French flag abe books.fr amazon.com American flag
    French flag amazon.fr Barnes & Noble American flag
    Italian flag abe books.it Nook at Barnes & Noble American flag
    Italian flag amazon.it Kobo American flag
    India flag junglee.com Google play American flag
    UK flag abe books.co.uk O’Reilly Safari American flag
    UK flag amazon.co.uk Powells American flag
    UN flag other stores
    Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder.
    Buy a copy of a baby naming book and you’ll never be at a loss for variable names. Fred is a wonderful name and easy to type. If you’re looking for easy-to-type variable names, try adsf or aoeu if you type with a DSK keyboard.
  2. Single Letter Variable Names

    : If you call your variables a, b, c, then it will be impossible to search for instances of them using a simple text editor. Further, nobody will be able to guess what they are for. If anyone even hints at breaking the tradition honoured since FØRTRAN of using i, j and k for indexing variables, namely replacing them with ii, jj and kk, warn them about what the Spanish Inquisition did to heretics.
  3. Creative Miss-spelling

    : If you must use descriptive variable and function names, misspell them. By misspelling in some function and variable names and spelling it correctly in others (such as SetPintleOpening SetPintalClosing) we effectively negate the use of grep or IDE (Integrated Development Environment) search techniques. It works amazingly well. Add an international flavor by spelling tory or tori in different theatres/theaters.
  4. Be Abstract

    : In naming functions and variables, make heavy use of abstract words like it, everything, data, handle, stuff, do, routine, perform and the digits e.g. routineX48, PerformDataFunction, DoIt, HandleStuff and do_args_method.
  5. A.C.R.O.N.Y.M.S.

    Use acronyms to keep the code terse. Real men never define acronyms; they understand them genetically. If you confuse even yourself with acronymns, secretly write code using meaningful names, then, when the code in working, use the global rename feature of Eclipse to give your variables and methods unintelligible names and acronyms, just the way a mechanical obfuscator would.
  6. 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).
  7. Eschew the Project Glossary

    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. If you are forced to write such a vocabulary, use recursive definitions such as this one taken from the Ant 1.6.5 manual: basedir : the absolute path of the project’s basedir (as set with the basedir attribute of <project>). The reader still has no idea what the basedir is, though he has been given the clue it is absolute even though all examples show it with . (which, incidentally, is relative).

    Wear your adversary down by tantalising, pretending to give information where there is really none. Disguise your vacuous statements sufficiently so the reader will blame himself for failing to understand.

    The reader asks himself, if I am trying to compile the com.mindprod.holidays package, is basedir C:\, C:\com\, J:\com\mindprod\ or J:\com\mindprod\holidays\ ? You see why you should never use concrete examples? They are too clear. If you are forced to use them, complain that they sound childish and unprofessional. Complain that examples make it look as if that is all the product can do. You want people to appreciate fully every possible variation from the get go. You are not trying to inform, but impress! After all, no academic would be caught dead giving an example. People only respect that which is too abstract to grasp easily.

    That’s a lot to remember. You will do just fine if all you do when writing documentation is maintain the attitude that people who don’t already know this jargon are stupid fools who don’t deserve to understand.

  8. Use Plural Forms From Other Languages

    A VAX/VMS (Virtual Address Extension/Virtual Memory System) script kept track of the statii returned from various Vaxen. Esperanto, Klingon qualifies as languages for these purposes. For pseudo-Esperanto pluraloj, add oj. You will be doing your part toward world peace.
  9. CapiTaliSaTion

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

    Wherever the rules of the language permit, give classes, constructors, methods, member variables, parameters and local variables the same names. For extra points, reuse local variable names inside {} blocks. The goal is to force the maintenance programmer to carefully examine the scope of every instance. In particular, in Java, make ordinary methods masquerade as constructors.
  11. Åccented Letters

    Use accented characters on variable names, e. g.
    typedef struct { int i; } ínt;
    where the second ínt’s í is actually i-acute. With only a simple text editor, it’s nearly impossible to distinguish the slant of the accent mark.
  12. Exploit Compiler Name Length Limits

    If the compiler will only distinguish the first, say, 8 characters of names, then vary the endings e.g. var_unit_update() in one case and var_unit_setup() in another. The compiler will treat both as var_unit.
  13. Underscore, a Friend Indeed

    Use _ and __ as identifiers.
  14. Mix Languages

    Randomly intersperse two languages (human or computer). If your boss insists you use his language, tell him you can organise your thoughts better in your own language, or, if that does not work, allege linguistic discrimination and threaten to sue your employers for a vast sum.
  15. Extended ASCII (American Standard Code for Information Interchange)

    Extended ASCII characters are perfectly valid as variable names, including ß, Ð and ñ characters. They are almost impossible to type without copying/pasting in a simple text editor.
  16. Names From Other Languages

    Use foreign language dictionaries as a source for variable names. For example, use the German punkt for point. Maintenance coders, without your firm grasp of German, will enjoy the multicultural experience of deciphering the meaning.
  17. Names From Mathematics

    Choose variable names that masquerade as mathematical operators, e.g.:
    openParen = ( slash + asterix ) / equals;
  18. 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.
  19. Rename and Reuse

    This trick works especially well in Ada, a language immune to many of the standard obfuscation techniques. The people who originally named all the objects and packages you use were morons. Rather than try to convince them to change, just use renames and subtypes to rename everything to names of your own devising. Make sure to leave a few references to the old names in, as a trap for the unwary.
  20. 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.
  21. Conventions Schmentions


    Ignore Oracle’s coding conventions, after all, Sun does. Fortunately, the compiler won’t tattle when you violate them. The goal is to come up with names that differ subtlely only in case. If you are forced to use the capitalisation conventions, you can still subvert wherever the choice is ambigous, e.g. use both inputFilename and inputfileName. Invent your own hopelessly complex naming conventions, then berate everyone else for not following them.
  22. Lower Case l Looks a Lot Like the Digit 1

    Use lower case l to indicate long constants, e. g. 10l is more likely to be mistaken for 101 that 10L is. Ban any fonts that clearly disambiguate uvw wW gq9 2z 5s il17|!j oO08 `'" ;:,. m nn rn {[()]}. Be creative.
  23. Reuse of Global Names as Private

    Declare a global array in module A and a private one of the same name in the header file for module B, so that it appears that it’s the global array you are using in module B, but it isn’t. Make no reference in the comments to this duplication.
  24. Recycling Revisited

    Use scoping as confusingly as possible by recycling variable names in contradictory ways. For example, suppose you have global variables A and B and functions foo and bar. If you know that variable A will be regularly passed to foo and B to bar, make sure to define the functions as function foo(B) and function bar(A) so that inside the functions A will always be referred to as B and vice versa. With more functions and globals, you can create vast confusing webs of mutually contradictory uses of the same names.
  25. Recycle Your Variables

    Wherever scope rules permit, reuse existing unrelated variable names. Similarly, use the same temporary variable for two unrelated purposes (purporting to save stack slots). For a fiendish variant, morph the variable, for example, assign a value to a variable at the top of a very long method and then somewhere in the middle, change the meaning of the variable in a subtle way, such as converting it from a 0-based coordinate to a 1-based coordinate. Be certain not to document this change in meaning.
  26. Cd wrttn wtht vwls s mch trsr

    When using abbreviations inside variable or method names, break the boredom with several variants for the same word and even spell it out longhand once in while. This helps defeat those lazy bums who use text search to understand only some aspect of your program. Consider variant spellings as a variant on the ploy, e.g. mixing International colour, with American color and dude-speak kulerz. If you spell out names in full, there is only one possible way to spell each name. These are too easy for the maintenance programmer to remember. Because there are so many different ways to abbreviate a word, with abbreviations, you can have several different variables that all have the same apparent purpose. As an added bonus, the maintenance programmer might not even notice they are separate variables.
  27. 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.
  28. m_

    a naming convention from the world of C++ is the use of m_ in front of members. This is supposed to help you tell them apart from methods, so long as you forget that method also starts with the letter m.
  29. o_apple obj_apple

    Use an o or obj prefix for each instance of the class to show that you’re thinking of the big, polymorphic picture.
  30. Hungarian Notation

    Hungarian Notation is the tactical nuclear weapon of source code obfuscation techniques; use it! Due to the sheer volume of source code contaminated by this idiom nothing can kill a maintenance engineer faster than a well planned Hungarian Notation attack. The following tips will help you corrupt the original intent of Hungarian Notation:
  31. Hungarian Notation Revisited

    One followon trick in the Hungarian notation is "change the type of a variable but leave the variable name unchanged". This is almost invariably done in windows apps with the migration from Win16 :- WndProc(HWND hW, WORD wMsg, WORD wParam, LONG lParam) to Win32 WndProc(HWND hW, UINT wMsg, WPARAM wParam, LPARAM lParam) where the w values hint that they are words, but they really refer to longs. The real value of this approach comes clear with the Win64 migration, when the parameters will be 64 bits wide, but the old w and l prefixes will remain forever.
  32. Reduce, Reuse, Recycle

    If you have to define a structure to hold data for callbacks, always call the structure PRIVDATA. Every module can define it’s own PRIVDATA. In VC++, this has the advantage of confusing the debugger so that if you have a PRIVDATA variable and try to expand it in the watch window, it doesn’t know which PRIVDATA you mean, so it just picks one.
  33. 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.
  34. Fun With Colours

    It goes without saying you should use numeric colour literals rather than named constants. Unfortunately, most skilled maintenance engineers will have learnt by now that hex coded colour values are easy to decode, e. g. 0x0204FB is
    Red = 02
    Green = 04
    Blue = FB
    Which is clearly pretty much entirely blue.

    You want is to use the decimal value, 132347. There’s no way without the aid of paper or a calculator that any normal person could convert that into the colour 'blue'. For extra bonus points you can produce a decimal colour that looks like it’s expressed as hex, for example 808000. A quick glance would guess half red + half green = darkish yellow, but in fact it’s not hex, the real colour is 0xc5440 (a dark cyan).

    The Netscape colours are all carefully named. For example papayawhip is 0xffefd5. Just to keep them on their toes, define a papayawhip colour constant as 0xff00ff, a garish magenta. Have fun making up obscure colour names like algae = 0x556b2f instead of darkolivegreen. Very few people know what colour puce and teal are, but would never admit it. Exploit that.

    You can even lay a trap for a programmer who comes after you to do the dirty deed. Use accurately-named but hideous colours. If the follow-up programer is lazy, he will change the colour definitions to something sane, but will leave your original colour names.

coding conventions
how to choose unambigous names: anathema!

This page is posted
on the web at:

http://mindprod.com/jgloss/unmainnaming.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\unmainnaming.html
Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[18.117.71.213]
You are visitor number