Browse Prior Art Database

Using a Template Processor to Simplify Programming

IP.com Disclosure Number: IPCOM000123326D
Original Publication Date: 1998-Sep-01
Included in the Prior Art Database: 2005-Apr-04
Document File: 3 page(s) / 171K

Publishing Venue

IBM

Related People

Blount, BL: AUTHOR [+2]

Abstract

Often multiple files need to be generated that follow the same format or that vary only slightly in content. Here are several examples of when this occurs:

This text was extracted from an ASCII text file.
This is the abbreviated version, containing approximately 34% of the total text.

Using a Template Processor to Simplify Programming

   Often multiple files need to be generated that follow the
same format or that vary only slightly in content.  Here are several
examples of when this occurs:

   In the generation of customized web pages.  If a web
server provides customized pages to clients, it must dynamically
generate HTML code for each user request.  Most often, the HTML
source is very similar and follows a set format.  Instead of
generating the source manually in the program, it would be easier to
provide templates for the various pages.  The program would only have
to "fill in the blanks" with database data instead of having to
generate the entire file.  As well, certain portions of the template
should only be present in the resulting HTML code if the program
specifies that they should be there.  Since HTML does not have its
own loops, includes and conditionals we need another way to provide
all of this functionality.

   In the generation of common code for various data
types.  This is called templates in C++ and is more generally known
as parametric polymorphism.  If a programmer wants to write a vector
class for integers and a vector class for booleans, they should only
need to write one generic class, and have the specific instances of
the code generated automatically.  Many programming languages today,
such as Java, provide no mechanism for doing this.

   In the generation of code that uses loop unrolling.  Loop
unrolling is a technique that takes a loop with n iterations and
converts it to a loop with n/d iterations, where d iterations of the
original loop occur in 1 iteration of the modified loop.  The value d
is called the unrolling depth.  Loop unrolling is used to achieve
better performance, and is performed automatically by some (but not
all) compilers.  The optimal unrolling depth is machine dependent, so
often performance with various depths are measured.  Instead of
writing a different source file for each depth, a programmer should
only have to write one source template, and a tool should generate
the appropriate source code for any given unrolling depth.

   In generating files that contain the same headers,
footers, and other components.  If a user is generating several
files that all have the first ten lines in common, then the first ten
lines should be abstracted out into a different file, and the other
files should only point to the file that contains the original ten
lines.

   In all of these cases, the problem is that a user may
have to repeatedly generate identical data, whether is it by copying
files by hand or by generating them in source code.  This repetition
is not only a waste of time but is prone to error.  The resulting
files are also difficult to edit if you later need to change them.

   This process allows the user to create a template for the
files they wish to generate.  Each resulting file is determined by
both the tempate file and by a data map (a set...