Do me a favor, would you? Have a quick look at this code and tell me what you think it does...
...
I'm pretty confident that you'll find the second version a lot easier to understand, because it breaks up all those blocks of code into procedures with descriptive names.
Note |
---|
While this code does compile, and does use a real dictionary, I make no claims as to whether it works. Certainly it is incomplete, because I haven't yet written the final local procedure. In any case the purpose is not to register students for courses taught by teachers they avoid but to demonstrate how complicated code can be improved. |
There are a couple of things you may find unfamiliar about this code. One is the use of a local map and local procedures. Just as you can (and almost always do) have a map in a program module, you can have maps within modules and within procedures.
...
The Hanson Loop is a while loop - it keeps executing as long as the Result variable is equal to Level:Benign. You could write a siilar similar loop testing for Result = True, but I think there are some important benefits to using the Clarion return levels, which I'll get to in a moment.
...
The Clarion help has this to say about error levels, in the context of the ABC ErrorManager object:
Panel | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Six Levels of Treatment By default, the error manager recognizes six different levels of error severity. The default actions for these levels range from no action for benign errors to halting the program for fatal errors. The error manager also supports the intermediate actions of simply notifying the user, or of notifying the user and letting the user decide whether to continue or abort. Customizable Treatments These various levels of treatment are implemented with virtual methods so they are easy to customize. The error manager calls a different virtual method for each severity level, so you can override the default error actions with your own application specific error actions. See the various Take methods for examples. The recognized severity EQUATEs are declared in EQUATES.CLW. These severity levels and their default actions are:
You may define your own additional severity levels and their associated actions. |
...