Angel \”Java\” Lopez on Blog

August 29, 2008

The Six Faces of IT Complexity

Filed under: Software Architecture, Software Development — ajlopez @ 10:19 am

I received an email from Roger Sessions, announcing his most recent issue of the ObjectWatch Quarterly Newsletter. ObjectWatch Newsletter is now in its thirteenth year of publication. He has written seven books including Simple Architectures for Complex Enterprises and many articles. In each issue, Sessions comments about one topic. This time, the topic of the Issue #57 (August 2008) is “The Six Faces of IT Complexity”. You can download the PDF version from:

Issue #57 (August 2008)

He has been studying IT complexity for several years now. Sessions has concluded that the vast majority of IT complexity falls into six categories. According him, if you can control these six categories, you can dramatically reduce the complexity that is choking your IT projects and preventing them from delivering business value.

These are the six causes of IT complexity Session enumerates (I take description from his articles and posts):

  1. Decompositional Failures – that is, systems that have not been decomposed into small enough subsets.
  2. Recompositional Failures – that is, systems that have been decomposed into subsets that are too small and have not been recomposed appropriately.
  3. Partitioning Failures – that is, systems in which either data and/or functionality has been divided into subsets that do not represent true partitions.
  4. Synergistic Failures – that is, systems in which functionality and/or data placement does not pass the test for synergy.
  5. Boundary Failures – that is, systems in which the boundaries between subsets are weak.
  6. Removal Failures – occur when there is functionality in a system that is unnecessary.

Read the article to a more detailed discussion, with real examples.

I know Sessions’ work since his book: Software Fortresses (I commented the book in an Spanish post), where Sessions gave us a new way to think about Service-Oriented and Enterprise Architectures.

Sites to visit:

The whitepapers at:

(I have to read one comparing enterprise architecture methodologies, like Zachman Framework)

Newletters index at:

(there are issues dedicated to SOA, complexity, Software as a Service, Enterprise Architecture…)

and Sessions’ new blog:

Simple Architectures for Complex Enterprises

promoting and discussing his new book of the same title:

(at Amazon)

Angel “Java” Lopez

August 19, 2008

AjBasic: an open source Basic-like interpreter

Filed under: AjBasic, AjGenesis, Programming Languages — ajlopez @ 12:05 am

My code generation project AjGenesis uses a interpreted language to execute tasks and expand templates. The language was named AjBasic. It’s used in all the examples I wrote with AjGenesis (more info at AjGenesis posts). Years ago, I had separated the interpreter code from the mother project. This weekend, I was refactoring the code. The result is now published at:

In my opinion, Google Code is easy to manage. Contrary to SourceForge and CodePlex, they are using Subversion as code repository. I use the Tortoise SVN client to checking the changes. Google people are gentle: I can create many projects, until now: (it’s in good form, I guess) (it’s still in its infancy)

More info in previous posts:

AjLisp- a Lisp interpreter in .NET
AjTalk- a Smalltalk-like interpreter

The Solution

The solution AjBasicWithTests is composed by the projects:

AjBasic: It implements the compiler and tokenizer. The tokenizer separates the incoming text in tokens. The compiler makes abstract trees from such input.

AjInterpreter: A new project, not present in AjGenesis. It contains all the support for the abstract tree, its nodes, the environment for values, and an evaluator of programs. The management of .NET objects, and dynamic objects, are in this project, too. My intention is to continue to use this project to support other interpreted languages.

AjBasic.Console: A simple console to test the interpreter.

AjBasic.GUI: A simple (and ugly) WinForm to test the interpreter.

AjBasic.Test: Some test fixtures, using NUnit (there is another solution AjBasic that not includes the tests)

All the projects are written using Visual Basic .NET. The solution was compiled using Visual Studio 2005. The console and GUI project could be used as a base that explains how to use the interpreter from your own application.

There are many points to discuss about the implementation: they would deserve future posts. By now, let’s explore some of the main features of the project, at its current status. Then, I’ll write down some ideas to explore in future versions.

As I mentioned, the language was born to support code generation inside AjGenesis. I designed it to manage native .NET objects, as dynamic object. But, what is a dynamic object? Its an object that has no class, but that can be expanded with new properties (the nearest example I could think now, are the Javascript objects).

