Meta-programming: automate software creation

The secret to success in the business software field is to automate the software creation process. If you do so, you gain a big advantage as you have to program or customize less software than your competition. I have identified three types of meta-programming. They all have their advantages and disadvantages.

1) Higher subject abstraction

You can create software that sells “cars” that has, for instance, a table with “occasions”, containing columns for “brand” and “color”.

You can also make software that sells “products”, that have “properties”. Both could be tables, and there could be a foreign key between them. The properties table could contain the columns for “product” (a reference), “name”, “value” and “required”.

I see this pattern when I look at software that is not specialized for a niche. It is clear that generic web shop software like WooCommerce does not know what the web shop owner is going to sell and thus has no other choice than to generalize. It often also allows you to add “custom” fields, often with cryptic and generated names.

Is this bad? Yes and no. Yes, as this creates complex data structures that do not perform and are hard to understand. No, as you may have to do less software development. So in fact you pay your more effective software development by lower software performance and worse structured data.

2) Higher code abstraction

Programming language constructs like reflections, “generics” in C#, “method_missing” in Ruby, “magic methods” in PHP and “proxy classes” in Java enable programmers to write less code that is more generic or reusable.

Is this bad? Yes and no. Yes, when your code starts to get variables named “instance” and “class” it becomes hard to grasp what it is actually doing. No, as it may actually lead to less and more powerful code. In fact you are paying your more effective software development by less readable and harder to modify software.

The real problem is that this approach becomes really ugly when the software is aging. The code will start to contain lots of exceptions implemented as if/else statements in the wrong abstraction level.

3) Generating the code

When you generate code you can still add exceptions afterwards. Also you can still use specific, readable code and simple data structures for the domain you are automating. This actually gives you the best of both worlds: a ‘natural’ abstraction level for data and code, but still lower software development costs. Yes, it may give code duplication at first, but as soon as the code ages, you will see that the exceptions you will have to add actually justify this.

Another advantage of this method is that it can be applied in any programming language as no special language constructs are required.

Further reading

While you are at it, why not check out Rails 3 Generators: Scaffolding and MVC and Scaffolding for Rails Newbs? I’m sure you’ll love it!