26.10.2013 Views

2 - Forth Interest Group

2 - Forth Interest Group

2 - Forth Interest Group

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

A Forum for Exploring <strong>Forth</strong> Issues and Promoting <strong>Forth</strong><br />

Organizing Code-Hindrances and Aids<br />

Mike Nola<br />

San Jose, California<br />

The partitioning of <strong>Forth</strong> source code into lines can be<br />

an arbitrary business. For improved readability, we devise<br />

line-break conventions. With these conventions to help<br />

compel us to write code more consistently, we are better<br />

equipped to improve the reading comprehension of those<br />

who study our code.<br />

Imagine the difficulty of comprehending written lan-<br />

guage if it lacked subdivisions. Continuous expanses of<br />

text with no sentence, paragraph, or section endings<br />

would seriously hinder our comprehension of it.<br />

For lengthy documents, we employ still other special<br />

conventions, such as numbered paragraphs or sections to<br />

help establish smaller frames of reference.<br />

For lengthy listings of program code, we need similar<br />

conventions.<br />

Blocks and files can create frames of reference by their<br />

attachment of a number or a name to an expanse of code.<br />

In object-oriented languages, class names and class hierar-<br />

chies help chop up the application and make it more<br />

manageable.<br />

Vocabularies act more as<br />

organizers in the domain<br />

of compiled code than in<br />

the domain of source code.<br />

Like files, classes are of arbitrary length. Classes also<br />

merit attention because the object-oriented languages can<br />

understand and can meaningfully process a class name as<br />

a scoping mechanism. In contrast, line numbers, blocks,<br />

and file names play a role closer to bookmarks.<br />

Furthermore, class hierarchies can organize program<br />

code in gross as well as refined ways.<br />

Responsiveness to Units of Code<br />

Consider how well hierarchies of file-system folders<br />

can organize our files. Consider how outlining modes are<br />

increasingly supported by popular word processors.<br />

A hierarchical or outline organization is perhaps the best<br />

means we have to organize information, so why not also<br />

apply such a structure to the source code within a file?This 1<br />

July 1995 August 38<br />

suggests viewing our source code as outlines or charts.<br />

If we overlook more granular subdivisions of code, a<br />

huge opportunity is missed. In the world of object<br />

languages, the equivalent capability takes the form of<br />

"code browsers."<br />

While object-oriented languages are sensitized to more<br />

granular code units, conventional languages lag far be-<br />

hind. Specifically, when preprocessors unravel the code<br />

from multiple files into a single continuous stream, the<br />

compiler (the programming language) misses the oppor-<br />

tunity to be able to respond appropriately.<br />

For C, sensitivity to file-level scope is more a linker<br />

function than a language function. This is not the case<br />

when the "external" keyword gives notice to the compiler<br />

that a nearby symbol is not defined in the same file. Even<br />

in the presence of such cues, however, C does not know<br />

or even care to determine which file ultimately defines the<br />

symbol. That task is deferred to the linking step, which I<br />

consider a language-independent processing step.<br />

In C's favor, the compiler requires knowledge about<br />

the interface, if not the actual definition of externally<br />

defined symbols. However, this once again requires the<br />

intervention of programmers to provide the necessary<br />

clues in the form of function prototypes. These clues are<br />

provided in header files which, in accompaniment with<br />

the C preprocessor, dispense knowledge to the compiler<br />

of as-yet-undefined symbols or previously compiled func-<br />

tions that reside in a library archive.<br />

The use of a separate declaration of the function<br />

interface and the function definition may create an added<br />

maintenance burden. However, this was also a stroke of<br />

genius on the part of C's designers. Interface-checking<br />

remains an important feature of both C and C++.<br />

1 The Catalyst for Browsers<br />

Witness that, for conventional compiled languages,<br />

several types of files are common. The trend is for code to<br />

be partitioned in a rich variety of ways, most of which can<br />

be categorized in one of two ways:<br />

One way involves homogeneous subdivisions, such as<br />

statement-oriented syntax units that are repeated often.<br />

(Continues on page 36.) I<br />

<strong>Forth</strong> Dimensions

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!