So, you can write code like this:

a.FirstName = Adam a.LastName = Doe a.Age = 800

You don’t have to declare the variable. You can create the object and add the property FirstName in one command (this automatic creation of object is not supported in AjGenesis, yet).

You can test the existence of a property:

if a.LastName then it has a LastName not nothing elseend if

If the variable a has no assigned value, or if it has no LastName property, the above condition is evaluated to false. You can test something like and no exception is raised. The result value would be a nothing, what is evaluated as a false in a condition.

The Tests

The solution was not developed using TDD (Test-driven development). Instead, I wrote the tests after the code, only to be sure the core functionality were well implemented, according to my expectations. I didn’t use descriptive names, but they were useful when I refactored the full solution:

You can try the language from the console AjBasic.Console:

and from the WinForm AjBasic.GUI

None of the above is the “ultimate app”, but they work… ;-)

Next Steps

There are many ideas flying near my remaining neuron, and I have to put order on them. Some points, for the record:

- Now the interpreter core is separated from compiler, I could write AjSharp, an interpreter with C# syntax. Then, it could be added to AjGenesis, to write templates in a language more palatable to die-hard C# programmers.

- Add support to dynamic classes and prototypes.

- Refactor the tests

- Write down a minimal manual, explaining the language and its features

- Extend the language to support delayed values and delayed evaluation

- The internal form of this interpreter could be rewritten in Java

- The option to write an AST related to DLR support doesn’t attract me, it could be a lot of work. But it could be interesting to learn more about .NET DLR.

- Use the language as the basis for programming distributed agents (an ambitious point, that deserves more evaluation).

As usual, I had fun written this software.

Angel “Java” Lopez

August 18, 2008

Top ten code-generation rules

Filed under: AjGenesis, Code Generation, Software Development — ajlopez @ 7:52 pm

Everyone can recognize me as a die-hard code-generation fan, with a twist: use a model as the starting point. I adopted the idea every week, practicing “dog fooding”, using my own code generation project AjGenesis. This week, I’m reading the now classic book “Code Generation in Action” , by Jack Herrington, edited by Manning. This book is a “must be read” to everyone interested in code generation. It’s a very interesting reading for developers, but also to managers: the author makes the case for use code generation, appealing to increasing quality and productivity, including agile teams.

In the first chapter, Herrington lists top ten rules I want to comment in this blog. The indented paragraphs are textual excerpts from the book (section 1.7), followed by my own comments:

Give the proper respect to hand-coding

You should both respect and loathe handwritten code. You should respect it because there are often special cases integrated into code that are overlooked with a cursory inspection. When replacing code you’ve written by hand, you need to make sure you have the special cases accounted for. You should loathe hand-code because engineering time is extremely valuable, and to waste it on repetitive tasks is nearly criminal. The goal of your generator should always be to optimize the organization’s most valuable assets—the creativity and enthusiasm of the engineering team.

Yes, the basis of code generation is to make easy to delegate the repetive tasks to the machine. We have to use tools that make easier our work: that’s the reason we are using compilers nowadays, instead of switching the bits directly in memory (or setting the relays in the old Eniac). Code generation rationale is not to destroy the handwritten code: its mission is to support it.

Handwrite the code first

You must fully understand your framework before generating code. Ideally, you should handwrite a significantly broad spectrum of code within the framework first and then use that code as the basis of the templates
for the generator.

Absolutely yes. Sometimes, new users of AjGenesis begin to use it directly from the examples. That is good, but it would be better to generate an example using the framework and technology they uses. If you know how to program using Struts/Hibernate, then, you can separate the variations from the essentials. At that point, you can begin to write the code generation artifacts (templates, tasks).

Control the source code

I can’t stress enough the importance of having a robust source-code control system. This is critical to a successful code-generation project. If your generator works directly on implementation files that contain some hand-written code, make sure you have a versioning system running that can protect your work.

Another path: if you generate the code from a model, check in only the model. The rest of the artifacts will come from code generation process. With the current technology, you can’t generate ALL the solution, but you can separate, with care, the generated part from the manual one.

Make a considered decision about the implementation language

