ART - Adaptive Reuse Technique

About ART

ART is a notation to represent families of similar programs as highly parameterized, adaptable templates, for ease of maintenance and reuse. Typically, a program family comprises program versions that evolved from a single original program as new requirements have been implemented to it over time. Each program version addresses a specific customer segment or platform. Such program versions have much in common, but differ in some user requirements or design/implementation details.

ART provides an end-to- end solution for managing program families that eliminates the need for other mechanisms that are often used for that purpose such as macros or design patterns, and significantly reduces the scope in which we apply configuration management systems.

ART templates contain code that is common for all program versions in a family - in parameterized form, for ease of adaptation. ART Processor derives program versions from ART templates, based on specifications of requirements that are specific to a given program version (i.e., requirements that have not been implemented as a common part in ART templates).

ART can be pictured as an advanced form of macros that evolved into well throughout program instrumentation notation, avoiding well-known pitfalls of macros, and greatly extending their power to tackle problems of program versioning. For example, ART gives a programmer full control over propagation of #define parameters to included files (#include) to enhance their reusability. Any similar files (or other program structures) can be represented as generic ART templates from which ART Processor generates concrete program files.

ART can be also pictured as an advanced template system, where any program structure (not only classes or functions) may become a parameterized template, and where parameters may be just anything we wish – types, program fragments, files or program structures of any kind and size.

In SPL (Software Product Line) reuse, ART plays a role of Variability Management Technique (VMT) that handles adaptive changes at the architecture to code. In practical SPL reuse scenarios, we typically use a range of VMTs such as macros, scripts, build tools (Ant or make), design patterns, or commenting out variant/optional code for manual inclusion/exclusion. As ART does what the other VMTs collectively can do, there is no need to use multiple (sometimes incompatible) VMTs.

Variability Management Techniques (VMT)

help developers manage the base code for families of system variants, e.g., a family of Linux versions running on various platforms, or financial systems used in different companies. VMTs organize and/or instrument the base code for ease of adaptation and reuse.

ART and its predecessor XVCL have been applied in industrial projects as a variability technique to manage reuse in product lines of web portals, command and control systems, mobile games, information systems, and to eliminate redundancies in software libraries (STL, Buffer).

How is ART different from the earlier XVCL?

ART is an enhanced, lightweight and XML-free version of XVCL. Like XVCL, ART is based on concepts of Bassett’s Frame TechnologyTM.

Frame Technology

is a language-neutral (i.e., processes various languages) system that manufactures custom software from reusable, machine-adaptable building blocks, called frames. FT is used to reduce the time, effort, and errors involved in the design, construction, and evolution of large, complex software systems.

ART improves the user experience by providing the following improvements to XVCL

Easy to learn and use: XVCL is a dialect of XML and uses XML trees and a parser for processing

ART parts with XML syntax and processing. You can define your own syntax for ART commands, to suit your programming environment and taste, and to avoid conflicts with the base languages. As default, ART offers a simple cpp-like syntax.

Expanding the customization options under #adapt command

In XVCL, the only command that you can place under adapt is insert. ART allows to use any command under #adapt. We found using #set, #while and #select commands under #adapt to be particularly very useful.

Robust structure instead of unreadable loops

In XVCL, while loops using many multi-value variables can be quite confusing. ART introduces a structure called set-loop which gives the possibility to store and use more multi-value variables together as one loop descriptor data structure.

More flexible

ART is more flexible than XVCL, as it allows the adaptation of a file even though the file might not contain any ART commands. Such adaptation would simply copy the adapted file to the output stream.

How it Works

Like other pre-processors, ART is a text manipulation system. ART Processor reads ART templates (source code files with embedded ART commands), and outputs source code files ready for compilation. ART commands (#[cmd]) are processed, while code is emitted to the output. The processing sequence is defined by ART commands, which will be explained in this tutorial.

Adapting input files

To start processing, we feed to ART Processor the specification file called SPC. ART commands in SPC, and in each subsequently processed file (ART template), are processed in the sequence in which they appear. When ART Processor encounters an #adaptf2 command while processing file f1, it suspends processing of file f1 and starts processing file f2. Once processing of file f2 is completed, ART Processor resumes processing of file f1 just after #adapt command. In that way the processing ends when the Processor reaches the end of the SPC.

So far, ART’s #adapt looks like a cpp’s #inclide. However, there is an important difference: unlike #include, #adapt “A” (as the command name suggests) can modify file “A” at the inclusion point, and it can do so differently at differentinclusion points. Many software components have a potential for reuse, but most often they have to be modified to fit a specific reuse context. ART’s #adapt together with other commands provide a powerful mechanism to do so. Examples that follow explain how this is done.

Usage and Examples

Let's see how ART can be applied with some simple code snippet examples.
The ART language like other languages allows us to declare and use variables. Let's look at the following simple example:

ART snippet:

Result:

As we can see, variables can be allocated with the #set command, and ?@varname? retrieves their value.

Values of variables propagate to the #adapt-ed files. Let’s see an example where #adapt and #set are used together, allowing for a simple form of adaptive reuse of files:

ART snippet:

template.art:

Result:

A template is reusable program component: First we set up values for variables (template parameters), then we #adapt a template with our variables to get the result we were expecting.

Since the template does not know about our specific settings, we can (re)use it in other contexts, with different values of variables, without any changes done to the template. I can #adapt a template with my own set of values, and my neighbour can #adapt it with his own set of values, and we both get the output we wanted, without making any changes to the template.

Multi-value variables and loops in ART

We can give multiple values to a variable with a #set command, by defining the values separated by comma. These variables in ART are called multi-variables or multi-value variables.ART's #while command will let us loop over the values of a multi-value variable. Example:

ART snippet:

template.art:

Result:

ART templates not only let us generate source code from reusing templates, but grealy hepl in maintenance and code evolution as well.Let's say we need to add another class to our example called 'Mage'. To do that we only need to make a very small change in our definition and we don't need to change the template code at all. The change is the following:

ART snippet (added Mage class and values):

template.art (all the same, no change):

Result:

This way ART can greatly boost our productivity and we don't need to worry about copy-paste errors or similar inconsistencies caused by user-error.

Let's add another small change to our code! Say some warrior classes will have special attack, some will not have, and the ones who have, can have different ones.

We need to learn two new commands for this. We will use the #insert - #break mechanism

Our template will have a breakpoint where we can extend with additional content from our specification, meaning, we can change the template from outside the template without affecting others. Let's see:

the new template.art:

the new spec file:

Later we will show better ways of injecting code, now we used a simple #if command and matching the class name.

Result:

Of course, there is much more in ART, however with these essential features and mechanism we can get a great deal of productivity out of it, if used in the correct way. Take a look at the Learn section to see more examples and explanations of ART commands.

Read on if you want to know more about ART in general.

Get ART, Run ART

You can download the ART processor and examples from this link. The package contains instructions on how to execute the processor.
To run the processor on your machine you will need an installed JRE on the computer. You can get it from here.

You can run snippet codes online on ARTFiddle. You can write ART code and execute it on out remote computer which will give you the result after executing your code. In this way for executing ART processor you only need internet connection. ARTFiddle has many toturials you can execute, modify to help you learn and understand how it works. The snippets you are running will get a unique code and can be kept and shared by link. Visit ARTFiddle to find out more.