Monday, January 14, 2008

Stackless Python

Erlang is currently getting a lot of attention as a language that supports concurrent programming with a large number of simultaneous lightweight processes (or threads if you prefer). But there are few reasons its ~sibling - Stackless Python - should get less attention, some preliminary benchmarks support that.

During grad school some students and I used Stackless Python in combination with MPI to create a simple simulation of a large number of players and NPCs in multiplayer games on a cluster. The game world was divided onto machines in the cluster and on each machine a few thousand tasklets (also called microthreads) each representing individual players and NPCs ran. When they ran into each other they communicated using channels. When players or NPCs came to the boundary of the game world we sent the serialized state of the tasklet representing the player or NPC using MPI messages to the neighbor CPU world.

Stackless Python turned out to be a very nice language to code in, and in fact the students and I tried to start a company providing microsimulation consulting services using it. Unfortunately such services turned out to be of much less demand than anticipated so we had to stop our efforts in that direction. But that wasn't Stackless' fault, in fact I would recommend having a look at Stackless Python if you consider doing microsimulation.

Search Engine Industry History in Trondheim

A friend of mine wrote a nice entry on what turned out to be part of the search engine industry history in Trondheim, please have a look.

Sunday, January 13, 2008

Future number of programming languages - singularity or infinity?

The development of programming language technology is going at a relatively moderate pace. And it seems like every new programming language tries to become the (singular) language that can be used to solve all problems, I believe that is the wrong approach since it tends to make the languages big, complex and hard to learn. This complexity is reflected in the readability and maintainability of code in such languages. According to Bruce Eckel and Neal Gafter it seems like Java is close to reaching some of those pain points.

Domain-specific languages (DSLs)
I believe a better approach would be to create small and highly domain-specific programming languages that can be mastered in a few minutes and function as specialized tools.

If you've ever done house refurnishing you know the thrill of finding the exactly right and highly specialized (frequently electric) tool for the job, it may not always be more efficient to use than a more general tool, but surprisingly often it is, and often by orders of magnitude (in user time).

I believe there is potential for similar efficiency gains by increasingly using domain specific programming languages. The alternatives to create domain-specific languages are usually to add features to already large and complex languages (not an option) or add more libraries to the large language, the latter is ok, but it can be hard to make these library APIs as syntactically efficient, expressive and pleasant to use as a domain-specific language.

Domain-specific languages - where and how?
Functional programming has in the last few years had a revival, e.g. Google's mapreduce for large-scale parallel computing, Python and Ruby adding Lisp-like features, and in upcoming languages such as Haskell and Erlang. I believe future domain-specific languages will borrow some from functional programming, but probably even more from declarative programming (e.g. Goedel or languages with inductive logic programming support, e.g. Aleph).

A typical sign of where a domain specific language could fit is when you need to write hundreds of lines of boilerplate code to get something done, and that something can be described in one sentence. Boilerplate code is in my opinion about as useful as heat from a light bulb, or noise produced by a computer. And since syntax matters I believe the syntax of most domain specific languages should resemble Python since Python leads the expressivity axis (i.e. gzip of source) of the great computer language shootout (but I am open to even more pleasant alternatives, please enlighten me). One issue with using a Python-like syntax is the representation of types, but I don't think that will be big issue for tight and highly declarative domain-specific languages.

But how should all the domain specific and other languages communicate?
Great question. Not sure, but I believe mainly through some kind of network/RPC interface. It is of course tempting to make the domain specific languages borrow from their "carrier" (e.g. jython being python + relatively full java access), but I am not sure if that is the right direction. But for runtime environments they should be both interpretable and being able to run on common virtual machines with just in time compilers (e.g. jvm). Even though there are some nice parser and compiler tools, e.g. antlr out there, I still think there is plenty of opportunity to create tools to support (rapid) development of domain-specific languages.

So I believe the number of programming languages is likely to diverge from singularity.

Who is the next?

The last 10 or so years there has been several internationally well-known IT companies establishing themselves with engineering presence in Trondheim, either through acquisitions or starting a brand-new offices. This count (most likely) increased by one last week when Microsoft offered to acquire (enterprise search software company) Fast Search and Transfer.

The current list of well-known IT companies with engineering presence in Trondheim to my knowledge are:
  • Google
  • Yahoo
  • Microsoft
  • SAP
  • Sun
  • Atmel
  • ARM
The natural follow up question: who is the next well-known IT company that establish themselves in Trondheim?

Saturday, January 12, 2008

The delicious absence of computer noise

I am not a big fan of noise from computers (which is typically caused by other fans..). Even if the noise can be close to avoided with with certain head phones or drowned out by other sources of sound I still hope computer noise is something that quickly becomes an artifact of the past.

The noise is a symptom
Computer noise caused by fans is a symptom of power inefficiency by spending a lot of energy producing heat rather than doing computations (of course some physical reasons for this). This is as I see it analog to old-fashioned light bulbs that used more energy to produce heat than light, fortunately light bulbs can be replaced with LED lamps.

Fixing the symptom (sort of)
In order to get a less noisy home office I drilled a hole in the floor between the office and my (cold) basement, put up a small shelf near the basement roof and moved my ubuntu box to the shelf with usb and monitor cables through the hole, and it certainly made a difference sound-wise.

Fixing the problem?
But energy-wise it has gotten worse since I am less likely to (manually) turn the box off and don't have any fancy time or usage-based power adjustments for it. So I believe my current home office solution is a only temporary patch, but uncertain what the real solution should be. Suggestions?

