Вы находитесь на странице: 1из 2

Charlotte C.

Cabrera
2BSA-1

Code Generation in Business Systems

Firms such as Gartner, Forrester, and IDC have focused their analyses of MDE technology on
commercial IT developers and software providers. As stated earlier, our analysis focused on the
unique acquisition concerns of the DoD and other federal agencies in which systems are acquired and
maintained for longer periods of time. Specifically, we examined business systems since this is an
area where code generation tools are having significant impact. This analysis included existing
technologies and approaches used for commercial off-the-shelf technologies (COTS), and it
investigated how those same principles can be applied to the acquisition of MDE tools. We used
the PECA Method (Plan, Establish Criteria, Collect Data, Analyze Results) to organize an acquirer's
technology assessment, and used an established risk framework to identify criteria within the overall
process.

Code Generation with Python


The language I chose for the code generators was, of course, Python. Its simplicity and power are
perfect for the job of reading data files and producing code. To simplify the integration with the C++
code, the Python generators are inserted directly into the C++ file as comments.

Cog reads a text file (C++ in our case), looking for specially-marked sections of text, that it will use
as generators. It executes those sections as Python code, capturing the output. The output is then
spliced into the file following the generator code.

Because the generator code and its output are both kept in the file, there is no distinction between
the input file and output file. Cog reads and writes the same file, and can be run over and over again
without losing information.
Cog processes text files, converting specially marked sections of the file into new content without
disturbing the rest of the file or the sections that it executes to produce the generated content. Zoom
in
In addition to executing Python generators, Cog itself is written in Python. Python's dynamic nature
made it simple to execute the Python code Cog found, and its flexibility made it possible to execute it
in a properly-constructed environment to get the desired semantics. Much of Cog's code is concerned
with getting indentation correct: I wanted the author to be able to organize his generator code to
look good in the host file, and produce generated code that looked good as well, without worrying
about fiddly whitespace issues.

Python's OS-level integration let me execute shell commands where needed. We use Perforce for
source control, which keeps files read-only until they need to be edited. When running Cog, it may
need to change files that the developer has not edited yet. It can execute a shell command to check
out files that are read-only.

Lastly, we used XML for our new property schema description, and Python's wide variety of XML
processing libraries made parsing the XML a snap.

How It Worked Out


In a word, great. We now have a powerful tool that lets us maintain a single XML file that describes
our data schema. Developers changing the schema have a simple tool to run that generates code
from the schema, producing output code in four different languages across 50 files.

Where we once used a repetitive and aggravating process that was inadequate to our needs, we now
have an automated process that lets developers express themselves and have Cog do the hard work.

Python's flexibility and power were put to work in two ways: to develop Cog itself, and sprinkled
throughout our C++ source code to give our developers a powerful tool to turn static data into
running code.

Although our product is built in C++, we've used Python to increase our productivity and expressive
power, ease maintenance work, and automate error-prone tasks. Our shipping software is built every
day with Python hard at work behind the scenes.

Вам также может понравиться