I read a book on a bunch a kids that beat up Vegas at blackjack with an elaborate card-counting system involving several people and lots of statistical tables. Somehow, out of that, I wondered how dense Perl programs look---that is, when we view them in an editor, just as characters.
So, I started to write a tiny program to compare the amount of visual whitespace (e.g. tabs count more than spaces) to the number of characters. That is pretty useless though, except as a rough measure of overall density. Programs are hard to read because they have islands of high density, so the overall approach doesn't work.
Next, I wrote what I call my "minesweeper" program. I would show it here but the program is on my laptop and I am using a restricted community computer. Basically, I go through a text file and look at all of the positions around a position. Each character can have eight characters around it. For each non-whitespace character around a position, I add 1 to that position. Whitespace and edges (including the parts of lines longer than the ones around it) get 0. The output from that is not very illuminating because it is denser than the programmer because it is just a big matrix. Mathematically it works, but visually it is worse.
So, from there, I created a density plot using GD::Graph. I create a canvas with the same number of rows and columns as the script, then color the pixels. Positions with higher densities show up darker. Positions with zero density show up white. Right now it is grayscale, but I would like to use colors at some point.
On one run, I ran the program using its source as input. The results were surprising. The islands of high density are where I would expect them (where all the typing is, silly), but their contour really shows where I am putting a lot of characters close together, which, I contend, makes the program harder to read there, just like it is harder to read porportional fonts (at least I think so).
Some programs are long (Shocked! Shocked I say!), so I break up the program into several images. Putting a bunch of small images on a single peice of paper can represent the entire program quickly.
Next, I want to make several images of the same script from different versions, then create a movie out of it---let's see how the density changes as we code. It probably varies from coder to coder, but I think for my stuff I would see a lot of random stuff, then points of gravity pulling code towards it, then a big bang where bits of code travel long distances as they get relegated to subroutines at the end of the script---maybe a text version of the Oregon Trail.
For some people, the gravity centers will keep attracting more and more characters, so I am also thinking about adding long distance effects. A character two positions away counts partially, although I have not decided if it should be a second or third power effect. If I really want to waste a lot of time, I can figure out how to calculate a programs Big-G gravitational constant, or shoehorn special relativity (some piece of code must bend the code around it somehow).
Some people may have density islands that seem to pulse as they add or subtract code. Who knows?
I still have a lot of small technical problems to decide. Do I keep the POD in or out? Or do I color it differently?
Oh well. Six minutes left on this computer.