Automated code generation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Max M

    Automated code generation

    Yesterday there was an article on Slashdot:
    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...


    It is about automatic code generation.

    I got interrested in the subject, did a web search, and it seems kind of
    powerfull.

    My main interrest is web development in Zope/CMF/Plone, where there is a
    lot of repeated code in the products. So automated code generation seems
    like a natural fit.

    But every time I think of a use case, I immediately think of a way to do
    it with encapsulation instead.

    Does anybody have any experience using Python and automated code
    generation where it actually make sense?

    Or os it useless in a language as dynamic as Python?


    regards max M

  • Cameron Laird

    #2
    Re: Automated code generation

    In article <3f58ba15$0$972 67$edfadb0f@dre ad12.news.tele. dk>,
    Max M <maxm@mxm.dk> wrote:[color=blue]
    >Yesterday there was an article on Slashdot:
    >http://books.slashdot.org/article.pl...id=126&tid=156
    >
    >It is about automatic code generation.[/color]

    Comment

    • John Roth

      #3
      Re: Automated code generation


      "Max M" <maxm@mxm.dk> wrote in message
      news:3f58ba15$0 $97267$edfadb0f @dread12.news.t ele.dk...[color=blue]
      > Yesterday there was an article on Slashdot:
      >[/color]
      http://books.slashdot.org/article.pl...id=126&tid=156[color=blue]
      >
      > It is about automatic code generation.
      >
      > I got interrested in the subject, did a web search, and it seems kind of
      > powerfull.
      >
      > My main interrest is web development in Zope/CMF/Plone, where there is a
      > lot of repeated code in the products. So automated code generation seems
      > like a natural fit.
      >
      > But every time I think of a use case, I immediately think of a way to do
      > it with encapsulation instead.
      >
      > Does anybody have any experience using Python and automated code
      > generation where it actually make sense?
      >
      > Or os it useless in a language as dynamic as Python?[/color]

      There are a few places where automated code generation makes sense,
      but these are mostly trivial time savers. For example, the propery()
      function
      could be extended to automatically generate trivial getters, setters and
      deleters, saving some coding and making things clearer in the majority
      of cases.

      John Roth[color=blue]
      >
      >
      > regards max M
      >[/color]


      Comment

      • Eddie Corns

        #4
        Re: Automated code generation

        Max M <maxm@mxm.dk> writes:
        [color=blue]
        >Yesterday there was an article on Slashdot:
        >http://books.slashdot.org/article.pl...id=126&tid=156[/color]
        [color=blue]
        >It is about automatic code generation.[/color]
        [color=blue]
        >I got interrested in the subject, did a web search, and it seems kind of
        >powerfull.[/color]
        [color=blue]
        >My main interrest is web development in Zope/CMF/Plone, where there is a
        >lot of repeated code in the products. So automated code generation seems
        >like a natural fit.[/color]
        [color=blue]
        >But every time I think of a use case, I immediately think of a way to do
        >it with encapsulation instead.[/color]
        [color=blue]
        >Does anybody have any experience using Python and automated code
        >generation where it actually make sense?[/color]
        [color=blue]
        >Or os it useless in a language as dynamic as Python?[/color]

        The target language doesn't have to be the same as the implementation
        language. A short while ago I created a small code generation program that
        created snippets of C code which were woven into a hand optimised C program.
        The result was an extremely fast program (which it needed to be) which still
        seemed to have some capabilities of the HLL I used to create it (Scheme in
        this case). I wouldn't even have attempted doing the analysis of the user
        input in C but it was so trivial in Scheme I was able to add lots of extras.
        It would have been a reasonable project in Python too. I did in fact use
        Python as a front end to hide what was happening.

        However I would suspect there would be a lot less scope for generating Python
        code. Its dynamic and reflexive nature make it unnecessary.

        Eddie

        Comment

        • achrist@easystreet.com

          #5
          Re: Automated code generation

          Cameron Laird wrote:[color=blue]
          >[color=green]
          > >[/color]
          >
          > Yes, it's largely useless in a language as dynamic as Python.[/color]


          Isn't SWIG a code generator?


          Al

          Comment

          • Cameron Laird

            #6
            Re: Automated code generation

            In article <3F58D910.197C3 C85@easystreet. com>, <achrist@easyst reet.com> wrote:[color=blue]
            >Cameron Laird wrote:[color=green]
            >>[color=darkred]
            >> >[/color]
            >>
            >> Yes, it's largely useless in a language as dynamic as Python.[/color]
            >
            >
            >Isn't SWIG a code generator?
            >
            >
            >Al[/color]

            I'm regarding SWIG as not about writing in Python; it's
            about writing in a combination of Python and C (or C++,
            or Fortran, or ...).
            --

            Cameron Laird <Cameron@Lairds .com>
            Business: http://www.Phaseit.net
            Personal: http://phaseit.net/claird/home.html

            Comment

            • Eugene Pervago

              #7
              Re: Automated code generation

              achrist@easystr eet.com wrote in message news:<3F58D910. 197C3C85@easyst reet.com>...[color=blue]
              > Cameron Laird wrote:[color=green]
              > > Yes, it's largely useless in a language as dynamic as Python.[/color]
              >
              > Isn't SWIG a code generator?[/color]

              Most of what it generates is C++, Python is special in that there is
              some optional wrapper code generated to use Python 2.2's features like
              properties. No code, for example, is generated for Ruby (or Perl
              AFAIK).

              Eugene Pervago
              Kahakai (Python scripted window manager) http://kahakai.sf.net/

              Comment

              • Simon Burton

                #8
                Re: Automated code generation


                My classes often have a __str__/__repr__ that generates a
                bit of python code that when eval'd will reproduce (a clone of) the instance.

                Simon.

                On Fri, 05 Sep 2003 18:30:19 +0200, Max M wrote:

                ....[color=blue]
                > Does anybody have any experience using Python and automated code
                > generation where it actually make sense?
                >
                > Or os it useless in a language as dynamic as Python?
                >
                >
                > regards max M[/color]

                Comment

                • darrell

                  #9
                  Re: Automated code generation

                  I write tools for testing embedded systems.
                  They parse the .h files and doc files to associate names with hex
                  values... This produces meg's of .py files which then support writing
                  tools and test scripts.

                  Everything from structure layout to:

                  EMERGENCY_STOP_ CMD=0x1234567L
                  ....
                  SOME_STRUCT=(["f1","f2"," f3"],">fI10s")
                  ....
                  ERROR_100="Some thig bad"


                  Does this qualify as code generation?

                  When the project wants to change something like how we "log".
                  Python is used to parse the entire source tree making changes.
                  Not Python code generation but it's more complicated than
                  search/replace. And could be applied to a Python code base as well

                  Is this code generation?

                  --Darrell


                  Max M wrote:[color=blue]
                  > Yesterday there was an article on Slashdot:
                  > http://books.slashdot.org/article.pl...id=126&tid=156
                  >
                  >
                  > It is about automatic code generation.
                  >
                  > I got interrested in the subject, did a web search, and it seems kind of
                  > powerfull.
                  >
                  > My main interrest is web development in Zope/CMF/Plone, where there is a
                  > lot of repeated code in the products. So automated code generation seems
                  > like a natural fit.
                  >
                  > But every time I think of a use case, I immediately think of a way to do
                  > it with encapsulation instead.
                  >
                  > Does anybody have any experience using Python and automated code
                  > generation where it actually make sense?
                  >
                  > Or os it useless in a language as dynamic as Python?
                  >
                  >
                  > regards max M
                  >[/color]

                  Comment

                  Working...