Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Re: Re: Templating system for generating C code?

by clscott (Friar)
on Mar 23, 2004 at 17:42 UTC ( #339090=note: print w/ replies, xml ) Need Help??

in reply to Re: Re: Templating system for generating C code?
in thread Templating system for generating C code?

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 --template=c --template=c-optimise-poll vs

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 :)


Comment on Re: Re: Re: Templating system for generating C code?
Download Code
Replies are listed 'Best First'.
Re^4: Templating system for generating C code?
by gnosti (Friar) on Dec 13, 2007 at 04:32 UTC
    I am building my first perl module. It helps my coding to be about to % INCLUDE something % and have the something be dynamically generated by perl code... like code for testing purposes as was mentioned above or parts of a Parse::RecDescent grammar, for me. TT makes it possiblel for me to break up a long program in which the scoping limits of 'our' forces me to keep the entire contents together.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://339090]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2015-11-27 18:49 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (731 votes), past polls