23 October 2011

Prospects for virtual life: Is Java a Wittgensteinian language?

Several years ago I wrote an article saying that Object-Oriented Programming (OOP) looked a lot like the Platonic vision of the world and wondered whether a Wittgensteinian programming language could be created. From the article:
...although at ground level OOP is still actually made of loops and conditions, it sure looks different from a programmer's point of view. In case of OOP you have to deal with so called objects (such as a button or a window or a menu or whatever you invent) and these objects have properties, events and methods.

Traditional programming was causal, while OOP is intentional. Traditionally, you would tell the computer something like: "Do this, then that, if the user does that go that way, if (s)he does that other thing go the other way, then enter this loop and continuously check and check and check whether the user has done anything you have plans for, and God forbid (s)he does something unexpected, and so on." Usually, you would have to predict any possible action the user could do and devise a certain response.

In OOP you are not programming in such a causal manner, you are actually setting various purposes or functions to various objects. You say "The purpose of this button over here is to open up that window", "The purpose of this text box is to get some text from the user." And so on. This allows you to create much more complex programs in a more bug-free manner.

A property is how the object looks like. For example, it has a certain color, or a certain text imprinted on it, or has a certain position inside a window and so on. When you change the value of some property, the object miraculously changes its appearance. You're just saying "I want you to be like that", and it becomes like that.

An event is something that can happen to the object. For example a button can be clicked. Or the mouse can go over it. A text can be changed. Etc. You, as a programmer, can say to an object: "If this event ever happens to you, this is how I want you to react."

A method is something that the object can do. While events are things inflicted on objects, methods are the things the objects themselves do. For instance, a text box can undo a text change or can copy the selected text to Clipboard.

What's fun from a philosophical point of view is that this OOP creates a very platonic virtual world. Plato's most famous idea is that everything in the real world, everything that we see and ourselves included, is only a sort of copy of some "archetypal" or ideal object. In the same way, every object OOP deals with is created from a so-called class. A class is the ideal, platonic object. A class consists in a set of properties without a specified value, having empty events and methods. To create a particular virtual object (that you can actually see on screen or with what you can actually do anything) you assign certain values to the ideal object (to the class), and write some code for its events and methods.

The class defines in a sort of abstract manner what all the possible objects of that type could be like. A class doesn't define a particular button, but defines the concept of any button. Translating Plato into OOP language: he believed the true world is the world of classes only, while the world of objects is only apparent (he used the following metaphor: objects are like the shadows of the classes, and we are only seeing these shadows, wrongfully taking them for real). In other words, he believed God was a computer programmer that did the job in a divine Visual Basic.

The philosopher most famous for debunking Plato's vision of the world is Wittgenstein. Wittgenstein's most famous idea is that objects in the real world are not the outcome of some platonic classes, but that they come in "families". A family is a set of real objects that resemble each other from various points of view. For example, the family "chair" is a set of all the objects that we call by that name. But we group together these objects in one single family, not because they share some common essence, but out of historic accidents. For example, in Romanian a toilet seat is called a "toilet chair" (because Romanians read sitting on the toilet more often than the English). To Romanians the toilet seat is part of the "chair" family, while the English have a more restrictive concept of "chair".

For describing his idea, Wittgenstein used the metaphor of a rope: a rope is made of many fibers, but there's no fiber that has the same length as the entire rope. In the same way, object A resembles object B, which resembles object C, and which, in turn, resemble object D, and all these objects may be part of the same family, but nonetheless, object A may not resemble object D in any dramatic manner. In other words, there's no common thread through all the objects called by a certain name - i.e. belonging to a certain family.

I've been wondering how a Wittgensteinian programming language would look like. Suppose the buttons and all the windows you could encounter in this virtual world would not arise from certain classes, but they would belong to a family. I think the virtual world would be much more diverse and fun, and, probably, any programmer's nightmare.

In order to create a new object, you would have to take an existing object and modify it in various ways. But there would not be any predetermined class to tell you in what ways you may modify it - a predetermined concept of "all" objects of that type. I guess such a Wittgensteinian standard would be great for the open source programs.

I've noticed now that someone made an interesting comment that Java can be seen as an example of such a Wittgensteinian language:

Maybe JavaScript is more of a Wittgensteinian language. It has three big differences compared to C++, C# and Java: First, there's no distinction between objects and classes; new objects are created not by instantiating classes but by copying existing objects. Second, it uses duck typing -- instead of checking whether an object is derived from a particular class, you check whether it has a given property or method. Third, there's no enforced encapsulation; properties and methods can be added or changed from without.

It seems to me that this is an important threshold, much more important than the transition from traditional programming to OOP. The reason is that evolution by natural selection works in a Wittgensteinian language. For instance, all living beings form a large Wittgensteinian family created by biological evolution - different species exist because extinction has created gaps in the threads of family resemblances that link living beings one to another, and not because members of a species are instantiations of an abstract class (this was Darwin's main insight, see Dennett 1995, chapter 2 for details). Once a Wittgensteinian programming language is available (e.g. Java), one can develop genuine evolution by natural selection in the virtual world. Java would be the equivalent of DNA.

I'm thinking of the following thing. Right now all programs are the result of intelligent design, i.e. each new program is the result of some human programmer making the changes in order to achieve some desired goal (such that the program serves some desired function). However, with a Wittgensteinian language it is possible in principle to eliminate the programmer entirely, and just let programs evolve under the selection pressure of users' demands. For example, right now many programs collect crash reports and improvement suggestions from users, but actual human programmers need to sift through all these reports and decide what changes to make. An Darwinian alternative to this system would involve an automatic meta-program sift through the reports, operate changes in the program and test the program (the alpha version) against a set of users willing to serve as testers (as it commonly already happens).

Biological evolution provides another important suggestion: the meta-program can be written in the same language as the program. In case of life, DNA is not enough to make a living being, DNA has to be transcribed into the proteins that actually make up the creature by some enzymes - but these enzymes are themselves proteins, and, as such, the information about how to make them is also coded in the DNA. This is a loop. The consequence of this loop is that not only life forms change, but also the mechanism for building life forms can change (and it did change - these are known as the "major transitions in evolution", see Maynard Smith & Szathm√°ry, Carroll, or Kirschner & Gerhart).

Applied to the virtual world of computer programs, this idea would mean that the program that sifts through user reports and which operates the changes in existing programs developing new versions can itself be written in Java (or in some other Wittgensteinian language), and, as such, can also be subjected to evolution by natural selection. This would thus become a self-contained system for developing better and better (i.e. in line with users' demands) computer programs without any need for human computer programmers.