![]() |
|
Published 1998-10-01 Printer-friendly version
Nik Johnson's breakout presentation on Monday afternoon was based on the premise that tools like the template language can be useful to all Clarion programmers, not just to those who build tools for sale to others. Anyone who adds code to an embed point, he suggested, should make an effort to understand at least the basics of the template language and the CLASS-related features of the Clarion language.
He illustrated the point with three examples: A simple template, a simple class, and a template which works together with a class to achieve the desired result. Reviewing each of these in detail provided an introduction to several basic template language statements and the basic CLASS structure.
Johnson pointed out that the template language is not particularly consistent in its structure and operation with the Clarion language. This is partly due to the fact that the languages have different purposes and may also reflect the separate development paths of the two languages. "The people involved in developing the template language may have been concentrating on a tool for their own use and may not have been thinking in terms of a wider audience," he said. As a result, the syntactical rules for the template language are more rigorous in some respects than the Clarion language and less in other respects.
The solution is to pay attention to the documented syntax rather than guessing at it based on experience with Clarion.
Templates can be especially useful in copy-and-modify situations where certain code patterns occur over and over, the only difference between instances being, say, variable names. Another situation where a template serves well is when a single function requires bits of code at various points in the program.
Unlike templates, CLASS structures are integral to the Clarion language. The strength of a CLASS is not related to generating similar code in multiple places but to using the same code over and over again. "Think of a CLASS as a specialized robot," suggested Johnson, "which handles a particular task or set of tasks on demand. Further, the CLASS structure provides for multiple copies of a given "robot", each configured to handle a particular instance of its designed functionality.
CLASSes are useful when several processes use the same set of data, when data persists between executions of processes, or when multiple similar processes must execute simultaneously.
The important thing in using CLASSes for your own purposes is to take advantage of Clarion's OOP-related features without becoming intimidated by the formalisms of OOP in the general sense.
Writing templates and classes for your own use, suggested Johnson, is very different from writing them for sale, just as building a system for limited distribution is different from building a shrink-wrapped project. However, just because you don't need extensive user documentation, don't skimp on notes and comments for your own use. It may be some time before you revisit this work and want to modify it.
While neatness counts, perfection doesn't. Johnson suggests that you keep your private templates and classes a work in progress, expanding them as you go. This almost guarantees that you will have pieces of code which are no longer needed or whose intended use never materialized. When you revisit a template or class to extend it, it's a good idea to do some cleanup as well, but in most cases it's not to keep every template or class in pristine condition.
How you develop your skills with templates and classes is a matter of personal style, but there are a number of resources you can use. The Programmer's Guide contains a full reference manual to the template language and two excellent chapters on Clarion's implementation of OOP. Examples of both templates and classes abound. The Application Handbook, which documents the ABC classes, is also a good source of insights into the use of CLASSes.
If you are active on CompuServe or the Clarion Internet newsgroups, don't hesitate to ask questions about templates and classes. You'll also find that many people answer coding questions by posting a piece of template code.
Classes in both template writing and OOP are offered by TopSpeed and by third parties.
And, we hasten to add, Clarion Online is also a good source of information on these subjects. (Editor's Note: Look for a major newsflash regarding Clarion classes in the October issue.)
Copyright © 1999-2009 by CoveComm Inc. All Rights Reserved. Reproduction in any form without the express written consent of CoveComm Inc., except as described in the subscription agreement, is prohibited.
Clarion Magazine ISSN 1718-9942
One year: $169
(includes all back issues since '99)
Renewals from $119
Two years: $269
Renewals from $219