Saturday, August 05, 2006

Some interesting aspects of programming : Multi-stage programming

The basic need for "multi-stage programming" arises of the following situation. Say you need to write a program whose result won't be a single number, but rather a computation, for instance a function that double its input f : R --> R , x --> 2*x, or anything that might be represented in some langage of your choice called L. The question is : given L, how do we construct a langage L* which can output some L in a consistent way. One can thinks of generics in dotnet2.0 or Java 1.5 as a particular case of multi-stage programming. Generics are L* functions verifying L syntax, with an extra variable representing a type, and they eventually produce code in L for that type. L* naturally inherits a typesytem fostered by L typesystem. For instance some L* function producing a function outputing a real number cannot be composed with another L* function having strings as an input. Thus an expression that produces code for treating integers can be typed as being such. L* is a first-order langage with respect to L, and its types are expressed using first-order logic to create first-order data types of L. A very nice introduction to a multistage C# or java can be found here. As everyone gets more accustomed to computers, there has been a huge push to get more than just static data, but also exchange programmatic-like structures, like dynamic web pages. There programmers need to have multistaged programming capacities. This explains a lot of the popularity for javascript, along with its universal runtime platform, as its L* can accept almost everything, being a very weakly typed system.

Some interesting aspects of programming : Continuations



If you think about what a program performs, we start with an input and events to deal with.
Based on a certain combination of those we will
    -> perform computation
    -> feed the results to other functions who will themselves do the same
So that in concept, we deal with a graph of control flow, and programming is finding a way to transcript that control flow correctly.

Good programming is about to do it in a way that maximise the signal to noise ratio, maximizing expressivenes, and minimizing the plumbering.

The usual programming langage are "stack based", aka they implicitly gives back computed results to the caller. This implicit and uncontrollable link leads to problems when you want to spread a result in different places, as your graph requires, or decide to deliver the results based on a particular event, like what happens with GUI and generally asynchronous programming (exemple)

That's why continuations, by separating computations from the control flow, are sometimes useful.
  


Technorati Tags: , ,