Introduction to CodeGen


CodeGen is a tool that software developers working in a Synergy Development Environment can use to generate source code. That code might be Synergy DBL code, or might be source code for some other language. CodeGen is not restricted to producing code for any particular development environment or programming language.

Of course you can’t just use CodeGen to generate any piece of source code that you can imagine. Before code can be generated a developer must declare the rules that define how a given piece of source code should be created. These rules are defined in template files. CodeGen interprets the code and instructions that a developer has defined in a template file in order to produce useful output.

Defining rules in a template file is only part of the story though. To be really useful CodeGen also needs to have another source of information that defines a context for what is to be generated.

Most software applications revolve around the collection, presentation, manipulation and storage of data. That data is ultimately stored in some type of persistent storage such as in a collection of data files, or in tables in a relational database. When developers work on a particular piece of source code they combine knowledge that they have about an application's data (metadata) with rules or "business logic", in order to create source code that addresses a particular requirement. CodeGen does the same thing.

When developers work in Synergy/DE they have access to an excellent source of metadata that is called the Synergy/DE Repository. A repository holds extensive information about the data structures used by an application, and the attributes of those data structures. A repository can also contain information about the relationships between the various data structures, and even about underlying data storage mechanisms. A Synergy repository is a very rich source of metadata and is the primary source of metadata used by CodeGen.

For developers who use the Synergy/DE UI Toolkit to present their application's user interface there may also be a second source of metadata called Window Script files. In some situations CodeGen can also make use of the metadata contained within these files also.

It’s all about metadata! CodeGen takes information about a data structure and combines it with rules that have been defined in a template file in order to create some useful output text.

Basic Principles

Each time a developer uses CodeGen to generate code they typically provide two primary pieces of information:

1.A source of metadata, usually the name of a repository structure.

2.The name of a template file that defines the rules for what is to be created.

Each time CodeGen generates an output file it usually does three primary things:

1.Read information from a metadata source, usually a repository structure.

2.Read rules from a template file.

3.Merge the rules with the metadata to create an output file.


Here's the Introduction to CodeGen video. Make sure you select a high-definition version of the video, by default YouTube tends to play the lowest resolution which can look pretty awful!




Copyright © 2021  Synergex International, Inc.