Tonto | ||
---|---|---|
<< Previous | Next >> |
The TONTO system is written in foo, a preprocessor which encourages a good object-oriented programming style. foo is closely related to Fortran95, and indeed, foo code currently translates into standard compliant Fortran95 code.
The following sections describe the rules for valid input to the foo preprocessor, and the actual transformation process performed by the preprocessor.
Although the rules are quite simple, and examples are given, it is probably easier to examine foo modules that have already been written. It should be possible to understand foo code without reading the formal rules, if you already have a basic knowledge of object-oriented programming techniques and syntax.
The most important element of the foo language is the introduction of a "dot notation". In this notation, a dot "." expands either into the Fortran95 "%" type separator symbol, or a procedure call, depending respectively on whether there is, or is not, a type component with the appropriate name defined in the type. Thus, using the dot notation, it is possible for the programmer to "hide" the detailed implementation of a type (and hence a module) from a casual user. In this way, the computer code becomes robust to future changes, sincethe distinction between a routine and actual data becomes blurred.
Note that you don't have to write your code in the foo language --- plain Fortran95 is fine, provided you stick to the guidelines in the previous chapter -- but foo has many advantages, and is worth the minimal effort required to learn it.
If you do choose write your code in foo, then the following advantages are available to you:
HTML code documentation facility. The code you write will be used to generate, automatically, fully hyperlinked synopsis-style html documentation.
Hyperlinked procedures and colour-coded syntax. Using the vim editor and the ctags program, the code you write can be coloured by syntax, folded by procedure, and fully hyperlinked with all other procedures in the system, greatly increasing your productivity.
Overloading and interface files. You can write routines with exactly the same name (provided that they can be distinguished by their call signature). The interface file required for this automatic overloading is automatically generated.
Automatic use statement generator. You don't have to write use stetements, because the preprocessor will automatically generate them for you. This can make compile times much faster on many systems when you use highly nested modules.
Dot notation. A dot notation is available, as used in most object oriented languages. The call statement is no longer required. In effect, a foo module module becomes a "class" which implements a so-called abstract data type (ADT). The dot notation allows you full data-hiding (i.e. encapsulation) for your module.
Multiple template inheritance. A multiple template-based inheritance scheme has been implemented, based on code inclusion. The inheritance scheme does not depend on subtyping, so opportunities for code re-use are not constrained in any way by language design and code structure. The scheme is not based on dynamic dispatch, ans so is efficient
Preconditions, postconditions, and error management facilities. To help in writing bug-free code, you can place preconditions and postconditions into your routines to codify the minimum requirements for your routine to perform its task correctly. If an error is detected you have a traceback of the call stack to tell you where it happened. You can elect not to use this facility if you are afraid it will make your code less efficient.
Memory management facilities. Fortran95 offers full support dynamical memory and pointers, but this can lead to serious problems with memory management, such as the famous "memory-leak" problem. Foo automatically checks is each routine you write is memory-tight. You can elect not to use it this facility facility (for reasons of fast code). Full traceback and memory monitoring is also available to help track difficult memory leaks.
Conditional compilation of PURE and ELEMENTAL routines. Fortran95 disallows write statements to be placed within routines marked PURE or ELEMENTAL, which may be an annoyance for testing purposes. You can elect to compile your code without these keywords.
Automatic end keyword completion. You can use the end keyword to stand for any of the usual block termination words: end program, end module, end subroutine, end function, end if, end do, end interface, end select, end type, end forall. This is less typing for you and makes the code less cluttered [1].
Automatic subroutine and function detection. You don't need to use the subroutine and function keywords. These are automatically detected for you. It means less typing and less cluttered code.
Protection against changes in the language elements. The foo preprocessor represents a minimal approach to object oriented programming, and it is conceivable that it may be translated into a language other than Fortran95 at a future date, should Fortran95 no longer be the best choice for fast, numerical programs.
[1] | But this makes it nearly mandatory to use indentation, which is good programming practice |