• Forum
  • Lounge
  • Want to write unmaintainable code? Here'

 
Want to write unmaintainable code? Here's how!

Dec 7, 2008 at 5:33pm
http://freeworld.thc.org/root/phun/unmaintain.html

These are some of my favorites:
C's Eccentric View Of Arrays
C compilers transform myArray[i] into *(myArray + i), which is equivalent to *(i + myArray) which is equivalent to i[myArray]. Experts know to put this to good use. To really disguise things, generate the index with a function:

int myfunc(int q, int p) { return p%q; }
...
myfunc(6291, 8)[Array];

Unfortunately, these techniques can only be used in native C classes, not Java.


Lisp
LISP is a dream language for the writer of unmaintainable code. Consider these baffling fragments:

(lambda (*<8-]= *<8-[= ) (or *<8-]= *<8-[= ))

(defun :-] (<) (= < 2))

(defun !(!)(if(and(funcall(lambda(!)(if(and '(< 0)(< ! 2))1 nil))(1+ !))
(not(null '(lambda(!)(if(< 1 !)t nil)))))1(* !(!(1- !)))))


Names From Mathematics
Choose variable names that masquerade as mathematical operators, e.g.:

openParen = (slash + asterix) / equals;

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.
Dec 8, 2008 at 10:54am
I lol'ed
Dec 8, 2008 at 10:56am
Hahaha oh man you could so do like:

marypoppins = (superman + starship) / god;


1
2
3
4
5
6
//Power Levels
superman = 1000;
starship = 20;
god = 10;

marypoppins power is = to those
Dec 8, 2008 at 2:41pm
I have always hated Hungarian notation. It is a blight that has stunted programmers since its inception.

Now I have something I can use to back up my claims. :-)


Other fun places to peruse:
http://www.ioccc.org/
http://www.catb.org/~esr/jargon/ (Be sure to check out "The Story of Mel")

XD
Dec 8, 2008 at 5:56pm
Hahaha this topic is awesome.
Dec 8, 2008 at 6:19pm
The sad part is how much of it is not considered facetious.

I recently submitted a modification to a project where I renamed a local variable (in a function I entirely rewrote) from buf to something that actually described what it held.

The maintainer gave me a hard time for "spuriously" renaming variables.

(I leave him/her nameless because he/she is a good guy/gal, who otherwise knows his/her stuff, better than I do.)
Dec 8, 2008 at 6:43pm
Something cool is creating C-strings starting from integer arrays:
1
2
3
int I[4] = {1819043144, 1867980911, 543452274, 0};
char* c = (char*)I;
//Assuming int to be 4 bytes 
Dec 8, 2008 at 9:04pm
That also presumes Intel-byte ordering (little-endian).
Dec 8, 2008 at 9:39pm
I remember this expression I wrote once. We were using a software called Quest3D that didn't use written source code. Instead, all we did was link together a series of boxes that each did something different. If there is such a thing as a "personal Hell", I'm pretty sure that one's mine.

Anyway, the if box was unusable, so when I had to use if, I did what any other programmer would have done in my place with an "expression" box: I hacked together the most complex trinary operator expression ever.
The box took five values as input and produced some other value that I can't remember what it was anymore. It was either a value to send to one of other nine boxes, or an index that would be used to tell the other nine boxes to ignore or recognize the value.
The expression had to be at least 1000 characters long, and had no less than three ?: nesting levels. It was a good thing that the parser ignored whitespace, because reading the expression in a single line was absolutely impossible.

And while I'm at it, all of Quest3D has "unmaintainable" written all over it. You can make and link so many boxes before all you're left with is an incomprehensible mess of lines and rectangles.
And it's also an exercise on running parallel code in your head. Different branches of boxes are executed at the same time. I once had to put a NOP box (it was just an expression box the simply returned the parameter. I wish there was an actual NOP box), just to keep the threads synchronized.

You'd think that something like this would be *at least* free, and that ideally the designers should pay us for the horror they created. Well, you're wrong. You can get the latest version of Quest3D for the modest price of € 10,000. You heard it. It costs more than the most expensive version of Visual Studio 2008.
Last edited on Dec 8, 2008 at 9:58pm
Dec 10, 2008 at 6:54am
I loved the IOCCC when I found it a couple years ago. What some of those folks did was truly amazing.

A couple years ago I learned how GCC implemented member function pointers when the pointer was to a virtual function. I used that knowledge to write a program that implemented a CPU simulator with a really esoteric instruction set. Something like 'A' meant Add, 'B' meant subtract etc. I would then take a pointer to the first virtual function in the class and add to it the opcode - 'A' so that it would call the virtual function to handle the opcode rather than the virtual function I took the pointer to.

It was so awesomely unintelligible and such blatant ignorance of all C++ coding standards that I actually wrote an assembler for the language after that so I could write more complicated programs (you had to pass the executable code as argv[1]--all instructions used only printable ASCII characters--and it was a little difficult to modify the 'machine code' by hand).

I'm actually pretty happy with the assembler. It does a pretty good job considering the brain-deadness of the instruction set. It even handled multiple files / includes....



Topic archived. No new replies allowed.