The tools you use to build the generator do not have to be the same tools you use to write the application. The problem that the generator is trying to solve is completely different from the problem being solved by the application. For that reason, you should look at the generator as an independent project and pick your tools accordingly.

That is one of the reasons that supports my adoption of a new language (affectionately named AjBasic) for my code generation tool AjGenesis. I wanted a dynamic language under my control, to extend in any direction the code generation process requires. In one of my initial test, I tried PHP, but I prefer to have a dedicated language.

Integrate the generator into the development process

The generator is a tool to be used by engineers; thus, it should fit cleanly within their development process. If it is appropriate, it can integrate with the integrated development environment (IDE), or in the build process or check-in process.

Making the core of AjGenesis as a class library, it could be integrated to other tools. You can use from NAnt, for example. An IDE tool calling AjGenesis is a pending task.

Include warnings

Your generator should always place warnings around code that it generates so that people do not hand-tweak  the code. If they hand-tweak the code and rerun the generator, they will lose their revisions. In addition, your first response to people ignoring the warnings should be to help them and not to berate them. The fact that  they are using your tool is a big step. Learn why they needed to ignore the warnings and improve  the generator or the documentation. You are the emissary of your tool.

In AjGenesis, this issue is the concern of the templates the user writes. You can add any text you like: that’s the power of writting your own templates, you have the ownership of the generated code.

Make it friendly

Just because a generator is a tool for programmers doesn’t mean it gets to be rude. The generator should tell the engineer what it’s doing, and what files it has altered or created, and handle its errors with a reasonable amount of decorum. It may sound silly, but a tool that is difficult to use or that’s flaky will be ignored and your efforts will be wasted.

AjGenesis core is a dll, that can be invoked from any application. Years ago, I wrote tasks to use it from NAnt. Thanks to Jonathan Cisneros, we have now the AjGenesis Studio, since last year. I improved the original code at the beginning of 2008, adding AjGenesis Web Studio. The error handling must be improved, specially for new users of AjBasic.

Include documentation

Good documentation is a selling point for the generator. Your documentation should be thorough but not overwhelming, and should highlight the key points: what the generator does, how it is installed, how it is
run, and what files it affects.

Actually, is a point not very covered by AjGenesis. But in exchange, there are many blog posts explaning the process, ideas, and examples (AjGenesis posts) (AjGenesis posts in Spanish). Users of the tool are beginning to write too (read Carlos Marcelo Santos posts). There is an Spanish email list where the users can discuss the tool (Code Generation group). And in the Codeplex project page, there are examples for Java, .NET, and PHP, many of these using the same model (the litmus test).

Keep in mind that generation is a cultural issue

Educating your colleagues through documentation, seminars, and one-on-one meetings is critical to successfully deploying the generator. People are skeptical of new things, and a good programmer is twice as skeptical as the average person. You need to break through those concerns and doubts and emphasize that you designed the generator for their benefit.

I gave three to four speech by year, only dedicated to explain the tool and its potential. Additionaly, I explain the tool in every course I give (Java, .NET, PHP, or software development in general). But to be adopted in a company or project, a power user must became the champion of the tool. It’s not easy to raise the level of abstraction, write the model and its transformation, in the middle of the day to day work.

Maintain the generator

Unless the generator is just a temporary measure, it will need to be maintained long term. If the generator manages a large portion of code, treat it just as you would an engineer maintaining that same piece of code. Your budget should include dedicated time and money for maintaining and upgrading that resource.

AjGenesis is not the “things” to maintain. They are the templates and tasks you use in your work. If you adopt the tool to generate .NET applications, you have to change and improve the templates when new tech appears (LINQ, ASP.NET MVC….). And when you gain experience, you have to improve the model itself, if you discover new ways to represent the product lines your company are involved.

I could add some points more:

- The generated code generated must be the kind of code you are proud to write by yourself. The tools should not dictate the form and appearance of such code.

- The use of a model raise the level of abstraction. Such strategy separates the wheat from the chaff, put the technicalities in the place they deserve: the importance is in the model

Well, enough for now. As you can notice, code generation is one of the subject that passionate me. It’s not the silver bullet. But it is a bullet I want to have, just in case.

