A living thing

- Posted in Tech by - Permalink

I started making my own Appjet clone as well, though it is not public yet (it is on friend's server where I began squatting). Very quickly I got to the "reflexive", "eat you own dog food way". That is, to design the clone not for performance or "business value", but, more academically, so that as much as possible is done inside the platform itself and as low as possible is left for some sort of external support.

For imports to work (and for applications as well, since I tried to go the no-eval way and use import instead), the files must be stored on disk. This is the thing that AppJet itself cannot do, so this platform needs supports in this aspect.

But, over time, I came to the conclusion that. in fact, this is the only thing where external support is needed, every other thing, from innards of multiuser platform with virtualized storage space, to the IDE, can be written inside AppJet. So the files began getting smaller, the half-implemented features went away (YAGNI for the moment) and finally, I aimed at creating as small as possible bootstrap of a platform. Something very small but sort-of living and capable of evolving in itself.

First thing: file saving. I decided to go webservice way: I call a service (through wpost) and it saves the files for me. It should have no other responsibility. Here's the code.

#!/usr/bin/env ruby

require "cgi"
cgi = CGI.new
File.umask(0002)

cgi.params.each do |name, code|
  File.open("../apps/"+name, "wb") do |f| f.syswrite(code) end
end

cgi.out do "" end

Yes, in the future it will definitiely needs some improvements, like some sort of security, or anyone calls it to write files virtually anywhere (where the script has access, of course). Sources are in apps subdirectory, this file (fs.rb) and static web if it will be used later is in www subdirectory, in main directory I have the appjet jar.

And now for the living being, Here it is.

var info = {};
info[appjet.appName] = appjet._native.codeSection("server")[0].display;
wpost("http://foo.net/fs.rb", info);

It resides in apps subdirectory and is used as the main file for running appjet.jar.

Look at it. It's already living. Whenever you load a page, it keeps its own life - it writes its new copy over itself. It is not capable of more than keeping the "life", but it is good enough. This is the starting point. A few more lines, and it gains the ability to evolve. Anyway, this is phase 1.

PS.: For those who don't get it. This is not the standalone application. It replicates itself - it really writes over the file it resides in, even if it is with the same content. It's new file, and if you reload the page, this new file will serve the page. This is the minimal (very uncapable) Appjet platform.
PPS.: Yes, you can write eval(request.query) and get much smaller beast, but I don't want to use eval. It's a cheat (it's deus ex machina - without input it does not do anything in itself and stagnates, it's empty jar filled with eval's orders, but has no own behaviour; the above one does and it's what is wanted, plus the capability acquire new behaviour (which it lacks)). And eval has its own problems, I simply don't like it.
PPPS.: Feel free to clone it and lead it along, too. If you like.