Software Secret Weapons™  
Build Variety Of Consumer Products At Low Cost Using Generative Programming posted by Pavel Simakov on 2007-05-07 16:13:08 under Code Generation
view comments
 


The Problem

I was reading this great PhD thesis The Extensible Graphical Game Generator (EGGG) {1} and it came to me! I suddenly understood the whole other dimension of the code generation and the generative programming. I wrote code generators before and I did so relying purely on my intuition. Now, I discovered a systematic process for building code generators. And I learned how to apply generative programming concepts to various other activities, not only to software engineering.

Don't get me wrong. It's not like this was my first day on the job. I read books about the code generation. I read the Generative Programming {2} bible back and forth many times. I love the book: the topics, the language, the authors - everything. I myself wrote the code generators that generate the source code of various kinds. I also wrote the code generators that create the representations other then the source-code, but images, HTML, IDL, state machines, etc. Over the years, I even took a deeper look at the functional programming. I looked at how functional programming affects the code generation approaches or even fully changes the meaning of the code generation as in Lisp macros. With all of this considered, there was still something new I saw in this Thesis.

At the same time you might ask: Who cares about the code generation? Why these code generators are important? The code generators are important (and exciting to work with) because they create something, and because they are human-like! The code generator has a small part of your thought and your creativity embedded into it. There are many examples of the commercial code generators that create beautiful things, including fully working concrete software applications. After you give your code generator to others, it works by itself and creates new things all the time. And it does it for free!

If it works for free, we definitely need more of it. How can one take advantage of the code generation on the regular basis? How to use the power of the code generation to build the consumer products, not the abstract concepts that only benefit the software engineers? How to recognize the opportunity to use code generation?

The Solution

I noticed that both, the Generative Programming book and the Thesis do not actually talk about the code generation in the first half. What do the authors spend half of the time talking about, if they do not actually talk about the code generation? Both books have "code generation" in the title, but they do not talk about the main subject for the first half! What can be more important? What do they talk about?

They talk about the feature models! The most important precondition to any successful code generator is a feature model! Before you can actually create a code generator you must have a feature model of the problem area, for which you are about to generate something. Not just the class model, ER model, state model, or domain model, but the feature model - model that specifically captures the constant and the variable parts of the problem area.

I read about feature modeling in the Generative Programming book. For all this time I thought the feature modeling was not that important in itself. To me, it was just a convenient formalism, a language used to consistently present the rest of the material in the book. But I was wrong. There is so much cool stuff in the book that the importance of the feature modeling can be easily missed. At the same time, the feature modeling is the most important part of the book, while the rest of the book is just the "implementation details".

Just look at this list of the high-profile web applications:

How do you think these applications work? All of these applications are the flexible web applications driven by the feature models. They have different internal implementations, but they all have the feature models in the backbone. Don't necessarily think that you must use the adaptive object models, dynamic languages, object database, extreme programming, or some other weird thing to make a successful application like that. All these things will definitely help, but they are not enough. The success starts and heavily relies upon the feature models. All those other things remain an implementation detail.

Where can one find these feature models? How to convert a feature model into a dynamically-configurable flexible web application? How to build these flexible software applications at low cost?

The Example

The Generative Programming book has three detailed practical examples of applying feature models to real problems. But these examples are focused on creating flexible software abstractions, templates, classes and libraries – all being highly abstract things. Considerable further imagination, software engineering experience and hands-on development work are required to convert these flexible software abstractions into flexible consumer products. There is no practical example (Krzysztof, please correct me here, if this is wrong!) on taking a feature model and using it to build a complete consumer software application.

If you have heard of domain specific languages, but were not quite sure where they come from and what to do with them – not surprisingly they come from feature models. The EGGG Thesis, I mentioned earlier, is that perfect practical example of applying feature modeling and DSL to create a variety of concrete consumer products – games. For example:

The EGGG tackles and solves many challenges in converting abstract concepts into consumer products starting purely with the feature model. It's written better than many books you can find in the bookstore; it's concise and complete at the same time. Let me describe how it unfolds.

  • The feature model covering a large number of different games is created first. The author calls it "a designer’s taxonomy of games", but it is indeed a feature model.
  • The internal domain specific language (internal DSL) is defined. The DSL operates in terms of the feature model. The purpose of this domain specific language is to configure various aspects of the features from the model and to control game play and the game construction process.
  • The instance of a specific game configuration is created using a domain specific language. Many examples are given including configuration DSL for Poker, Tic Tac Toe, Rock Paper Scissors, etc.
  • The code generator is then created to convert the instance of the game specification DSL into the source code files. As a result, the code generator produces a complete set of the source code files that can be immediately compiled to create a fully working game.
  • As an added bonus, a generator produces the self-documented game rules, interactive graphical user interface, and even a good-enough game strategy implementation that allows game designer to immediately play the game with a skilled computer opponent.

Well it is not quite that simple, but you got the point. EGGG is an excellent tutorial for someone interested in applying feature models to building dynamically-configurable flexible software application. Try it, it works.

Final Word

What is a feature model anyways? After learning the object-oriented programming and the UML is it worth learning yet another methodology? Is the feature model any different from the class model? While similar and complimentary, feature modeling is quite different from other modeling techniques used in software engineering. Let me recite the Generative Programming book from page 83, last paragraph:
  • Feature modeling is the activity of modeling the common and the variable properties of concepts and their interdependencies and organizing them into a coherent model.
The feature modeling is not about modeling the medium-grained software implementation details as UML is. Not all things are classes and objects; there are things that are even more important then classes and objects. The feature modeling is not only about the software engineering. The feature modeling is about modeling the reality around us.

The feature modeling might as well be the most important modeling technique for you if your goal is to build flexible consumer products. The feature modeling is a general technique for anyone who wants to model the variability in a specific consumer product. It is a tool for business visionaries, creative artists, book authors, fashion designers, marketing geniuses, movie producers, or anyone else who needs creativity! Feature modeling is a tool for creative design!

It gets even better... If a creative design for a consumer product is formalized into a feature model one can use the computers to generate the infinite number of the different product instances. The feature modeling is a road to unlimited creativity and mass-customization at low cost.

References

Comment (1)

  • Comment by Website Builder — March 11, 2008 @ 4:44 pm

    Interesting read.


Leave a comment


  Copyright © 2004-2007 by Pavel Simakov SourceForge.net Logo