Search TheCodeArtist

AI : Artificial or Actual Intelligence

Here is a question for the programmer in you:

Q. How do you write a program that writes itself ?

NOTE: The following article is NOT about quines.

Now coming back to the question, let us think for a moment. do we really need a program that can write itself. Or to put it more precisely, In what scenario is a self-modifying piece of code better than one which is not?

The first obvious scenario that comes to mind is that : Catching Run-time Errors.
Currently there are two schools of thought on the whole run-time issue scene.
  • Run-Time errors are critical and must and should be identified & fixed.
  • There is no such thing as a Run-Time error.
    ( There are only Exceptions ;) )

      The first school of thought is very harsh on developer. It expects developers to foresee the program's future and code in such a manner so as to be able to handle ANY situation that may arise ( however rarely). This also encourages Test-Driven programming which is sloppy to say the least. With every test-cycle discovering a series of "bugs" (that occur once 1 say 10,000 iterations) & adding a series of "minor" patches or fixes for each. By the time the code is considered "ready", its hardly efficient any more. Often the patches outnumber the original code itself.[1] This goes to show that the "ready" code doesn't do its job efficiently, but also more importantly, no longer does it do what it was originally intended to. You don't take a F1 car and add a tanker-trailer to carry gasoline just in case it runs out. Proper design is a prerequisite and oft ignored phase in most development projects [2].

      In the second school of thought, we find die-hard fans and wannabe fan-boys of  languages like JAVA that allow a developer to get away with anything and everything, as long as he feels comfortable doing it the way it is done. A guy trained in this school of thought will firmly believe that-
      If a tree was going to fall, and you knew it would fall,
      then hey! its not a problem anymore. Its expected behavior!
      Rather than preventing the tree from falling,
      you gently step aside & wait for it to fall...
      ...and then proceed [3].

      try {
          tree = forest.tree;
          if (tree.falling() == 1) {
              throw new TreeFallingException("RUN!");
          console.printLine("All iz well");

      } catch (TreeFallingException e) {
          console.printLine("RUN! RUN! RUN!");

      } catch (Exception err) {
          console.printLine("No tree, But RUN! " + err.WhyToRun());

      } finally {

      As we see, neither approach is perfect and both have their disadvantages. 

      Enter A.I. ...
      Imagine a platform where you have infinite memory. Now add infinite processing power to your kitty. With these two in your pocket, you can write a program to do pretty much anything, right? So whats the catch you might ask.
      That IS THE catch? Your program has to be able to do EVERYTHING!

      More on this in a latter post.

      To wrap-up:
      Q. How do you write a program that writes itself ?
      ANS: Quite simply, You don't! ;-)

      Read part2 of this series AI: Heuristics

      [1] Each patch to the applied to the code is the evolving code itself. But developer intervenes individually.

      [2] Today's average developer, having been exposed to the horrors of coding a poor design, is in a position to understand the problems of not spending enough time in the design phase. But, Its often the tightly constrained project schedules and the uncertainty associated with new-technologies that mean that there is never enough time dedicated to the design-phase.

      [3] Each catch-block added to the code is the evolving code itself. Again here the developer intervenes.

      No comments :

      Post a Comment