The biggest advantage of using a template module over the HEREDOCS is the ease with which you can substitute the templates to generate differnt output for whatever reason you might need to:

  • Change the code fragments that are generated to test optimised C code
  • Switch the language that is generated (Or add another!)
  • Use the same information to build documentation/diagrams

The biggest advantage of encapsulating the "display" logic in the templates is that it simplifies the responsibilities of your application to:

  1. acquire input
  2. build the graph
  3. select a template
  4. pass the graph to the template
  5. write the output to disk
and insulates your application from bugs introduced by changing the display logic.

It also becomes much easier to produce all of those other formats that we might want because the templates now recieve all of the data in context and allow it to make output decicions based on the data rather than be an external holder to interpolated strings.

This would allow you to generate your C project many different ways without having to edit and re-edit versions of your application.

This allows you to maintain a parallel set of templates rather than "parallel" copies of the same application if you needed to test optimisation changes to your C code. Especially if changes to the output required changes to the display logic

generator.pl --template=c generator.pl --template=c-optimise-poll vs generator.pl generator_test_c-optimise-poll.pl

In the end what technique you decide to use depends on what you really want to do with the information you have.

If you don't need all the stuff, don't bother with it, but I like it when I can write a few templates and the beginnings of a documentation outline cheap.

It makes my manager happy to have documentation, and when my managed is happy I'm usually in a better mood :)

--
Clayton

In reply to Re: Re: Re: Templating system for generating C code? by clscott
in thread Templating system for generating C code? by toma

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.