Programming Language Perversity
Harold Abelson once said that code should be written for humans to read and only incidentally for computers to write. It follows that, like any form of communication, code can carry emotions. Programming perversity, then, is code that conveys morbid fascination, the kind of amused horror where you cover your eyes but peek through your fingers. Take some innocuous features of a programming language and then bend it all into a pretzel. Congratulations, you've made performance art.
The IOCCC, International Obfuscated C Code Contest, was the first mainstream programming perversity. This is the winner of the 1985 contest:
#define P(X)j=write(1,X,1)
#define C 39
int M[5000]={2},*u=M,N[5000],R=22,a[4],l[]={0,-1,C-1,-1},m[]={1,-C,-1,C},*b=N,
*d=N,c,e,f,g,i,j,k,s;main(){for(M[i=C*R-1]=24;f|d>=b;){c=M[g=i];i=e;for(s=f=0;
s<4;s++)if((k=m[s]+g)>=0&&k<C*R&&l[s]!=k%C&&(!M[k]||!j&&c>=16!=M[k]>=16))a[f++
]=s;if(f){f=M[e=m[s=a[rand()/(1+2147483647/f)]]+g];j=j<f?f:j;f+=c&-16*!j;M[g]=
c|1<<s;M[*d++=e]=f|1<<(s+2)%4;}else e=d>b++?b[-1]:e;}P(" ");for(s=C;--s;P("_")
)P(" ");for(;P("\n"),R--;P("|"))for(e=C;e--;P("_ "+(*u++/8)%2))P("| "+(*u/4)%2
);}
It prints a random maze.
The Underhanded C Contest is significantly more perverse in intent (make evil code look innocuous) and/but the code is a lot more subtle. It hasn't run since 2016. I miss it.
Aphyr's X-ing the technical interview series is the highest-profile modern-day example of perversity. It's popular enough that X-ing the technical interview is now a meme.1 Richard Towers used the format to solve N-queens with the Typescript typechecker, and my friend Lars Hupel solved fizzbuzz with Kubernetes ingress rules.
I've published a couple of perversity demos: one on implementing a tag machine in vim keystokes and one on pattern matching crimes in Python, like matching on whether the object has private fields. I got the word "crimes" from Xe Iaso's Crimes with Go Generics, where she implements a variety of things, like partial function application, via generics.
My favorite, uh, perverse-person is Kevin Kuchta. Some of his masterpieces:
- A URL shortener with AWS Lambda, just Lambda.
- Webchat frontend implemented entirely in pure CSS
- Turning the Typescript typechecker into a spellchecker
He's incredible. An artist who's medium is source code. That's what I like about perversity: it's a particular kind of humor that only makes sense to other programmers.
What makes for good perversity?
This is more "what I like" than actual hard and fast rules. Good perversity is
- Unexpected: it does something that you wouldn't expect to be possible. Positive example: implementing webchat in CSS. Negative example: printing "hello world".
- Creative: it does this by combining simple unrelated features. PE: combining background images, pseudoselectors, and forever-loading pages. NE: using macros and metaprogramming, stuff we already expect can do weird stuff.
- Elegant: the vague sort-of-idea that the perversity stands by itself without a lot of extra fluff backing it up. PE: underhanded C. NE: obfuscated C, Enterprise Hello World
- Awful: it triggers a deep sense of why are you doing this?!
Bonus points for perversity that is, for some god-forsaken reason, actually useful in the real world. It's unexpected, creative, elegant, and perverse that you can write arbitrary JavaScript with just !+[]()
. It is amazing that you can use this to bypass Ebay's malware protection software.
-
Just once I want to see a subversion where the interviewer outcrazies the candidate ↩
If you're reading this on the web, you can subscribe here. Updates are once a week. My main website is here.
My new book, Logic for Programmers, is now in early access! Get it here.