Template Oriented Programming

Template Oriented Programming

In computer programming, Template oriented programming (TOP) is a programming paradigm that focuses on templates to accomplish a programmer’s goals. Template oriented programming is a more general version of generic programming in which the template is the fundamental abstraction mechanism, as opposed to traditional generic programming applications that add templates to traditional languages such as C++, C#, or Java.

Introduction

The goal of template oriented programming is not to directly create machine code (or byte codes) to be executed on a (virtual) machine. Instead, the output of TOP is information to be processed by other code (or by humans). This could include familiar template output such as HTML/XML, or more complex code like C/C++/Java/C#, shell scripts, VHDL/Verilog, CAD scripts, etc. TOP allows one to generate one or more tedious artifacts from a simple, user defined model that is input.

Note that when the word template is used here, it is not talking about a specific programming language feature such as C++ template, C# generics, etc. Instead, it refers to the general concept of a template.

Many current template implementations of Template processors target text as their output. In general, however, template oriented programming may target code (such as C# generics), or any internal abstractions, such as reusable parts of an abstract syntax tree.

Fundamental Concepts

Similar to the paradigm shift that occurred when moving from structured programming to object oriented programming, or from unmanaged to managed, garbage collected code, programming in the TOP paradigm requires a different way of thinking about the information. The programmer starts with what he desires to have as output of a given set of code. This output is then abstracted as necessary to allow customization based on the input. The abstractions include: Simple field substitution similar to word processing form letters, extracting parts of the template into sub-templates that can be reused, looping over part of a template, making part of a template conditional, etc. The paradigm shift requires thinking about what should be produced instead of thinking about what the computer should do step by step.

This discussion leads to a short rabbit trail. Imperative programming languages (Fortran, BASIC, Java and C for example), evolved from machine language, and focus on telling the computer what to do. Declarative programming languages (Lisp, Prolog, XML), on the other hand, describe relationships between information. The drawback of pure declarative languages is that they cannot do anything, since they have no imperative aspect. Thus, most declarative languages have some way to start or otherwise control the execution of the program.

TOP applies the technique of declarative programming to code generation. This allows things like referring to information that does “not yet” exist. Such references, when first evaluated, will be null. However, when the information is “later” created, the reference will be created correctly. Notice the time related words were placed in quotes. That is because, in TOP one does not think about time. The processing order is handled by the system. Relieving this burden from the programmer eliminates many common bugs, and frees the mind of the programmer to focus on the more valuable, customer driven requirements.

A simple example is in order at this point. Let’s say a program was to evaluate a parenthesized mathematical expression. Assume the expression is mapped to a tree, with the leaves being the inner most expressions. A traditional imperative evaluator must find the leaves, evaluate these first, and then work up. A declarative solution, on the other hand, can simply state the desired result for each operator. All sub expressions are evaluated independently, and parent expression results will eventually be updated whenever a sub expression result changes. The system is responsible for making sure the result at the top is correct based on the last changes to any sub-expressions.

Declarative programming solutions have predominantly been used only in academia. They have many problems that make them inadequate for most commercial purposes. These issues, however, are mostly related to the runtime use of a declarative system: Difficulty handling the updating of program state, performance issues associated with information updating, etc. The TOP paradigm, instead, uses declarative techniques at compile time, avoiding many of these drawbacks.

This field is similar to that of template meta-programming. Template meta-programming systems are generally applied to a single, existing language. C++ templates, for example, allow adding templates to the C++ language. The focus is how to add compile time abstraction to the C++ language. TOP, on the other hand focuses on the templates, with the output language (or languages) being a secondary concern. In addition, the target language is defined by the programmer.


Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Look at other dictionaries:

  • Object-oriented programming — Programming paradigms Agent oriented Automata based Component based Flow based Pipelined Concatenative Concurrent computing …   Wikipedia

  • Subject-oriented programming — Programming paradigms Agent oriented Automata based Component based Flow based Pipelined Concatenative Concurrent computing …   Wikipedia

  • Comparison of programming languages (object-oriented programming) — Programming language comparisons General comparison Basic syntax Basic instructions Arrays Associative arrays String operations …   Wikipedia

  • Constructor (object-oriented programming) — Programming language comparisons General comparison Basic syntax Basic instructions Arrays Associative arrays String operations …   Wikipedia

  • List of object-oriented programming terms — Those words found in object oriented programming. Some are related to OOP and some not. A * Abstract class (also called deferred class) * Abstract method * Abstraction (computer science) * Access control * Accessor method * Allocated class *… …   Wikipedia

  • Programming paradigm — Programming paradigms Agent oriented Automata based Component based Flow based Pipelined Concatenative Concu …   Wikipedia

  • Programming in the large and programming in the small — Programming paradigms Agent oriented Automata based Component based Flow based Pipelined Concatenative Concurrent computin …   Wikipedia

  • Programming language — lists Alphabetical Categorical Chronological Generational A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that… …   Wikipedia

  • Template method pattern — [ LePUS3 ( [http://lepus.org.uk/ref/legend/legend.xml legend] ) ] In software engineering, the template method pattern is a design pattern.It is a so called behavioral pattern, and is unrelated to C++ templates.IntroductionIn a template pattern,… …   Wikipedia

  • Event-driven programming — Programming paradigms Agent oriented Automata based Component based Flow based Pipelined Concatenative Concurrent computin …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”