Sunday, January 6, 2008

Increase Automation of Test-Driven Development?

I believe Test-Driven Development can be improved by increased automation, some of the suggested thoughts could perhaps also be adapted to Behavioral-Driven Development (BDD).

Test-Driven Development (TDD) is a manual repeated cycle of writing and running tests, writing the least amount of code to make tests pass, and finally refactoring code (and tests) to make it shine. Writing tests gives the important "side effect" of simultaneously designing the API.

Automation of coding part?
The word automated is sometimes mentioned together with TDD, but that usually refers to automated unit tests (that needs to be manually written) or automated refactoring (that needs to be manually performed by the user e.g. using a refactoring tool/IDE).

Writing the code is done with a greedy approach, i.e. writing just enough to make tests pass, and the coding per TDD cycle is usually only a one-to-at-most-few short methods that is called by the new test, i.e. small increments of code. These small code increments could potentially be automatically induced using machine learning, e.g. using inductive logic programming, program synthesis or genetic programming. There are at least 2 problems with this 1) readability of induced code, 2) scalability. The readability part can be manually handled in the refactoring step of the TDD cycle, and wrt scalability of induction of TDD code increments I believe one can perhaps do smart (automated) things with mocks to prune the search space for the chosen machine learning algorithm.

Towards API Driven Design (ADD?)
One of the things that is hot in software testing research is development of tools that generates unit tests automatically based on code input, e.g. if you have a large chunk of (legacy) code with zero or low test coverage you can use such tools to get high (or even full) test coverage. In their simplest forms such tools just generate tests calling methods to be tested with various permutations of input (e.g. corner/extreme value inputs), this typically leads to enormous amounts of variable quality tests, and there are fortunately tools that are smarter and seems to promise higher quality tests, e.g. DSD-Crasher. I believe such tools can perhaps be used to automatically fill in missing test-cases in TDD, e.g. if you add one test with a set of input values, such tools can generate the corner-variants of the same test. This leads to a more API driven development, since the developer doesn't have to write the API many times (with various inputs), but gets support by the tool to fill in test cases.

Remarks related to recent blogosphere postings about code size
I agree that size is code's worst enemy, but believe it would be slightly better to deal with size if much of the coding and writing tests for it is offloaded to the computer so the coder can focus more on API driven development. I don't believe everybody should be afraid of a little typing if it is to improve readability of code, but they should spare their fingers when the computer is eager to fill in.

Friday, January 4, 2008

Dining Philosophers and Quarreling Kids

Concurrency in general and in particular making concurrent processes smoothly share resources are hard programming problems. The classic problem illustrating concurrency is the dining philosophers problem where the shared resources are forks. The problems the philosophers can get include resource starvation, deadlock and livelock. (Note: dining philosophers has a slight resemblence of the game of musical chairs)

The quarreling kids problem
A much less classic but way more realistic concurrency problem is the quarreling kids problem, i.e. when providing N resources (e.g. food or toys) to M kids (who might be either spoiled, tired or hungry) several situations can occur:
  1. N < M
    • Typical result: Quarreling kids since some kids doesn't get any resources
  2. N ≥ M and N mod M != 0
    • Typical result: Quarreling kids since resources are unevenly distributed
  3. N &ge M and N mod M == 0
    • Can go smoothly, but can lead to quarreling kids if:
      • the resources differ, e.g. in type, size, shape or color
      • the order/speed resources are distributed in
      • the resources doesn't match the recipient's expectations (stereotypical: the girl doesn't get the pink colored and the boy doesn't get the blue colored)
Solutions to the quarreling kids problem?
An obvious solution approach could be to let the kids select resources themselves, but that will typically make the kids that selects first happy and the rest less happy and start quarreling, and if the kids select resources at the same time that also typically leads to quarreling during selection process.
A second approach is to provide non-discrete resources that are of infinite divisible nature, but that has unfortunately practical lower boundaries.
A third approach is to provide personalized (heterogeneous) resources, so every kids gets what they anticipate, but this requires both detailed knowledge of each kids preference and is impractical due to either limited resource budget, limited resource availability or possibly other reasons (e.g. nutrition?).

So what might work?

A) Provide homogeneous resources (where N ≥ M and N mod M == 0) could work, this way the kids are likely to feel that they are fairly treated.

But what if there are fewer resources than kids (N < M)

B) Provide resources that supports and encourages communication and interaction, i.e. where sharing pays off (e.g. in a more or less continuous sport like soccer or a turn-based board game)

This sounds awfully politically correct, what is the point?

The point is that solving the quarreling kids problem most likely requires solutions that:
  1. Avoids resource sharing by having dedicated resources to each kid (e.g. a pair of skates each), like in A above, or
  2. Provides resources that are being competed for under a set of communicated and agreed-upon cooperative rules as in soccer, or waited for under as set of cooperative rules in a turn-based board game, like in B above. (Without cooperation quarreling about resources will occur)
From a programming perspective, the quarreling kids (processes) problem with dedicated resources don't have any sharing problems, and can entirely avoid complex synchronization mechanisms (e.g. locks and mutexes), communication between the kids (processes) are done using speech (messages). This approach is similar to message-based parallelism such as using (asyncronous) messages in MPI and Erlang or channels in Stackless Python.


But what is the computational analogy for solution 2?