Adia: Doing More With Much Less

As I mentioned earlier, I've been doing some Python programming in the past couple of days. I'm working on a project that for now I'll dub Adia (after the Sarah McLachlan song). Adia will be a Python web MVC framework that will allow you to do ARAD (Absurdly Rapid Application Development). Adia's vision is simple: Do as much as possible with the least possible effort. "Laziness is a virtue":http://www.zefhemel.com/archives/2004/10/08/the-importance-of-laziness.

When all is done, Adia should be a full blown MVC framework, probably quite like "Ruby on Rails":http://www.rubyonrails.org/, but hopefully even more productive than that. MVC, meaning Model, View, Controller is a very well-known pattern for application development. So far I've only done work on the Model part of Adia. The Model deals with your data model, your database: the players in your system and how they are related. Adia will allow you to very quickly declare this model in your code and create the object structure and methods to easily use it. That's not a really new idea, O/R (Object/Relational) mappers have done that for ages. The difference with Adia is that your Python code is the only place where you declare your model. You don't have to create a database schema, Adia will do it for you. It has the concept of DataProviders which are objects that deal with the data storage for you. Right now there's only a MySQLDataProvider, but a SQLServerDataProvider, or probably even a XMLDataProvider could be written. I'll just show how it works with a little code sample, but because Textile (the code formatter I, for whatever reason, use on my blog) messes up my code so I can't inline it. You can find the "example code here":http://www.zefhemel.com/upload/adiaexample.txt.

In order to run this piece of code you only need a MySQL database and the Adia library. It will automatically create the needed tables. Also, if you adapt the data model in your application and rerun it, Adia will adapt the database schema accordingly, without loss of data (most of the time). Unlike many other systems you can just use it right away, without a code generation step.

So, quite some work has been done on the Model side of the story. 1:1 relations are supported and so are 1:N relations between objects. I still have to implement N:M relations. I've also written unit tests for most of the code, to be sure that it keeps working when I change something. Things that I still have to figure out are querying the data. Right now you can only request all or a number of object of some type and sort them. There's a very ad-hoc style of filtering, but it has to be improved. I also still have to think about how to use joins, but I got some ideas for that, I'm sure I'll figure something out.

Once I finish the Model part of Adia, I'll start working on the Controller and View side. The Controller part is the part that does the actual work. It contains the main logic of your programme, sometimes called business logic. After the Controller has done its part it will display its results through a View. A View deals with the presentation. In Adia it will probably be a (simple?) template language.

The reason that I started Adia is something that I observed a couple of months ago. If you look at web applications you'll see a pattern: there are always some entities which are related to one another. You have to be able to add an entity, modify it, remove it and show a list of them. It's always the same. In the end, what a programmer should be able to do using Adia is the following: * Create a python file that contains the model declaration (as in the example code). * Run a script (supplied with Adia) on it. The script will automatically generate default controllers and views for listing, adding, modifying and deleting of entities; stuff that you nearly always need. * Run the application.

Of course the generated code will not be perfect, but it should save quite a lot of boring work. The framework should aid the programmer as much as it can.

Anyway, there's a lot of problems to figure out and a lot of programming to do. But I thought I'd just inform you of what I'm working on. If you want to have a look at the code so far, you can get it from my Subversion repository. You can access it using a "Subversion":http://subversion.tigris.org client like, for example, "TortoiseSVN":http://tortoisesvn.tigris.org/. The repository URL is: svn://zef.cc/adia. Using the SVN command line tools you can do a check-out using:

svn co svn://zef.cc/adia