Code-Generation Techniques for Java
Subject:   Code smell
Date:   2003-09-04 08:56:46
From:   anonymous2
Code generation is a code smell and a sign of lack of expessive power in the language.

Full Threads Oldest First

Showing messages 1 through 2 of 2.

  • Code smell
    2003-09-08 10:47:29  anonymous2 [View]

    Funny you should say that. Arguably one of the most expressive languages around, Common Lisp, relies heavily on code generators (compile time macros).

    I love code generators, macros, "wizards", etc. They let me express my applications requirements in a way much closer to their domain than what the assorted languages provide. I've been working with them for over 15 years.

    Plus, while many languages truly aren't very expressive for a particular domain, they are quite dominant. A code generator can enhance a lesser environment in a specific way allowing you to leverage both the community and legacy code already in the other language along with the expressability of the language for the code generator in the specific vertical you are dealing with.

    Code generators help leverage existing environments so that you don't have to give up higher level abstractions or throw out the baby with the bathwater by migrating to a more expressive system.

    The hard part is finding a good code generator that allows you not only create the code, but also recreate the code. That's the sign of a better environment as most systems are a one shot deal that don't adapt to change very well.
  • Jack Herrington photo Code smell
    2003-09-04 09:07:17  Jack Herrington | O'Reilly Author [View]

    The requirement to use CG to effectively implement EJBs does indicate a design smell.

    That's not the end of the story though. There are reasons why, for example, .NET coders are using CG. The .NET APIs are simpler, but they still want the platform independence that they get with CG. In addition they want the quality that CG brings to redundantly coded tiers, such as the database access tier of a web application.

    I'm not a 'CG everywhere' advocate. I believe in pragmatic use in appropriate areas. A database access layer is one of those areas. No matter how great your language you are still going to be hand coding accessors for each table and field. All of which is redundant work which could be better done by a generator.