Angel \”Java\” Lopez on Blog

November 18, 2011

AjGenesis: Basis of its Implementation

Filed under: AjGenesis, Code Generation, Ruby — ajlopez @ 12:07 pm

I dedicated a lot of time to the development of AjGenesis, my open source code generation engine (from a free model). It’s time to write down what I consider the key points of its implementation, the parts that makes AjGenesis what it is.

First: the use of a free model on memory, that it’s managed like a common object in a programming language. You don’t need to traverse XML path or something else. You can visit and manipulated one or mode models  like any other dynamic object. I didn’t adopt a type model or a model with a schema: the model is free, you can put on each model what you want to have in it. The model is deserialized from XML or from text files, or it could be injected for your program: AjGenesis can be hosted as a library in your own application.

Second: the use of a dynamic, simple language, to execute simple or complex task, with access to rich class library. In AjGenesis, I use AjBasic, a interpreter that can access .NET. It can use, create and change dynamic objects, like the models.

Third: the use of templates, with expressions and commands (i.e. loops) written using the dynamic language.

(Some early alternatives were: use XML with schemas for models, and XSLT for transformations. I rejected them because I felt they had shortcomings that could affect the clear development of the system).

See:
Building an Application with AjGenesis
Code Generation with AjGenesis in a Real Project
Models for Code Generation in AjGenesis
AjBasic: An Open Source Basic-alike Interpreter
Generating Code Hello World with AjGenesis

Having these three pillars, I used AjGenesis for years, in different technologies, languages and framework (from Java to .NET, from JSP to ASP.NET to ASP.NET MVC, from PHP4 to PHP5 to .NET4 to .NET5, DDL for MySql, MS SQL Server database, and one user is generating code for Ruby and Rails!). Notably, I’m generating text artifacts for technologies that didn’t exist at the beginning of the project, with minimal changes to AjGenesis itself. And it can run in Linux and Mac OSX thanks to the Mono project (see Running AjGenesis Using Mono and Ubuntu).

Ideas to implement: the ability of inject the source of the model (you could write your own serializer); you could choose the dynamic language to use (I plan to add AjSharp as dynamic language for tasks and templates).

But if I have the three key points I enumerated above, I could implement AjGenesis. Then, as a proof of concept, I started to implement the same ideas under Ruby: dynamic objects, that can be loaded from YAML (or XML, or other formats), the use of ruby for task programming, and its template using ERB (or, maybe, other template engines).

You can check my progress at: https://github.com/ajlopez/AjGenesisRb

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

1 Comment »

  1. [...] It’s really interesting to see how simple ideas can be reimplemented in dynamic languages. Next steps: more samples, ruby gem, node package, and web site implementing code generation as a service (ASP.NET implementation commented in my old post). (see AjGenesis: Basis of Its Implementation). [...]

    Pingback by AjGenesis Code Generation in .NET, Javascript and Ruby, All the Gates are Open « Angel ”Java” Lopez on Blog — May 29, 2012 @ 4:33 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Theme: Shocking Blue Green. Get a free blog at WordPress.com

Follow

Get every new post delivered to your Inbox.

Join 67 other followers

%d bloggers like this: