Jun 2017

Code as Art I

There is code out there that when I look at it has a certain kind of appeal to my visual senses. Old style code has the effect of mild nostalgia (until I recall having to compile everything just to get it to run efficiently) while other code has the effect of perhaps making me see things in a different way without even understanding what the code does. In this series I take a look first at some of my own code through different colored lenses by changing vim color themes and different languages.

Simple & Succinct

One of my favorite programs to crack open in an editor and look at is etu which used to stand for Epeg Transform Utility but since it relies on imlib2 now I guess Enligtenment Transform Utility probably makes more sense.... whatever. What I like about it is how simple the program and code is. Anyone familar with C can probably figure out everything that is going on pretty quickly (and everything it does wrong... whatever). It all starts with the header file:

etu_h

and then into the source file:

etu_c

etu_c2

The etu program is probably the most deliberate program I have ever written. When I finalized it the goal was to be as readable as possible while retaining the core function. Of course, in the end, with tools like mogrify and other imlib2 utilities it is kind of dated. In fact, I keep it around solely because it is so clean and well formatted. What I find most interesting about etu is the program is designed to manipulate images, or ostensibly, a program that I consider artful, in a way, which manipulates other art. A hidden meta-function? I dunno ...

Ultra Clean Python Proggie

Python, by its very nature, enforces a cleanliness and structure to its syntax... which by no means does not mean others cannot find ways to totally obfusicate it. I have seen Python code that is absolutely horrible. This little gem which is part of the pwutils package is super compact and of course well indented (although there isn't much to indent):

cpy1

A Perl Middle Ground

Perl from my own point of view is the popular polar opposite of Python as there are no strict formatting rules and while it is strongly typed, Perl is typed by context (something as half hack of a writer I really like.) but I do my best to ride a line of style when I crank out Perl code. In this example, I think the script keeps to both Perl traditions while being formatted similarly to a C program:

Perl

Tangled Wires

Not only am I not a professional programmer (not a profesional anything) but sometimes in code we get into situations where there is just no good way to get out of them. At least I think so. Here is a code snippet from a tiny tcpdump clone program module that is part of the netstr project. I have, for years, been trying to come up with a better way to deal with it and have come up empty each time:

etu_h

What is really bizarre is the output:

 sudo netstr tcpdump --if eth0 --polls 3 port 22
Starting capturing engine on eth0...
Tue Feb 23 18:48:48 2016 : 192.168.1.2:41978 > \
     192.168.1.9:22 tcp len 60 off 16384 ttl 64   \
     cksum 46613 seq 3162571457 ack 0 win 4210
Tue Feb 23 18:48:48 2016 : 192.168.1.9:22 >  \
      192.168.1.2:41978 tcp len 60 off 16384 ttl\
       64 cksum 24759 seq 3605267132 ack 3179348673 win 36920
Tue Feb 23 18:48:48 2016 : 192.168.1.2:41978 >\
       192.168.1.9:22 tcp len 52 off 16384 ttl 64\
       cksum 48405 seq 3179348673 ack 3622044348 win 58624
Closing capturing engine...

Not so bad to look at, but where it comes from is a mess.

Many Panes of NASM

As a thought project, I cracked open an old simple nasm bootable floppy program, loaded it into vim then changed the colorscheme a few times. The result I think is very interesting. As an exercise, try looking at each one of these individually or next to eachother and see what it brings up. I put in my own ideas:

BnW ASM

old school-ish is the first thing that came to mind and then...

red ASM

Readers are probably not familar with them, but that colorscheme looks very similar to late 1980s and early 1990s US Navy tactical console displays. At the time Amber screens and some red text was used (the military had found other colors caused certain problems... although later it was learned the amber displays caused sailors to fall asleep).

and of course; had to do The Matrix:

cyan ASM green ASM

The greener shot also looks a little old school like the old style vt green terminals, some of which were amber as well. Some readers might not know but old OpenBOOT systems had all white backgrounds with black text.

In the end the military found out the best way to avoid sleepy or worse, ticked off, sailors (all red, all blue and all green consoles caused sailors to become agitated) was to finally move towards multiple colors, kind of like this LXterminal screenshot:

mixed ASM

Notice the mild tones of the colors also give it a sort of old school yet modern (as in more than one color) feel.

Summary & Next Time

Is it art? These primitive examples show some of how, in my opinion, there exists an aesthetic to code itself not exclusively what the code is capable of. These were some very simplistic examples but illustrate how visuals can be interesting and even set a certain tone for the hacker, programmer, developer, sysadmin, enthusiast or all of the above. Next time will be a look at some interesting visualization concepts like terminal session managers and colors, layering and whatever other strangeness I can come up with.