Angel “Java” Lopez

August 17, 2008

New Smalltalk Site:

Filed under: Programming Languages, Smalltalk, Software Development — ajlopez @ 2:37 pm

These days, this new site dedicated to Smalltalk was launched:

According to the site: is a non-profit organization which congregates Smalltalk programmers and enthusiastics. In 2008, we are going a step forward with this new website.
The big idea behind this website is to provide a source of information about Smalltalk in general.
The Smalltalk community has not good sources of information, or they’re all over the net, and sometimes it’s difficult to find them.

If you want to contribute, you’re welcome!

It’s an spinoff of the activity of the Spanish mailing list:

Some of the most popular articles published:

Interview with Luca Bruno, the creator of Smalltalk YX

Argentinian Smalltalk Congress- Smalltalks 2008

Seaside and Ruby on rails

It has sections:


Smalltalk Frequently Asked Questions

GemStone Frequently Asked Questions


Commercial Smalltalk Environments

Free Smalltalk Environments

Abbandon Smalltalk Environments

Frameworks, Platforms & Tools

and more: Tools, Resources, Community. It has links to Smalltalk Books, like:

Free Books 

Thanks to the work of Stéphane Ducasse, we have a huge collection of Free Smalltalk books online.
Download from

Creative Common Books

Our friend Diego Gomez Deck has written an excellent book in Spanish to start in Smalltalk. You can buy a hardcopy or you can download it under the creative common licence from
If you like it, we recommend to buy it, we are proud of this kind of projects.

The site is in its infancy, but I hope that with the help of the Smalltalk community, it will grow and become a reference to anyone interested in ST.

It’s supported by PHP. In my opinion, it’s a good sign: for years, Smalltalk community was reluctant to integrate or use other tools or technologies. In these days, with the plethora of languages, frameworks and platforms, we must abandon such isolated trend, and be more integrated.

Angel “Java” Lopez

August 15, 2008

Agiles 2008 in Argentina

Filed under: Agile Software Devevelopment, Software Development — ajlopez @ 10:37 am

A group of people and companies, agile practicioners and enthusiasts, are organizing (in agile way, what else?) the forthcoming:

First Latin-American Conference on Agile Development Methodologies


Among the international experts that have already confirmed their participation in Ágiles 2008 are Mary and Tom Poppendieck, Matt Gelbwaks and Tobias Mayer.

Tobias Mayer is an agile coach, that teach agile methodologies to most of us, here, in Buenos Aires and in other cities of Argentina. He is a kindly man, with great abilities to inspire and engage people in agile way. He could be considered the “godfather” of agile movement in this country… :-)

The organizers are calling for papers, ideas, proposals for activities:

Attending a conference without saying a word is too boring! We welcome your ideas to actively take part in Ágiles 2008. We have three kinds of activities in mind: Talks (the usual slideshow, people seated, Q & A at the end), Interactive Sessions (people standing, moving around, talking, doing) and Panels (subject open to discussion, format to be defined). But fear not: we are eager to receive your craziest idea! Just write us and we will try to find its place in the world.

Slots are 45 minutes long, but you may take more than one for a single activity.

Deadline is September 1st. You may leave us your proposal filling the form in

Ágiles 2008 Organization Team

For years, agile methodologies were gaining acceptance in my country, Argentina, and in Latin America. And now is the time to show to the rest of the industry what is all that agile movement.

Just do it (with a backlog… ;-)

Angel “Java” Lopez

August 14, 2008

Smalltalk 2008 in Argentina, Call for Papers

Filed under: Smalltalk, Software Development — ajlopez @ 9:39 am

Last year was the first installment of this argentinian Smalltalk conference. Now, a group is preparing the 2008 version. This is the site (Seaside based) and annoucement:

Smalltalks 2008 – 2nd Argentinian Smalltalk Conference


This year’s conference will take place on the 13th, 14th and 15th of November on the Universidad Abierta Interamericana, Av. Montes de Oca 745, Buenos Aires, Argentina. Like the 2007 conference, the registration will be free of charge.

This year we are willing to offer new activities. For this reason we open the calls for:

