Re: Automatic Code Generation

Discussion in 'Python' started by Rasmus Fogh, Oct 6, 2003.

  1. Rasmus Fogh

    Rasmus Fogh Guest

    On Sun, 5 Oct 2003, Ian Bicking wrote:

    > On Sun, 2003-10-05 at 11:52, Rasmus Fogh wrote:
    > > Someone raised the question of automatic code generation a few weeks back.
    > >
    > > And yes, we (CCPN) are using automatic Python code generation in a major
    > > way. Basically we are making data models in UML, and using automatic code
    > > generation to make Python APIs, XML I/O etc. (more below). We can be found
    > > at http://www.ccpn.ac.uk/index.html
    > >
    > > As a general point, automtic code generation would seem like a good idea
    > > in special cases where:
    > >
    > > - a lot of repetitive code can be derived completely from a more compact
    > > or problem-oriented description.
    > > - The problem is large
    > > - You need to keep doing new pieces of code and/or maintain several sets
    > > of synchronized files on top of an evolving problem description
    > > - You avoid hand-modifying the code, either because you can get 100%
    > > automatic generation, or you can 'park' the handcoded modifications where
    > > they are read into the automatic generation process.

    >
    > I would disagree that code generation is a good solution to these, or
    > nearly any case. Specifically in Python, code generation isn't
    > necessary because you can build objects and classes dynamically. So if
    > you have a non-Python representation of the object or class, you can
    > write code to dynamically create that class, instead of writing code
    > that writes code.
    >


    Building the code dynamically would certainly be an alternative, so code
    generation is not necessary (i.e. unavoidable). In our case I think it
    makes sense, though. The code to create your classes and the logic to
    control it would presumably be much the same in either case, it is just a
    question whether to execute the generated code or write it to a file. It
    would seem to be faster to generate the code once and for all rather than
    each time you need the code. You may get more flexibility by generating
    the code as you need it, but seeing CCPN is making data models and data
    exchange libraries that should be the same for all users, we specifically
    do not want the individual programs to have that flexibility. Finally, it
    is probably easier for users to read and debug generated code than a model
    + generating script.

    To each his own,

    Rasmus

    > One possible exception to this may be templating languages, which
    > typically compile more directly to Python code, with the full generality
    > that entails. But even in this circumstance I think there are
    > considerable arguments against compilation, as the compilation can be
    > difficult to manage and errors are not as well reported. (But
    > unfortunately the alternative is an interpreted template, which has its
    > own issues)
    >
    > Analogously I can imagine other situations where logic needs to be
    > embedded into the description, though even in those situations code
    > generation may not be necessary.
    >
    > --
    > Ian Bicking | | http://blog.ianbicking.org
    >
    >
    >
    Rasmus Fogh, Oct 6, 2003
    #1
    1. Advertising

  2. Rasmus Fogh

    John J. Lee Guest

    Rasmus Fogh <> writes:

    > On Sun, 5 Oct 2003, Ian Bicking wrote:

    [...]
    > > > As a general point, automtic code generation would seem like a good idea
    > > > in special cases where:

    [...snip code generation advantages...]
    > > I would disagree that code generation is a good solution to these, or
    > > nearly any case. Specifically in Python, code generation isn't
    > > necessary because you can build objects and classes dynamically. So if

    [...]
    > Building the code dynamically would certainly be an alternative, so code
    > generation is not necessary (i.e. unavoidable). In our case I think it

    [...]

    Ian was suggesting not generating code *at all*. Just use Python's
    'ordinary' dynamic features. Paul Prescod posted some messages about
    this a few years ago (claiming "code generaztion is always a hack, but
    sometimes a necessary one", more or less), but I can't find the one I
    was thinking of (maybe it was an article, not a USENET post?). Here's
    one from the other side of the argument, from Alex Martelli:

    http://tinyurl.com/pxbr

    <http://groups.google.com/groups?q=group:comp.lang.python+%22code+generation%22+hack&hl=en&lr=&ie=UTF-8&selm=Zij_8.108176%24vm5.3725547%40news2.tin.it&rnum=2>


    John
    John J. Lee, Oct 6, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rasmus Fogh

    Automatic Code Generation

    Rasmus Fogh, Oct 5, 2003, in forum: Python
    Replies:
    0
    Views:
    320
    Rasmus Fogh
    Oct 5, 2003
  2. JoshforRefugee

    help with automatic code generation

    JoshforRefugee, Jan 31, 2007, in forum: C++
    Replies:
    0
    Views:
    400
    JoshforRefugee
    Jan 31, 2007
  3. JoshforRefugee

    help with automatic code generation

    JoshforRefugee, Jan 31, 2007, in forum: C++
    Replies:
    6
    Views:
    309
    JoshforRefugee
    Feb 1, 2007
  4. fpga_designe

    Automatic VHDL generation from C code

    fpga_designe, May 15, 2009, in forum: VHDL
    Replies:
    1
    Views:
    680
    fpga_designe
    May 15, 2009
  5. John W. Long

    HTML Generation (Next Generation CGI)

    John W. Long, Nov 22, 2003, in forum: Ruby
    Replies:
    4
    Views:
    319
    John W. Long
    Nov 24, 2003
Loading...

Share This Page