How to Write Code Nobody Can Maintain (And Still Get Away With It)
This tongue‑in‑cheek guide enumerates a series of deliberately bad programming techniques—ranging from confusing naming conventions and deceptive comments to absurd design choices and hidden macros—aimed at making code virtually impossible to understand, maintain, or test.
01 Naming
Easy‑to‑type names – e.g., Fred, asdf.
Single‑letter variables – e.g., a, b, c, x, y, z (or a1, a2, … if needed).
Creative misspellings – e.g., SetPintleOpening, SetPintalClosing, making search difficult.
Abstract names – e.g., ProcessData, DoIt, GetData, saying nothing.
Acronyms – e.g., WTF, RTFSC, or Chinese pinyin abbreviations like BT, TMD, TJJTDS.
Random capitalisation – e.g., gEtnuMbER.
Reuse names – using the same variable name in nested blocks.
Accent characters – e.g., int ínt (the second ínt is not int).
Underscores – e.g., _, __, ___.
Mix languages – combine English, German, or Chinese pinyin.
Symbolic names – e.g., slash, asterix, comma.
Irrelevant words – e.g., god, superman, iloveu.
Confuse l and 1 – letters that look identical.
02 Deception
Interleave comments and code
for(j=0; j<array_len; j+=8){
total += array[j+0];
total += array[j+1];
total += array[j+2];
/* Main body of
total += array[j+3]; * loop is unrolled
total += array[j+4]; * for greater speed.
total += array[j+5]; */
total += array[j+6];
total += array[j+7];
}Hide macros – e.g., #define a=b a=0-b, looks innocent.
Line breaks – split identifiers like xy_z to hinder search. #define local_var xy\_z // local_var OK Code/display mismatch – UI says "postal code" while code uses "zipcode".
Hide globals – pass global variables as function parameters to disguise them.
Synonyms – use different words for the same concept.
#ifndef DONE
#ifdef TWICE
// put stuff here to declare 3rd time around
void g(char* str);
#define DONE
#else
#ifdef ONCE
// put stuff here to declare 2nd time around<
void g(void* str);
#define TWICE
#else
// put stuff here to declare 1st time around
void g(std::string str);
#define ONCE
#endif
#endif
#endif03 Documentation & Comments
Lie in comments – don’t update them when code changes.
Obvious comments – e.g., /* add 1 to i */.
Comment what, not why
Never comment secrets – hide critical business logic.
Over‑detail – write exhaustive design documents with hundreds of sections.
Avoid units in comments – omit seconds vs. milliseconds, pixels vs. inches.
Gotchas – never comment pitfalls.
Vent in comments
04 Design
Java casts – excessive casting from collections.
Exploit Java redundancy – e.g., Bubblegum b = new Bubblegom();
Never validate – ignore input and return‑value checks.
No encapsulation – expose all details to callers.
Copy‑paste cloning – reuse code without understanding.
Huge listeners – a single listener with massive if‑else chains.
Multi‑dimensional arrays – go beyond three dimensions.
Mix accessors – combine getters/setters with direct public fields.
Layered wrappers – wrap APIs 6‑8 times, deep inheritance.
No secrets – make every member public.
Parameter permutation – swap argument order then revert later.
Rename parameters – e.g., setAlignment → setLeftAlignment, setRightAlignment.
Packratting – keep all unused variables and methods.
Final everything – seal all classes to prevent extension.
Avoid interfaces – use concrete classes everywhere.
Avoid layouts – hard‑code absolute coordinates.
Environment variables – initialise members via getenv() or System.getProperty().
Magic numbers
Global variables – initialise them in unrelated functions and pass them around.
Config files – mismatch parameter names between config and code.
Bloat classes – overload a class with many unrelated methods.
Subclass abuse – create deep inheritance hierarchies for each attribute.
05 Chaos Your Code
Use XML – inflate tiny logic into massive XML files.
Messy C code
Different numeral bases – mix decimal, octal, etc.
Prefer void* – cast everywhere.
Implicit conversions – rely on C++ constructors for silent casts.
Decompose conditions – replace a==100 with a>99 && a<101.
Exploit semicolons – e.g., if(a);else;{ int d; d=c; }.
Indirect casts – new Double(d).toString() instead of Double.toString(d).
Deep nesting – >10 nested parentheses or >20 nested braces.
Array tricks – use pointer arithmetic or i[myArray].
Long lines – make lines as long as possible.
Avoid early returns – no goto, no break, force deep if‑else chains.
Avoid braces – omit {} in if‑else to increase confusion.
Macro abuse – hide logic behind macros.
Trivial wrappers – wrap a bool in a class that does nothing.
Loop inversion – replace for‑loops with while, swap bounds, change < to <=, etc.
06 Testing
Never test – ignore error handling and system call returns.
No performance testing – blame the hardware instead of optimizing.
Don’t write test cases – skip coverage and automation.
Testing is cowardly – claim a brave programmer needs no tests.
07 Miscellaneous
Your boss knows everything – obey blindly to learn unmaintainable tricks.
Subvert the help desk – hide bugs from support, deflect users.
Keep quiet – don’t disclose major bugs, even to close contacts.
Spin – label terrible code with GoF patterns or agile buzzwords.
In short, our motto is – Write Everywhere, Read Nowhere.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
