A stylistic viewpoint on compressed code

I talked about this in a previous post (Did old code have weird style?). I think it really appeared with Algol 60, and disappeared somewhere in the 1980s. Partially I think it had to do with compressing code onto one line to reduce the number of punch cards needed. Otherwise, as Algol syntax was heavily used in articles, I imagine it had a place there, compressing code, that would have otherwise bloated.

Here’a an example from Algol 60:

procedure maxmin(a,m,n,large,small); value m,n;
    real array a; integer m,n; real large, small;
    begin real big, little; integer i, j;
        big := little := a[1,1];
        for j := 1 step 1 until n do
        for i := 1 step 1 until m do
        if a[i,j] > big then big := a[i,j] else
        if a[i,j] < little then little := a[i,j];
        large := big; small := little

The programmer of course had to know their syntax… there is very little in the way of indenting. This is largely because Algol was the first language to really embrace “free” style. Fortran and Cobol  were still somewhat fixated on fixed style.

If we were to write this now (in say C) , we might wind-bag it out.

void maxmin(double a[], int m; int n; double *large; double *small)
    double big, little;
    int i, j;
    big = a[0][0];
    little = a[0][0];
    for (i=0; i<m; i=i+1)
        for (j=0; j<n; j=j+1)
            if (a[i][j] > big)
                big = a[i][j];
            else if (a[i][j] < little)
                little = a[i][j];
    *large = big;
    *small = little;

What about if we wrote the code in “compressed” Julia?

function maxmin(a,m,n)
    little = big = a[1,1]
    for i=1:m, j=1:n
        if (a[i,j] > big) big = a[i,j]
        elseif (a[i,j] < little) little = a[i,j] end
    return little, big

Would it be terrible? I have to believe from a stylistic viewpoint, and even from a readability viewpoint, some use of compressed code is optimal.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.