Montag, 2. November 2015

Doing considered harmful

This is a bit of a philosophical excursion about beeing and doing and why doing is inherently dangerous

In our every day life we are accustomed to doing things. The result of doing something is an altered state of the world. This is quite different in mathematics. While the mathematician might be doing something, math itself does not do anything, math just "is".

Why is math so good?

When I was a student I had a chance to talk to a computer-science professor and I asked him the following question: "why is math capable of going from simple things like counting to elaborate things like tensor calculus and remain free of bugs, while in computer science we cannot accomplish such a thing and the more complex a program gets the more bug-ridden it becomes". He praised me for the intelligent question, but he did not have a satisfactory answer.

In hindsight I came to the conclusion, that the ingredients that enables math to climb such high levels ob abstraction are guarantees. In fact that is at the heart of all mathematical reasoning: there are things which are guaranteed to be true and from there you derive new things, which are then equally guaranteed to be true.

No guarantees

When you write an imperative program, the core ingedient is a statement. There may be other constructs like procedures, classes and so forth, but at the end of the day, these just organize statemens and to some extend limit the effect a statement can have.

A statement does something. Is there anything guaranteed about statements as such? There's certainly not much. The only guarantees I can come up with, is that a statement takes time and energy when executed.

So I believe, programming started on the wrong foot when making statements the heart of the matter. You are already on shaky ground to begin with.

Now of course, some statements are so simple that you can actually tell what they do and thus make a guarantee. But this only hold for thise particular statements and not for statements in general.

Compare this to math, where e.g. it is guaranteed, that every Integer has a successor. Imagine how difficult life would be, if this was true only for certain Integers. You'd have to inspect an Integer to determine whether it has a successor or not.

Math in programming

Incidently not all of programming is about statements. Every self-respecting programming language has a notion of expressions. An expression is something like

sqrt (a*a + b*b)

This is not a statement. It does not really do anything unless you are interested in the value it computes to:

c = sqrt (a*a + b*b)

Now when it computes c, you still don't care how it is computed. It may start by computung a*a or with b*b and you couldn't care less.

Doing and being

So in most programming languages there is a world of doing (statements) and a world of being (expressions) and programmers switch between these world effortlessly without even noticing.

But saying that "understanding a program means undestanding what it does" is clearly wrong. First this does not hold for expresions and second there are programming languages where the aspect of doing is completely absent.

Programming without doing

The following programming languages lack the concept of doing:

  1. In Excel or any other spreadsheet, a cell contains either an input value, a constant or a formula. The cells with the formulae show the results of the computation. The author of the spreadsheed does not care how the result is obtained. 
  2. The select statement is SQL produces a result in a way which is opaque to the programmer (at least it should be). The programmer does not know what the underlying engine does
  3. Pure functional programming languages like haskell do not have a concept of doing. In that respect they are conceptually closer to Expressions, Excel and SQL than to java.
Conclusion

In everyday life, doing is  quite respected. It is the only way we can change the state of the world. Usually we do things with some goal in mind. But let me ask you this question: "how well does this work for you?".

In my expericene it doesn't work well at all. The world is full of unintended consequences. Now uninteded consequences is the one thing we don't need in programming.

In the real world, we don't have any choice other than doing things. But, in order to avoid unintend consequences,  we should stay away from doing wherever possible.







Keine Kommentare:

Kommentar veröffentlichen