Friday, July 18, 2008

meta programming a gene pool

I was having a walk, and suddenly, my light bulb flashed with a new revelation.
There is no escape from specialization (context specific optimization).

I always used to wonder why is that we humans can only function under very constrained limits, be it temperature, humidity, regular food / water consumption, radiation ....
there are animals and insects that have much better tolerances, but taking it to the extreme, a piece of stone per example, has even better tolerances. The price is obvious, it cannot 'do' much.
The light bulb flash was that there is no escape from specialization, we are really good, at least better than a stone in acting and actively 'being' (whatever that means) in our environment, so we got specialized to do really good living here, with the disadvantage of not being good at all living in 'other places', a stone can live in both places (here and mars per example), it is not specialized / optimized for life here ... but pays for it by having 'no life' :P (here or on mars).

If per example we were to be able to live on earth and under water, we would need additional mechanisms and organs to be able to do that, which would make us probably slower and less efficient both here and under water, same for temperature conditions, radiations ... to be able to live on mars AND on earth, we would probably need to be less efficient living in any of the places because we would be bloated with stuff we don't need in the place we're currently in.

TO better formulate it, the wider the range of constraints we want to be able to live in, the less we will be efficient living in a place with constraints spanning only a small range of the potentially livable range of constraints we support.

The light bulb also flashed because of how this applies to software development:
It seems to be an unsurmountable law, that the wish to write completely general reusable code is bound to fail, I already wrote about my thoughts on code materialization in a previous post, and it seems I am still thinking about this topic from time to time. so it seems its bloated, heavy, complex and general in one extreme and specialized, light, easy to use and fast, on the other.

The only way I see around this is meta programming, if designed and implemented nicely (like in the loki library per example) using policies per example to customize code at compile time, it could be a good way to go, it needs more work of course, because it means actually implementing all the potentially needed functionality, or at least a good part of it, or in the minimal case only the currently needed implementation, but then the design of the policy has to be well thought-out, since in the absence of different implementations, the design could turn out to be flawed and would need to be changed when new implementations come.
So again, this would be like a pool of potential functionality, and the nice thing is, the end compiled code would not be bloated, since only the used parts (genes) go into the final product (creature) .
The effort to do this is obviously not small, specially for the unexperienced, furthermore, although the end product might not be bloated, the source code, might become bloated and too complex if again, care is not taken.

Unfortunately, meta-programming, although pretty flexible in c++, is not flexible enough for my taste, but still better than in other languages, but more on that next time.

No comments: