Wednesday, October 19, 2005

Code generation wizards: Ruby on Rails vs. Microsoft (and dynamic programming languages)

Please excuse me in advance if this is not a fair comparison: the last time that I used Microsoft VisualStudio code generating wizards was about 8 years ago at Angel Studio where I wrote a 'network play' library for multi-user PC racing games. The generated code was so obtuse that no human being could really understand it (well, I tried). I ended up writing my own equivalent library using UDP (using the same API so we could build against either library).

Anyway, that gave me a feeling of bad aji (Japanese word for taste - used in playing Go and refers to good or bad shape of stones played - good aji or bad aji). Needless to say, VisualStudio's code generator generated code with bad aji!

Ruby on Rails is really three things: a code generating wizard, utility class libraries, and a runtime component. The RoR code generator produces easy-to-read Ruby code and .rhtml templates (look like JSPs except for embedded Ruby code rather than Java code). The generated code is so readable that it is a pleasure to modify as required.

Now to be fair, Ruby is a dynamic language that has great introspection capabilities (i.e., code can look at itself, modify itself, etc.) This makes all the difference in the quality of generated code. Dynamic languages like Ruby, Lisp/Scheme, Python, and Smalltalk will always win over languages like C++, Java, and C# in flexibility of generated code, ORM, etc., etc.

What I think is interesting is that there has never been a mainstream computer programming language that is dynamic! I believe that this is because dynamic languages are favored by the "very high end of the programmer food chain"; for example: software architects who write custom domain specific languages to bring domain experts and programmers closer together in the development process. While some computer science text books (like "Structure and Interpretation of Computer Programs", "On LISP", etc.) cover meta-level programming very well, there are way too many programmers who have not been exposed to higher level programming techniques. I think that someday, a dynamic language will become the "new C++", or the "new Java" - hopefully sooner than later.

No comments: