Signature program


A signature program is a small, highly condensed piece of code, usually three or fewer lines in length which when compiled produces an interesting pattern or function that is not always obvious from the code.
Signature programs are generally found in the signature section of user posts in forums, messages etc., particularly in technically oriented websites such as Slashdot.

Optimisation and example

In order for the program, often of great complexity, which would usually be represented with many lines of code, to fit into a single line, many compression techniques are used. The following program prints out an ASCII art version of the Sierpinski triangle fractal, shown in the illustration:

main

An uncompressed "spelt out" version of this program may look like this:

  1. include
int main

Here we can see that many portions of code are missing from the signature program, most obviously the lack of #include , no return type of main as well as the use of non-standard main. The ?: operator plays a vital role in reducing the overall size of the program, allowing a single expression to replace the sizeable number of if/else logical conditionals. Size is also dramatically reduced by removing all whitespace and line breaks.
Signature programs often make use of undocumented or lesser-known features or quirks in a particular compiler which allow for smaller overall program size, as well as obscurity.

Obfuscated programs

A common theme in signature programs is to make the code so obfuscated that the outcome and purpose of the program is not apparent, at least to start with, or that the programs are masked to give the impression that the program performs one function when it actually does something completely different, sometimes with alarming or embarrassing outcomes.

MinRay

expert took the condensed program concept to a new level by legibly printing the results of a contest for a minimal ray tracing program on the back of a business card. Code from the Graphics Gems IV is reproduced here.

typedef structvec;vec U,black,amb=;struct sphere*s,*best,sph=;yx;double u,b,tmin,sqrt,tan;double vdotvec A,
B;vec vcombdouble a;vec A,B;vec vunitvec A;struct sphere*intersectvec P,D;vec tracevec P,D;main/*minray!*/

While this is uncomfortably long for a signature, it is remarkably short for a ray-tracer.