Templating Programming Language
October 31, 2011
Posted by on
Usually, people use the term templating language and programming langauge separately. Templating language refers to the language used by a template system for building online applications, such as JSP/ASP. Programming language refers to the imperative language that is used to build business logic, such as Java/C#/PHP/Ruby. They are like Oil and water that does not mix well. Templating programming language is the combination of the two. You can use it to directly write web pages, or write business logic. All in the same language.
A templating programming langauge should have the below characteristics:
- Taking arbitrary input: this is a major feature for templating language. Programming languages are usually very picky on what input to take on – only syntactically and semantically correct input are compiled and executed. Templating langauge takes a different approach. It usually can process arbitrary input. Actions are triggered when certain patterns are encountered in the input template. When there is no such pattern, the template is output directly without any change. This is a major convenience for templating language users. It allows the user to start writing template right away without any learning. They can delay the learning until they actually need to do certain things such as creating a placeholder and replace it with a value. A templating programming langauge should inherit this usability feature.
- Having all major programming constructs: all major programming constructs, such as variable declaration, expression, assignment, conditional statement, loop statement, functions are useful in a templating programming language. Just look at all the advanced templating systems. They have all of them. Without loop, how do you render tables? Without conditional statement, how do you greet user based on their title? Once you start adding conditional statement and loop, all the other basic structures such as variable declaration, expression, assignment have to be added as well.
- Linking between template structure and programming structure. It does not make sense to combine two types of languages without having a mechanism to make them interact and work with each other. Ideally, the linking should be deep and cohesive.