Why Befunge is better than Perl

Copyright © 2002 - Jérôme Quelin

[+ del.icio.us] [+ Developers Zone] [+ Bookmarks.fr] [Digg this] [+ My Yahoo!]


Everyone knows Befunge, the famous programming language using a 2-dimensional cartesian Funge. It's obvious that Befunge, by its ease of use, and powerful syntax, is better than Perl. But very few people know that Befunge being the best language ever can be proven mathematically.

A little mathematical reminder...

The Golden Ratio

Whoever has already done some mathematics already knows the Golden Ratio. The Golden Ratio (also known as the divine proportion, the golden mean, or the golden section) is often encountered in the mathematics field.

Supposedly discovered by Pythagoras, it is a Pisot-Vijayaraghavan constant, and has surprising connections with continued fractions and the Euclidean algorithm for computing the greatest common divisor of two integers.

But the Golden Ratio is in fact ubiquitous, and has some fascinating connections with a lot of theorems or well-known mathematical curiosities (such as the Fibonacci numbers).

The Golden Ratio proves correct the folowing equation:

    x^2 - x - 1 = 0

and its value is about 1.6180339

The Golden Rectangle

You can use the Golden Ratio in geometry, which is then called Golden Geometry. It deals with ratios of distances in geometric figures.

Applied to a rectangle, the golden ratio is defined such that partitioning the original rectangle into a square and a new rectangle results in the new rectangle having sides with the same ratio. Such a rectangle is called a golden rectangle.

Golden geometry is well-known by architects, and even the ancient Greeks incorporated it into their art and architecture. Apparently, many ancient buildings (including the Parthenon) use golden rectangles. It was thought to be the most pleasing of all rectangles. It was not too thick, not too thin, but just right.

Because of this, sheets of paper are often somewhat close to being golden rectangles (8.5x11 is not particularly close to a golden rectangle, by the way).

Golden Programming

And that's the point, my friends! Human brain prefers (read: is more efficient) when it must handle things that incorporate golden ratio.

Every programmer knows that a program does not fit in a screen, she must scroll between pages to find a particular line. But that's because she is programming in a brain-dead language, that must fit in 80 columns.

A short experiment

Since we're speaking of Perl, here's a short experiment on my linux box:

    $ cd /usr/lib/perl5
    $ find . -name "*.pm" -print | xargs cat | wc -cl
     415791 11294380
    $ expr 11294380 / 415791

Got it? This means that there is no more than 28 chars on average in Perl code. And in fact, it's even less than 28 chars, since .pm files also carry documentation that use the whole 80 columns in a line.

If we calculate the average number of lines in a file:

    $ cd /usr/lib/perl5
    $ find . -name "*.pm" -print | wc -l
    $ find . -name "*.pm" -print | xargs cat | wc -l
    $ expr 415791 / 872

Now, we can find the ratio for those programs:

    $ expr 476 / 28

Not too difficult: we simply divide the length by the width, that's golden geometry.

Now let's correct those figures a little. The programmer often use a fixed-width font editor, and a letter in those fonts have a big height and a small width. Typically, if we stick to the standard 80x25 terminal, the height is:

    80 / 25 = 3.2

times bigger than the width. So in fact, the ratio in a Perl program is:

    415791 / 872 * 415791 / 11294380 / 80 * 25 = 5.48

As you can see, the result is somehow edifying. 5.48 is not close to the golden ratio, it's more than three times the golden ratio!

Back to Befunge

With Befunge sources, I have the following figures:

    97 files, 740 lines, 28151 characters               [1]
    ratio = 97 / 740 * 28151 / 740 / 80 * 25            [2]
    ratio = 1.56

You can do the maths yourself: Befunge's ratio is about the golden ratio itself!

  [1] Fetching the comprehensive source repository of Befunge
      programs, at Cat's Eye site.
  [2] The ratio should be more than one, so one can invert height and
      width in order to achieve this goal. That's what is done here,
      since Befunge programs are usually larger than long.


Now, do I really have anything to add? The ancient Greeks have understood this, but it seems we lost their wisdom when computer languages were invented. Hopefully, when designing Befunge, Chris Pressey thought about this and decided to create a language that will fit comfortably in a human brain.

Moreover, if you remember how programming in Befunge matches the reality (Befunge is the only language to handle more than one cartesian dimension), then it should be now obvious why Befunge is better than Perl.

[IE7, par Dean Edwards] [Validation du HTML] [Validation du CSS]