Hommage à Douglas Adams
Le langage de programmation Ook
Code : Tout sélectionner
++++++++++[>+++++++>++++++++++>+++>+<<<<-] >++.>+.+++++++..+++.>++.<<+++++++++++++++. >.+++.------.--------.>+.>.
Code : Tout sélectionner
/==!/============atoi=@@@@=@@=--#
| | /==!/====itoa=@@@@=@@=++#
| | | |
$,@/>,@/@\@/.<@/.#
| /-\
\===div=?\<!\?/#!===+<<<\ /-\
\<==@\>@\>>!/?!/=<?\>!\?/<<#
| | #\->->+</
\=!\=?!/->>+<<?\#
#\?<<+>>-/
Reverse the Usual True False Convention
: Reverse the usual definitions of true and false. Sounds very obvious but it works great. You can hide:
#define TRUE 0
#define FALSE 1
somewhere deep in the code so that it is dredged up from the bowels of the program from some file that no one ever looks at anymore. Then force the program to do comparisons like:
if ( var == TRUE )
if ( var != FALSE )
someone is bound to "correct" the apparent redundancy, and use var elsewhere in the usual way:
if ( var )
Another technique is to make TRUE and FALSE have the same value, though most would consider that out and out cheating. Using values 1 and 2 or -1 and 0 is a more subtle way to trip people up and still look respectable. You can use this same technique in Java by defining a static constant called TRUE. Programmers might be more suspicious you are up to no good since there is a built-in literal true in Java.
1.
A Real Life Example
: Here's a real life example written by a master. Let's look at all the different techniques he packed into this single C function.
void* Realocate(void*buf, int os, int ns)
{
void*temp;
temp = malloc(os);
memcpy((void*)temp, (void*)buf, os);
free(buf);
buf = malloc(ns);
memset(buf, 0, ns);
memcpy((void*)buf, (void*)temp, ns);
return buf;
}
* Reinvent simple functions which are part of the standard libraries.
* The word Realocate is not spelled correctly. Never underestimate the power of creative spelling.
* Presume malloc will always return successfully.
* Make a temporary copy of input buffer for no real reason.
* Cast things for no reason. memcpy() takes (void*), so cast our pointers even though they're already (void*). Bonus for the fact that you could pass anything anyway.
* Never bothered to free temp. This will cause a slow memory leak, that may not show up until the program has been running for days.
* Copy more than necessary from the buffer just in case. This will only cause a core dump on Unix, not Windows.
* It should be obvious that os and ns stand for "old size" and "new size".
* After allocating buf, memset it to 0. Don't use calloc() because somebody might rewrite the ANSI spec so that calloc() fills the buffer with something other than 0. (Never mind the fact that we're about to copy exactly the same amount of data into buf.)