The conference will have two tracks, one on Scientific Research and other on Software Development for Industries.
Programming Contest
This year we will host a programming contest, encompassing all Smalltalks dialects.
Guest lectures by outstanding personalities.
Hands on
Tutorial sessions.

There is a call for papers (PDF version), about topics:


  • Aspects, Aspect Languages and Applications.
  • Ambient Intelligence, Ubiquitous / Pervasive Computing and Embedded Systems.
  • Compilation Technology, Optimization, Virtual Machines.
  • Educational Material.
  • Language Engineering, Extensions.
  • Model Driven Engineering / Development.
  • Meta-Modeling.
  • Programming in the Large, Design, Architectures and Components.
  • Programming Environments, Browsers, User Interfaces, UI Frameworks.
  • Reasoning About Code (Analyses, Refactoring, Type Inference, Metrics).
  • Reflection and Meta-programming.
  • Team management.
  • Testing, Extreme Programming / Practices.
  • Web Services, Internet Applications, Event-driven Programming.
  • Experience Reports.

Interesting, this year they are extending the scope of the research and educational track to include other dynamic languages, not only Smalltalk. They have an impressive Program Committee:

  • Federico Balaguer (LIFIA, Universidad Nacional de La Plata, Argentina)
  • Tulio Ballari (UTN, Buenos Aires, Argentina)
  • Alexandre Bergel (INRIA, Lille, France)
  • Gilad Bracha (Cadence Design Systems, USA)
  • Johan Brichau (Université Catholique de Louvain, Belgium)
  • Cecilia Challiol (LIFIA, Universidad Nacional de La Plata, Argentina)
  • Marcus Denker (SCG, University of Bern, Switzerland)
  • Fernando Dodino (UTN, Buenos Aires, Argentina)
  • Stéphane Ducasse (INRIA, Lille, France)
  • Alejandra Garrido (LIFIA, Universidad Nacional de La Plata, Argentina)
  • Tudor Girba (SCG, University of Bern, Switzerland)
  • Orla Greevy (SCG, University of Bern, Switzerland)
  • Julián Grigera (LIFIA, Universidad Nacional de La Plata, Argentina)
  • Andy Kellens (PROG, Vrije Universiteit Brussels, Belgium)
  • Kim Mens (Université Catholique de Louvain, Belgium)
  • Guillermo Adrián Molina (ESSI Projects, Spain)
  • Damien Pollet (INRIA, Lille, France)
  • David Röthlisberger (SCG, University of Bern, Switzerland)
  • Daniel Solmirano (UTN, Buenos Aires, Argentina)
  • Tom Van Cutsem (PROG, Vrije Universeit Brussels, Belgium)
  • Roel Wuyts (IMEC, Belgium)

Smalltalk is a technology that, in my opinion, failed to crossing the chasm. At late 80s, early 90s, the community was divided in many diverging dialects and commercial implementations. But it has impetus and loyalty members, as was proved last year, here, in Argentina, with the success of the last year conference. I hope Smalltalk could integrate with other technologies, like .NET and Java, in order to gain more momentum and acceptance. See, as an example, F# adoption in scientific community: the access to a popular class framework is a key feature in today mainstream. Insisting in one world, one language attitude is not an option, nowadays. I celebrate, then, the open of the above call for papers to other dynamic languages.

Angel “Java” Lopez

August 13, 2008

Closures in F#

Filed under: .NET, F#, Functional Programming — ajlopez @ 11:30 am

In my previous post about F#:

First steps in F#

I declared that there is no variable in the language, instead, we talk about identifiers. Why? Let’s explore the concept of closure, and how is used in F#.

According to Wikipedia article about closures in computer science:

a closure is a function that is evaluated in an environment containing one or more bound variables

But, what does this mean? To reveal its meaning, let’s assign a value to an identifier, using fsi.exe, the F# interactive interpreter:

MSR F# Interactive, (c) Microsoft Corporation, All Rights Reserved
F# Version, compiling for .NET Framework Version v2.0.50727

NOTE: See ‘fsi –help’ for flags
NOTE: Commands: #r <string>; reference (dynamically load) the given DLL.
NOTE: #I <string>; add the given search path for referenced DLLs.

