9 questions

1 answer

1 comment

17,030 users

Welcome to Helix SDK Q&A, where you can ask questions and receive answers from other members of the community.

Templating Engines

0 votes
A big part of the power of Helix is that we try to generate as much of the common code for you as possible.  You define the structure of what you want, and we'll generate the code to implement that structure in your desired language.

At the heart of this is our code generation engine.  This started out as a Java program, which morphed into a C++ program, and is now under surgery to become something new.

When writing code that writes code - at the beginning - it's easy to simply inline the bits of code that will be generated as strings in the master code generation program.  That's what we have now.  That's how it was in Java, and how it got morphed into C++ as well.

As we go forward, though, this becomes harder and harder to maintain.  We need to generate more code.  We need to pay attention to more situations, and we need to be more and more sophisticated.  I can see where we need to go, but, for the time being I just don't know exactly what it's going to look like.

So, I've opted for small steps and to iterate my way through the problem.

First step is to extract as much of the hard-coded inline strings from the code generation engine and put them into separate template files.  This is an on-going effort, but it is already making the code generation engine much cleaner and clearer to understand.  It also means that I don't necessarily have to re-compile the code generation engine when I need to tweak the output.  As long as what I need to tweak is in one of the template files, I just update it and go.  This is already making life much easier.

I hesitate to use one of the more powerful templating solutions at this point, because I worry that I'm just trading one set of problems for another.  I like it when the templates are extremely clean and have very little xml or other cruft in them.  I recognize, though, that the logic of the if/else/loop/etc. code generation engine has to go somewhere.  It's either going to be embedded in the templates themselves - and evaluated by the template engine, or it will stay in our existing code-generator and get applied to more simple template files.

I don't have the right answer yet.  I only know I have to do something to make this more maintainable.  Iteration is the key.  I'll keep doing small things to make it better, and I'll keep looking at the templating engines out there to see if I can find the right balance.
closed with the note: blog-post
asked Sep 11, 2013 by Steven M. Cherry (42,320 points)
closed Sep 11, 2013 by Steven M. Cherry
...