Saturday, April 10, 2010

Viewing programming as constraint satisfaction

Programming could be viewed as solving a constraint satisfaction problem. We start with some empty disk space and the goal is have a program there. Only the goal state is important. We are not searching for a path. We are searching for a goal state that meets the constraints.

I could view my programming as an attempt to solve the problem efficiently. Modifying existing source code is like a mutation in a local search. Hitting an unexpected constraint and choosing a different path is like backtracking. And rewriting allows me to get rid of old constraints.

A super intelligent machine may laugh. It will see the inefficiency of my primitive attempts. I would seem like a 19 month old baby.

Friday, April 2, 2010

Ulimited "cd -" history

I use bash and I use "cd -" to go to the previous directory. To be able to go back more than one step, I had to replace the original cd command with a function:

# cd with automatic pushd
function cd() {
    if test "x$1" = "x-" ; then
        popd >/dev/null
        pushd . >/dev/null
        builtin cd "$@"

Put that into your ~/.bashrc and start a new bash.

Example usage

/home$ cd /opt
/opt$ cd /var/log
/var/log$ cd -
/opt$ cd -