NOTE: #use <string>; accept input from the given file.
NOTE: #load <string> …<string>;
NOTE: load the given file(s) as a compilation unit.
NOTE: #time;; toggle timing on/off.
NOTE: #types;; toggle display of types on/off.
NOTE: #quit;; exit.
NOTE: Visit the F# website at
NOTE: Bug reports to Enjoy!

> let x = 2;;

val x : int

Now, we have an identifier named x. We can show its value:

> x;;
val it : int = 2

A simple integer. Now, we cannot change its value: this identifier was carved in stone as an integer 2. Nothing in the human history could change its value. Is it true? Let’s define a function:

> let dup n = n * x;;

val dup : int -> int

This function dup takes an argument n and multiplies it by the value of identifier x. This identifier is a free “variable” in the function. During the evaluation of the function, x takes its value from the environment. Let’s try now:

> dup 3;;
val it : int = 6

The result was six, as expected. But now, let’s “change” the value of x:

> let x = 3;;

val x : int

> x;;
val it : int = 3

But this is the point to understand closures: this “x” is ANOTHER identifier, that it shadows the previous one. BUT, for the function dup, the identifier x is STILL the previous one. Let’s try again to invoke the function:

> dup 3;;
val it : int = 6

The dup still uses the original x!! That’s the closure in action. If we try:

> dup;;
val it : (int -> int) = <fun:clo@0>

Note the clo @ 0 : its the signature of the closure this function is using. It points to the original environment where the function was defined.

This feature implies that the behaviour of a function doesn’t change after its definition. Even the apparently “free variables” are bounded at definition time. All this is part of the solid fundations of functional programming, in general, and F#, in particular.

About closures and related concept, lambdas, these are the seminal papers:

The Original ‘Lambda Papers’ by Guy Steele and Gerald Sussman

You can learn a lot about Lisp, and closures/lambdas, visiting:

Closures + Lambda = The key to OOP in Lisp « Learning Lisp


I implemented some lambdas and closures, in my Lisp interpreter:

AjLisp: a Lisp interpreter in .NET

More C# related stuff about closures:

What’s In A Closure?
Fibonacci Numbers, Caching and Closures

Angel “Java” Lopez

August 12, 2008

Code Generation for NHibernate using AjGenesis

Filed under: .NET, AjGenesis, Code Generation, NHibernate — ajlopez @ 8:23 am

Last year, thanks to the initial idea from Omar del valle Rodriguez, and suggestions of Fabio Maulo, I wrote tasks and templates in my open source code generation tool, AjGenesis, to generate an example of a .NET application, using NHibernate. It shows the use of NHibernate from .NET, using .hbm mapping files (one per class). It generates four applications, two in Visual Basic .NET 2.x, and two in C# 2.0, using DAOs and DDD ideas

The example can be downloaded from the AjGenesis example page at Codeplex. The file is named

If you are new to AjGenesis, I wrote some introductory posts:

Code Generation with AjGenesis- A Hello
Application Generation using AjGenesis
Code Generation as a Service with AjGenesis
More post about AjGenesis…

The model

The base idea in AjGenesis is to use a free-defined model, where you can specify what you want to express for your domain at hands. In this example, I model entities, and from such model, AjGenesis generates complete applications, that you can modify and improve. The model is written in XML files, part of the model is at file Projects/AjOmar/Project.xml:

<Project> <Name>AjOmar</Name> <Description>Example AjOmar for (N)Hibernate</Description> <Prefix>AjOm</Prefix> <Domain>com.ajomar</Domain> <CompanyName>ajomar</CompanyName> <Model> <Entities> <Entity Source="Entities/Client.xml"/> <Entity Source="Entities/Company.xml"/> <Entity Source="Entities/User.xml"/> </Entities> </Model> </Project>

Omar initial project have Company and User , both inheriting from Client. In the database, there are three tables, and NHiberate’s magic is in charge of mapping that entity domain to the corresponding tables.

The User.xml describe the user, according to Omar specifications:

<Entity> <Name>User</Name> <Description>User Entity</Description> <SetName>Users</SetName> <Descriptor>User</Descriptor> <SetDescriptor>Users</SetDescriptor> <SqlTable>users</SqlTable> <Inherits>Client</Inherits> <Properties> <Property> <Name>FirstName</Name> <Type>Text</Type> <SqlType>varchar(200)</SqlType> </Property> <Property> <Name>LastName</Name> <Type>Text</Type> <SqlType>varchar(200)</SqlType> </Property> </Properties> </Entity>

