Thursday, March 29, 2012

different ways to organise code

side effects and global variables

variable1 = 0;
variable2 = 1;
...
foo();
bar();



bundling state into a context structure

struct State;
State ctx;
...
foo(ctx);
bar(ctx);



bundling the data and the methods together


class State;
ctx = new State;
...
ctx.foo();
ctx.bar();


Define the computation as a "type"

monad ctx;
...
dosomething = ctx(state).
foo().
bar();


dosomething();

No comments: