Slashdot Mirror


Code Generation in Action

Simon P. Chappell writes "Now, I enjoy a good technical book more than the next geek, but it's been quite a while since one left me quite so excited with the possibilities that it presented. Code Generation in Action is beyond interesting, it is a masterful tome on its subject matter, written by one who is obviously an experienced practicioner in his craft." If "code generation" isn't a familiar term to you, this enthusiastic overview on devx.com is a concise introduction to what code generation is about, though it makes no pretense of ambivalence about its importance as a programming tool. Read on for the rest of Chappell's review. Code Generation in Action author Jack Herrington pages 342 (10 page index) publisher Manning rating 9 reviewer Simon P. Chappell ISBN 1930110979 summary A masterful tome.

Overview Code Generation in Action, CGiA to its friends, is presented in two parts. The first part is four chapters, and covers a code generation case-study, the basic principles of code generation, including the different types of code generation strategies together with reasons why you would or would not use each strategy. The book's chosen toolset for building generators is presented next, and then some walk-through examples of building simple generators wraps up the first part.

The second part is a kind of a cross between a cookbook and a list of engineering solutions. There are nine chapters with the breadth of solutions covered being quite impressive, covering the gamut of generation of user interfaces, documentation, unit tests and data access code. Each chapter presents a couple of solutions within its topic area, often for different technologies within that topic. For example, the user interface chapter covers the generation of Java ServerPages, Swing dialog boxes and then Microsoft MFC dialog boxes. No favouritism here!

What's To Like There's a lot to like with this book. The writing is very clear and of good prose. I found the introduction to be very compelling, and I felt completely drawn in by the opening case-study. The four chapters of part one are a concise case for code generation, and would be very useful information to help persuade co-workers and management of the positive risk/benefit ratio with trying code-generation on a live project.

It would be impossible to try enough of any solution from part two in a time-frame short enough to make this review useful, but in the solutions that match my areas of knowledge, I found myself admiring Herrington's straight-forward and pragmatic approach.

What's To Consider There are two aspects of this book that I want to flag. One of these aspects, some will love and others will hate, and that is the choice of generator language for CGiA. The author has chosen to use Ruby as his working language. This is an interesting choice. Ruby is certainly a language that is inspiring a lot of admiration these days (in fact, it's hard to get Dave Thomas to stop talking about it :-), but with the majority of the code-generation examples being for Java-related technologies, I wonder why Java was not selected instead.

I also found myself wondering about the lack of discussion of how to integrate these Ruby tools into a typical Java build process. Many developers I know use ant to bring automation and consistency to their builds, yet the book doesn't mention this. (JRuby anyone?) Certainly something to consider for the second edition or future code-generation authors.

Summary

This is a masterful tome that inspires and delights, although the two issues raised above did cost it a perfect score of ten.

Table Of Contents
  1. Code generation fundamentals
    1. Overview
    2. Code generation basics
    3. Code generation tools
    4. Building simple generators
  2. Code generation solutions
    1. Generating user interfaces
    2. Generating documentation
    3. Generating unit tests
    4. Embedding SQL with generators
    5. Handling data
    6. Creating database access generators
    7. Generating web services layers
    8. Generating business logic
    9. More generator ideas

You can purchase Code Generation in Action from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

29 of 262 comments (clear)

  1. I belong to the Code Generation... by burgburgburg · · Score: 4, Funny
    And I can take it or leave it if I please.

    Richard Hell and Codeoids

  2. good stuff by DreadSpoon · · Score: 4, Interesting

    Code generation is definitely something programmers of large/complex projects should look into. There's a lot of different forms of it, and I'd be surprised if people haven't used on form or another already.

    My personal favorite trick at the moment is describing interfaces in XML, and getting multi-language bindings and docs out of it with a few XSLT scripts. Techniques like that makes script language bindings easy as pie (as do other systems like Swig).

    1. Re:good stuff by SpamJunkie · · Score: 5, Funny

      Code generation is definitely something programmers of large/complex projects should look into. There's a lot of different forms of it, and I'd be surprised if people haven't used one form or another already.

      Ya, I've done some code generation myself. I used a text editor and my brain. How does everyone else do it?

      I thought about using my wang instead of my brain but he just types screenfulls of the V word.

    2. Re:good stuff by kisrael · · Score: 4, Funny

      Ya, I've done some code generation myself. I used a text editor and my brain. How does everyone else do it?

      I thought about using my wang instead of my brain but he just types screenfulls of the V word.


      " V", huh? I feel sorry for your romantic partners. My wang can type " VFR"...
      " VFR4" if I'm really excited.

      --
      SO YOU'RE GOING TO DIE: The Comic for Dealing with Death
  3. Something missing? Like a definition? by Trigun · · Score: 5, Insightful

    Code generation is a time-saving technique that helps engineers do better, more creative, and useful work by reducing redundant hand-coding. In this world of increasingly code-intensive frameworks, the value of replacing laborious hand-coding with code generation is acute and, thus, its popularity is increasing.

    Why not put a little bit about code generation in the review. Even a little blurb like "It builds the mundane portions of coding" would have helped out a bit.

    1. Re:Something missing? Like a definition? by register_ax · · Score: 5, Insightful
      I concur.

      [rant]
      What the hell is up with these book reviews? I equate book reviews with SCO. All I see is a large body of reviewers making unsubstantiated claims to a book that tickled their fancy in a personal sort of way. They say basically, "this book tickled a nerve, but I will not say what I already know that led to that nerve being in place already." Of course it turns out then to be some haphazard therapy session where the reviewer begins to delve into themselves while completely ignoring their audience!!!

      OK, I know /. may not be extremely high with the English majors, but how about we don't post such things submitted by such arrogant posters? (is it possible?) I don't claim myself as being a master of prose, but you won't see me trying to do something I knowingly can't.

      One more point, the reviews most commonly given are little more then amazonian reviews. They rave about how great something is, realize that only constitutes of 2 senteces, and proceed with immediately filling in the blanks with worthless prose to create content.

      And lastly, I don't receive book reviews on my main page because of their vapid nature. This means that /. is losing on my potential business. I would love to see them prosper, but they have to create something that is interesting. Slashdot is all about bringing the obscure to the masses, but I hardly see that through their book reviews. What is the freakin deal with OReilly's cookbooks? Are there any really, really bad OReilly books at all? We all have hordes of them or wish we had complete collections. We know what a cookbook is and they don't really differ that much between subject.

      I am trying to prove a point here, that reputation and common sense through the title allow for little differentiation between your preconceived notions about the book and what the book is realistically about. I want books to come to the forefront from the dirges, such as the recent classic The Elegant Universe: Superstrings, Hidden Dimensions, and the Quest for the Ultimate Theory (Feb 2000) by Brian Greene, or "been around the block more then once" Men of Mathematics (June 1937) by Eric Temple Bell. My point being, either book is known to those in the "know," but is rare to be known by budding scientists (high school students) and younger folk. I won't let this branch off into a rant in poor public schooling and child upbringing. I only want to see objective viewpoints of why the book may be helpful to me, not why it made you change your perspective on life! FSCK!
      [/rant]

      Thank you for being patient.

  4. Code generation == metaprogramming by Anonymous Coward · · Score: 5, Insightful

    And Lisp has been doing it for years, as has, to a lesser extent, C++ (and Ada) templates. And the good thing about Lisp metaprogramming is that it is in the one language - lisp.

    Having 1 language generating another - Ruby and Java - is the recipe for confusion and complexity.

    1. Re:Code generation == metaprogramming by Anonymous+Brave+Guy · · Score: 4, Funny

      Yeah, honestly, these upstart newbies yaccing on about code generation as if it were some sort of new idea. Lex think for a minute and bison other books before we get carried away, shall we?

      (And "active code generation" used to be called "high-level languages" and used fairly often by stronger programmers who didn't like cut-and-paste. Maybe that's not buzzwordy enough any more, though.)

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    2. Re:Code generation == metaprogramming by Usquebaugh · · Score: 3, Insightful

      It's a shame that the humor of your post will be lost on the majority of /. readers.

  5. We didn't know we were doing anything special... by Fnkmaster · · Score: 4, Insightful
    But we built a very large code generation system as part of my old company's electronic trading system. It used the JavaDoc system and a custom JavaDoc parser we built to generate oodles and oodles of very repetitive code from the base business objects, such as XML parsers and translaters and the like. It was a big time saver, undoubtedly. The big problems we had were versioning and its interaction with our build system, and more importantly, the fact that the code generator itself becomes very complex to read, such that only one or two developers are capable of making changes to it.


    My rule of thumb is if I find myself writing code that bores me silly and thinking "a frigging monkey could be taught to code this piece", I will strongly consider writing a program to write the program for me. Be warned about the maintenance and readability issues though in larger development projects where there are a lot of mediocre programmers around. You can always assign those mediocre programmers to hack on monkey-easy code, but you can't get them to hack on a code generator, so carefully consider the nature of the development organization you are dealing with, and the tradeoff between available "high-value" time and resources vs. "low-value" (i.e. monkey coder) time and resources. This perspective has been brought to you by my pointy-haired side.

  6. Code generation and Pragmatic programmer by gbvb · · Score: 4, Informative

    if you ever read the "Pragmatic Programmer" book about software developer practices, it mentions that they used code generation for many things. Code generation definitely helps when you have many similar but not same implementation.. But, in Java or any other object oriented languages, inheritence can be used to avoid similar looking code (which is what code generation would do).
    But, even here, I think the UI pages, or template based generators definitely help. There was a tool by DevelopMentor which used to generate code for ATL. It was based on templates..

  7. NOT about compiler code generators by GillBates0 · · Score: 5, Interesting
    I've been doing R&D work with compilers (Ada/C(++)/Java(bytecode generators)) for quite a while now, and the first thought that occurred to me was that this is an article/book about the code generator pass in compilers.

    But apparently, it is not. I, for one, wasn't too happy seeing the term "code generator" applied to superficial software that generates HTML/user level code for standard dialog boxes etc. HTML isn't code in the first place, anyway.

    Maybe I'm being too fussy about this, but a code generator, traditionally has always meant a part of the compiler back-end which actually translates intermediate code to machine-level instructions. VB and other UI tools generate stubs for the most part...well maybe they are code generators, but I'm just not too happy about the choice of terms.

    --
    An Indian-American Hindu committed to non-violent thought/speech/action alarmed by the global explosion of radical Islam
    1. Re:NOT about compiler code generators by naarok · · Score: 3, Insightful

      A code generator is a compiler. It takes some source and produces an implementation of the source using a more primitive language.

      I wrote a code generator for EJBs. The template that was passed in was very much the source as a very high level language. The output was Java code.

      I wrote a Pascal compiler for a virutal machine. The source taken in was Pascal, the output was VM code.

      The two were very similar except the gramar for the code generator was much simpler so I didn't need a complex lexical parser.

      Don't dismiss code generation as some trick. It is a very valid approach to simplifying repetitive steps and is as much a compiler as what you are thinking of.

    2. Re:NOT about compiler code generators by kmo · · Score: 4, Insightful

      Maybe I'm being too fussy about this, but a code generator, traditionally has always meant a part of the compiler back-end which actually translates intermediate code to machine-level instructions.
      I think you're being too fussy. Anything that generates code can reasonably be called a code generator. You are just most familiar with the backends of compilers.

      Code generation can allow a developer to compensate for missing abstractions in the underlying language or architecture. For example, it's almost trivial to write generator for a Java type-safe enum class with a couple of pages of java tied to a Velocity template for an enum. You just have to be sure that your build process regenerates the class if your input changes. The input could be something as simple as
      color {red, green, blue}

      It's then easy to add features to your enum infrastructure that aren't in Bloch's class and have them show up in all the project enums (like correct serialization and localization).

      The GUI builders that spit out code fragments are just the tip of the iceberg when it comes to code generators. Imagine a utility that could generate the plumbing to make EJB or RMI methods directly accessable from a Windows DCOM client, without it knowing or caring that it's talking to Java on the other end.

      Or automatically generating classes for Customer, Order, and Product from an existing database table, and seamlessly loading, caching and saving their instance data without the application knowing or caring that it is persistent.

      Automating this sort of tedious programming is what code generation is all about.

  8. Ruby not Java by Colonel+Panic · · Score: 4, Informative

    The author has chosen to use Ruby as his working language. This is an interesting choice. Ruby is certainly a language that is inspiring a lot of admiration these days..., but with the majority of the code-generation examples being for Java-related technologies, I wonder why Java was not selected instead.

    I think the author makes it pretty clear why he chose Ruby instead of Java. Essentially, in order to parse text (which is one of the primary functions in code generators) you would have to write 2 to 3X more code in Java than you would in Ruby. Java is not an optimal text parsing language - first off you have to find a regex engine for it. That leaves you with choosing one of the scripting languages: Ruby, Perl or Python.

    Here's what the author says about the cons of using Java for code generation (page 41):

    * Java is not ideal for text parsing. (I would agree)
    * Strong typing is not ideal for text processing application (again, I would tend to agree, strong typing only gets in your way)
    * The implementation overhead is large for small generators. (you'll be writing a lot more java code than you would in Ruby to get the same thing done)

    Overall, I'm finding it to be a great book, and the use of Ruby for implementing the examples is a plus as far as I'm concerned.

    As far as integrating Ruby into the build process goes, I recall hearing something about a project that uses Ruby to drive Ant.

  9. Code generators are just compilers... by Dr.+Zowie · · Score: 3, Interesting
    The obvious case is a generator that writes "C" code -- after all, "C" was intended as just a metalanguage like Gnu's RTL, but for the earlier BCMP compiler. It's arguable that generated C code is more true to the spirit of the language than is hand-coded C code.

    I became a code-generation convert about two years ago when I first encountered Perl Data Language -- what made PDL development feasible was a code generator by Lukka, Glazebrook, and Soeller: their generator ("PP") writes all the loops and conditionals that do vectorized processing of large arrays.

    Of course, PP has its limitations -- the age old complaint of engineers is that they will eventually outgrow any code generation framework -- but it's simple enough to augment the generation language or, in extreme cases, to sidestep the parts of the functionality that you're not using.

  10. Code generation a necessity by russotto · · Score: 3, Insightful

    I work on a large Java project where we use entity EJBs. Code generation isn't an _option_ here, it's a necessity. We have hundreds of tables (over 500) and each of them has an EJB. Writing out the infrastructure for each and every one by hand would be a huge and boring waste of time. I think the necessity for code generation actually points to a problem with design of EJB itself, but that we're pretty much stuck with.

    1. Re:Code generation a necessity by BigGerman · · Score: 4, Insightful

      there is a _huge_ design problem with EJB.
      To me it manifests itself in the ass-first design:
      if I work with a framework, the typical scenario for OOP would be: framework provides interface, I implement it with my classes so they can play in the framework.
      With EJBs, it is another way around: you define an interface and the container/framework creates classes and implements your interface for you!
      Code generaton became so popular with J2EE for this very reason: there is _always_ a step where you need to produce a lot of redundant EJB artifacts so you might as well automate it.

  11. Swings and roundabouts by Rogerborg · · Score: 4, Insightful

    I worked at a telco where we generated C code on the fly from high level Structured Definition Language for the main call control processing.

    It was a great idea... in theory. In theory, it was impossible for the implementation to get out of sync with the detailed design (the SDL). In theory, there's no difference between theory and practice, but in practice there is. Some of the features that we had to add simply couldn't be modelled in SDL, plus there were performance issues, and it produced ugly source.

    It was used for fifteen years (yeah, pre-ANSI), but it eventually collapsed under the weight of all of the hacks that were required to work around the limitations. We eventually had to admit that the behaviour of the complete source (generated plus all the stuff around it) was now so different from that defined by the SDL that it was no longer worth putting up with the limitations of the SDL.

    In the end, we just took a snapshot of the generated code and set developers free to actually fix it rather than hack around it. At that point, there were only a few people left who even knew SDL, so there were very few tears shed. The rest of us cheered, and the product got significantly cleaner as we refactored the bejeesus out of all the generated C and removed the hacks.

    I'd recommend giving code generation a try, but don't be ruled by it. Once the product is mature, if the code generation is limiting you, then don't be afraid to drop it and fix the lower level generated code.

    --
    If you were blocking sigs, you wouldn't have to read this.
  12. Re:Software Engineering is not just there yet by johnnyb · · Score: 4, Informative

    Actually, it's very much there. It's not a _replacement_ for development, but there are many parts of coding which is benefitted by code generation. I often write tools to write code for me. Once I had to write a color-picker in HTML (VERY repetitive code), so I wrote a code-generator in Emacs Lisp and it saved me several hours. Several implementations of this concept exist:

    * Templating (see Alexandrescu's book on Modern C++ design)

    * Macros for those in the Scheme/Lisp world (these are GREAT and AWESOME)

    * Compile-time programming (only available in LISP as far as I'm aware through the eval-when construct)

    * Custom program-generators

    And then there's the related concept of partial evaluation that, while excellent, has received very little attention by the commercial sector.

    Now, many code-generation facilities could be done better with good libraries, but this isn't universally the case. Delphi is probably the best at putting in libraries/properties what others put in code generators, and their software is much easier and better because of it.

    Macros and compile-time programming are two of the best ways to do this, but Scheme and LISP are the only ones that do this reasonably.

  13. Re:Am I FUD? by querencia · · Score: 3, Insightful

    Code Generation is for people who don't understand or are too lazy for abstraction

    The article that timothy suggested as background reading (here) points out that code generation is most useful when you're forced to use a framework that requires lots of simple-minded "scaffolding-style" code. EJB is the prime example.

    In other words, I agree with you --- if code generation is useful, it's probably because the infrastructure you're using was poorly designed. But that doesn't mean you don't have to use it. Managers who have no idea what J2EE is require you to use J2EE. So you use code generation.

  14. I thought J2EE was supposed to simplify things by KenSeymour · · Score: 3, Insightful

    A quote from the Sun web site:

    J2EE technology and its component based model simplifies enterprise development and deployment.

    But now I hear that we need code generation to keep up with all the mundane tasks made necessary by the use of EJBs.
    So we build a code generator and we have to maintain that.

    This is on top of all the J2EE design patterns you are supposed to do because the world would come to an end if you just accessed a database table using JDBC directly.

    Once in a while someone should look at the assertion that it would be harder to maintain a lot of imbedded JDBC code in your application than it would be maintain the 5 or so classes you need for each business object in order to maintain architectural purity.

    --
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Albert Einstein
  15. Actually, a very interesting topic by SWPadnos · · Score: 4, Informative

    For those who are saying that the term "Code Generator" isn't applicable - it is. Consider a C++ compiler. It may generate asm code, which then gets converted into machine code.

    (generic) C++ -> (specific) asm -> executable bits

    (obviuosly, the C/C++ compiler doesn't need to generate asm, but it's still code generation if it does)

    Code generators just take this a level higher, so the code "life cycle" looks like this:

    (generic) Diagram / CG description -> (specific implementation) C++ -> (specific machine) asm -> machine code.

    Code generators have a great potential for easing coding and documentation. Just like GCC has many backends to generate code for different processor architectures, the code compilers can have different backends to make source code in different languages (C, C++, Fortran, whatever). Even better, you can run a different translator and get documentation out of the "source" - in HTML, DocBook, XML, or any other format you want.

    There are tools to let you make UML diagrams (Google for "Executable UML" for great goodness), and generate real-time C code for an application, a C++ app simulator that runs on a PC, and documentation for the system, all from the same diagram. The tools are expensive (like $15k-$30k), but for large projects, they can be a great savings.

    I saw a program called BridgePoint (from Project Technologies), which was able to generate embedded, real-time code that was as efficient (more in some areas, less in others, but it averaged out the same) as hand-optimized code done by expert programmers. It all depends on how goo dyour translator is (and this program lets you write your own).

    Some books on the subject:
    "Executable UML: A Foundation for Model-Driven Architecture", by Stephen J. Mellor and Marc J. Balcer
    "Executable UML: The Models are the Code", by Leon Starr
    "Real-Time UML: Developing Efficient Objects for Embedded Systems, Second Edition", by Bruce Powel Douglass

    --
    - The Sigless Wonder
  16. Re:Am I FUD? by smagoun · · Score: 4, Insightful
    You're assuming you run the generator once, and that's it. That's what many people do, and it's wrong. The generator should be part of the build cycle. If you want to change the generated code snippet, change the generator!

    While I agree with you in principle - that better abstraction is usually the way to go - that's not always possible in the real world. For example, sometimes you have to produce an API for someone else, or hook up to their API. In those cases, better abstraction isn't always an option. Sometimes your boss says "you're using EJB" and you're stuck with it. In those cases a generator can be a big help.

    The cool thing about integrating a generator into your build is that you get the benefits of abstraction without many of the drawbacks. The generator becomes your abstraction, so you can make modifications in one place. Sure, using a generator requires a little more thought than cut-n-paste. So does proper abstraction. The two aren't all that different, and both approaches have their place.

  17. Re:Yea. Ok. Perl do it, too. by Raffaello · · Score: 4, Informative

    Yes, of course you can do this in lisp.

    The point your parent poster was making, is that a lisp program has the full power of the language available at macro expansion time, just prior to compilation. This means you can redefine the syntax of the language at will to create any language you like on top of lisp. Lisp macros should not be confused with c-style macros, which are merely token substitutions, not redefinitions of language grammar.

    You only have this in perl in a very crude and hackish sense. You have to write your own parser; you have to write your own code generator; you have to run every piece of code through your home-brew parser/code-generator before you send it to the perl interpreter. Debugging? Heaven help you if any of:
    1. Your code written in your new-language-built-on-perl has errors
    2. Your parser has errors.
    3. Your code generator has errors.

    In Lisp, the macro facilities come for free, are part of the standard (so macros are portable). Vendors are responsible for correctness, so debugging is a simple matter of using the built in functions macroexpand and macroexpand-1.

    Saying that Perl has the same sort of code generation capabilities as Lisp is rather like saying that, since all languages are Turing equivalent, assembly language has the same macro capabilities as lisp.

    The power of a language comes from its expressiveness, the things it lets you do easily without having to resort the 21st century equivalents of a turing machine. With Perl, you only get this level of expressiveness by using convoluted, error prone, home-brew substitutes for real macros.

  18. Code Generation incorporated in .NET by spideyct · · Score: 3, Interesting

    The .NET Framework has great built-in support for code generation, called the CodeDOM model. It is the mechanism used by all of the Visual Studio IDE wizards.

    What is great is how they abstracted out the target language. Once you build a CodeDOM graph in your generator, you can pass it to any language generator (C#, VB.NET, J#, write your own) to create the result.

  19. Code generation and macros by game · · Score: 3, Interesting

    Generating code from database schemas and the like can be acceptable in my book. However, generating code just because it is repetitive and clunky is *not*.

    In theory, good programmers never write repetitive code: they factor out functions, classes. Still, there are things that cannot be factored out easily, patterns of code that just do not map well into functions or cannot be abstracted away in whatever way the language provides.

    Some languages are better at abstraction than others, but not many provides the ability to generate code (think of syntactic abstraction). This is where Lisp macros shine. They can hide ugliness I'm forced to do in the name of performance, define new control structures, ...

    Think of the number times you were forced to go out of your way to solve a problem because while it was more correct or efficient it was less easy on the eyes. True macros would have helped. Well, divide that number by 10, the rest was probably your fault :-).

    A language needing a code generator for reasons above lacks power and for this lack a thousand small tools will appear all trying to plug some holes.

  20. Not FUD, but not correct, either. by tmoertel · · Score: 4, Insightful
    mcc wrote:
    Code Generation is for people who don't understand or are too lazy for abstraction ...
    Baloney.

    Code generation is a practical, efficient tool for solving many problems where OO-style abstraction need not enter the picture. One such class of problems is building interfaces and glue code from external specifications.

    A few years ago, I wrote a simple code generator that reads the SQL DDL for a large database and generates an object-based interface to the database. Client coders could then use the object-based interface to access the database. The advantages of this approach proved to be numerous:

    • Single, authoritative reference specification. The object interface was always in sync with the reference, which for this project was the database schema.
    • Richer compile-time error detection. The projection of the schema into the object interface was fully available to the type system so that many kinds of client errors could be caught at compile time, not run time.
    • Reduced opportunity for errors between subsystem boundaries. Because the object-based interface was generated by machine from the actual database -- and not derived from some programmer's understanding of the database -- there were fewer opportunities for impedance mismatch across the boundaries of the application code and the database. (Studies of errors in complex projects have shown that errors are more common between subsystem boundaries, and so this benefit is important.)
    mcc further states:
    But I cannot think of any case in an object-oriented language where it would be both less work and more maintainable to write a code generator than to just abstract away the parts that would be auto-generated.
    If you can't think of any such cases, it's because you're thinking too small. Look at the bigger picture. For starters:
    • When the number of variables affecting the desired code characteristics is large enough to make hand-coding (at any level of abstraction) impractical. E.g., FFTW: "FFTW uses a code generator to produce highly-optimized routines for computing small transforms."
    • When your code must conform to an external reference specification that changes rapidly enough to make hand coding (at any level of abstraction) impractical. (See my example above.)
    • When the requirement for correctness is so stringent as to make hand-coding methods impractical, mandating code generation from a formal specification.
    • When you must target an output language whose native abstraction capabilities are too crude to capture directly the degree of abstraction that is merited. Believe it or not, most popular OO languages fall into this category for many commonly occuring problems. Hence the popularity of design patterns. (Compare, e.g., with the abstraction capabilities of modern functional programming languages like Haskell and O'Caml.)
    Make no mistake about it, code generation is a practical, effective tool that every programmer should understand. To dismiss it out of hand is a costly mistake.
  21. Re:Software Engineering is not just there yet by amightywind · · Score: 3, Insightful

    Amen to LISP/Scheme macros. Java and C++ have reimplemented so many other Lisp ideas you wonder why attention never turned to the preprocessor. After 15+ years of C++/Java and OO we would still all be better off programming in Lisp.

    --
    an ill wind that blows no good