The User entity inherits from Client, described as:

<Entity> <Name>Company</Name> <Description>Company Entity</Description> <SetName>Companies</SetName> <Descriptor>Company</Descriptor> <SetDescriptor>Companies</SetDescriptor> <SqlTable>companies</SqlTable> <Inherits>Client</Inherits> <Properties> <Property> <Name>CompanyName</Name> <Type>Text</Type> <SqlType>varchar(200)</SqlType> </Property> <Property> <Name>ContactName</Name> <Type>Text</Type> <SqlType>varchar(200)</SqlType> </Property> </Properties> </Entity>

There are technology elements, in separate files, as database to use, the language to generate, and other details. So, we can change the technology details without changing the above abstract model. An example of a technology file is Projects/AjOmar/Technologies/VbNet2Nh.xml:

<Technology> <Programming> <Dialect>VbNet2Nh</Dialect> </Programming> <Database> <Dialect>MsSql</Dialect> <Name>AjOmar</Name> <Username>sa</Username> <Prefix>ajom_</Prefix> <Host>(local)</Host> </Database> <NHibernate> <Dialect>NHibernate.Dialect.MsSql2000Dialect</Dialect> </NHibernate> </Technology>

You can change this file to your convenience. Following Fabio Maulo suggestion, there is one .hbm per entity. Using AjGenesis templates and tasks, this is an example of such mapping file, Build/AjOmar/VbNet2Nh/Src/AjOmar.Data/Company.hbm.xml:

<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="AjOmar.Entities" namespace="AjOmar.Entities" > <joined-subclass name="Company" table="ajom_companies" extends="Client"> <key column="Id" /> <property name="CompanyName" type="String"/> <property name="ContactName" type="String"/> </joined-subclass> </hibernate-mapping>

The applications

The example generate complete applications, with class library projects and web site to use as presentation layer. The code generation process is invoked from command line, using this four commands from AjOmar folder:

GenerateProject AjOmar VbNet2Nh
GenerateProject AjOmar CSharp2Nh
GenerateProject AjOmar VbNet2DDDNh
GenerateProject AjOmar CSharp2DDDNh

You must add the AjGenesis bin folder to your path. The first two commands generate ASP.NET 2.x applications, in VB.NET and C#, using DAOs that invoke NHibernate. Additionaly, they generate the DDL scripts to create the MS SQL Server database. The last two are similar, but using some ideas from Domain-Driven Design. This is tipical output of the tool:

Under the build folder the applications are generated:

This is the C# application loaded in Visual Studio:

The Web client project implements a navigational model to browse and update entities.

Note: the model is not fixed. You can define the model as you want. This is an example only to show AjGenesis capabilities. But you can write your own model, transformations and templates. AjGenesis is not limited to one predefined model, and you can generate all the text artifacts you want, if you write the corresponding tasks and templates. Sky is the limit!

Generating DDD

There are solutions using DDD ideas. They have class library projects:

  • AjNHibernate: containing the classes to call NHibernate: configuration, session factory, and session management.
  • AjOmar.Domain: Entities, Services, Repositories, a la Evans. There is no Value Objet or Aggregate The services are called Managers: the name service is used in Application project.
  • AjOmar.Application: the tier that coordiname the calls to Domain, from presentation.

There is a web application, AjOmar.WebClient, with pages to list, view and update entities:

Next steps

The idea is to expand this example to generate code that uses Hibernate, Java, EJB3, MySql, and/or Struts2. I have some examples written, but I have to update them to the ideas presented by Omar and Fabio. Code generation for other technologies is the acid test for AjGenesis: from the same model, generate different applications with many technologies. Suggestions, comments, welcome!

Angel “Java” Lopez

August 11, 2008

First steps in F#

Filed under: .NET, F#, Functional Programming, Programming Languages — ajlopez @ 12:22 pm

The F# language has been under development in Microsoft Research. Its main creator is Don Syme. You can visit the F# web site:

A comment from that site:

Combining the efficiency, scripting, strong typing and productivity of ML with the stability, libraries, cross-language working and tools of .NET.

F# is a programming language that provides the much sought-after combination of type safety, performance and scripting, with all the advantages of running on a high-quality, well-supported modern runtime system.

The last published version, up today, is:

F# realease announcement

Installing F#

You can download a .msi file, or a .zip one. The .msi is an installer program, that install F# compiler, and F# for Visual Studio. I installed the version in my machine. This is one of the screen from my past year installation:



The last step could take many minutes. It install the support of F# inside Visual Studio. You can use VS or, alternative, a F# command line compiler and interpreter. The F# programs can be launched from Mono, then you can write F# code under Linux.

At the end of install, a folder is created c:\Program Files\FSharp-<version> (it has a .sh file to install the tools in Mono).

There is a new program menu:

The fsi interpreter

We can use an interactive tool, that is the F# interpreter at bin\fsi.exe:

C:\Program Files\FSharp-\bin>fsi MSR F# Interactive, (c) Microsoft Corporation, All Rights Reserved F# Version, compiling for .NET Framework Version v2.0.50727 NOTE: NOTE: See 'fsi --help' for flags NOTE: NOTE: Commands: #r <string>;; reference (dynamically load) the given DLL. NOTE: #I <string>;; add the given search path for referenced DLLs. NOTE: #use <string>;; accept input from the given file. NOTE: #load <string> ...<string>;; NOTE: load the given file(s) as a compilation unit. NOTE: #time;; toggle timing on/off. NOTE: #types;; toggle display of types on/off. NOTE: #quit;; exit. NOTE: NOTE: Visit the F# website at NOTE: Bug reports to Enjoy!

Using let

Let’s enter

> let x = 10;;

We get at output:

val x : int

The ;; makes the program to compile and execute the entered commands. In this command, x is an identifier, that has an integer value. F# is a typed language. We didn’t define the type of the identifier x: it was inferred automatically from the value we put in it. Let’s note that is an identifier, not a variable. Once an identifier is set, we can’t change its value. That is a distinctive feature of functional programming in general. I’ll explore that behavior in future posts.

Now, let’s enter

> x;;

(the > was added by the program, it’s the fsi’s prompt) We get

val it : int = 10

The fsi program prints the expression and its type. it is the name that it uses when we don’t speficy a target identifier.

Defining functions

Using the same let, we can define functions:

>  let dup x = x * 2;;
val dup : int -> int

For F#, values and functions are the same. A function is a first class citizen in the F# language, and it can be manipulated as any other value.

The second line above shows that dup is a function that receives an integer and returns another integer. The identifier dup now points to that function. It is its value.

We can apply the function entering:

> dup 10;;
val it : int = 20

A function is a value, we can pass a function as a parameter:

> let apply f x = f (f x);;
val apply : (‘a -> ‘a) -> ‘a -> ‘a

The result is something more cryptic. The term ‘a refers to a undefined type. It could be an integer, or an string, or something else. But if we give an integer as second parameter to apply, the first one MUST BE a function that takes an integer and returns another integer. Don Syme, the creator of F#, was involved in the definition and implementation of generics in .NET 2.x. One could think he implemented that features to create the F# language… ;-)

If we entered

> apply dup 2;;

then we get

val it : int = 8

that is the same that

> dup (dup 2);;


For those who are not familiar with functional programming, the concept of a function as a first class value, citizen with the same rights and duties of a value, could sound something strange. But if you can grasp the base of this approach, you’ll appreciate the advantages of this path (the appearance of lambda and delegates in mainstream .NET is an example of such adoption). If you have seen a Lisp or other functional implementation, all this sounds as a deja vu for you.

The interesting part of F# is that not only supports the functional programming paradigm but also interacts with the rest of the .NET framework. Then, F# is not an “academic” language, only related to itself, but was adopted in many projects. Although I was dealing with the command line interpreter in this post, we can use the Visual Studio, leveraging debugging, projects, and editors.

Enjoy F#!

Angel “Java” Lopez

The Shocking Blue Green Theme Blog at


Get every new post delivered to your Inbox.

Join 56 other followers