2004-10-02

Flon's law

Here's a nice quote that popped up when I ran the fortune command today:

Flon's Law:
There is not now, and never will be, a language in which it is
the least bit difficult to write bad programs.


As a computer science student this is both interesting and provocative. But perhaps not as provocative as it first seems. It depends on what this Flon means with "bad programs". First of all I think it is safe to say that all programs which are incorrect are bad. These are programs which don't follow the specification or the programmers intent. Other programs which are bad might be those that are difficult to understand. A third category which is related to the second one is programs which are difficult to maintain. Those are programs which are badly structured and don't contain the right generalisations.

Now, I believe that language features in general are invented or added to a language because they make it easier to write good programs, i.e. programs which are correct, easy to understand and maintain. But is might be that these feature doesn't go that well together and make it very easy to write bad programs. The canonical example here is C++. It is certainly possible to write good programs in C++ but it is extremely easy to write bad programs. It is almost as if the language encourage you to do that.

But I do believe that some languages are better at forbidding bad programs than others. Haskell has a number of features which I believe make it a better language in this sense. Haskell has a strong static type system which prevents many buglets to go through compilation. But strong types can also be used to enforce almost arbitrarily complex properties about you program. Haskell also have a separation between pure and side effecting computations. Side effects are well-known for being difficult to reason about and make programs more error prone. A third feature of Haskell is automatic memory management. These three features makes it in my opinion more difficult to write incorrect programs. But they do not improve on the situation when it comes to understandable or maintainable programs. I have a hard time imagine a language which enforces understandable and maintainable programs. Advanced module systems only make it possible to write maintainable programs they do not enforce it.

So, my conclusion is that Flon's law is true. In all languages I know it is possible and even easy to write programs which are bad in the sense that they are difficult to understand and maintain. But I do think that some languages are better than others in that they make it more difficult to write incorrect programs. That I think is a big win and I think it is worth pursuing that line of research.

1 comment:

Hernan Echegoyemberry said...

Nice to read this, I agree with you, I've even put a kind of rant on stackoverflow about this a couple of years ago

http://stackoverflow.com/questions/3110140/take-care-about-precedence-of-and-in-c-c-and-any-keystroke-when-program

Perhap (I hope) someday this should be a merit criteria for a language.

"There is a poor Hamming distance between any code and any bug"

=)