Continuation

From dis-Emi-A

Jump to: navigation, search


Contents

Intro

There are a few constructs that appear in current languages that require some mechanism to continue a statement, or provide special handling to the execution of a statement. These includes such things as try, catch, and finally (including automatic objects with destructors).

What high-level requirement do those items carry? In general they are ways of expressing some relationship between blocks of code, dealing with abnormal sitautions, or splitting logically connected code that needs to be executed at different points of the function. These high-level concepts should be treated distinctly; in practice these two needs are met ad-hoc in existing languages and become the source of errors (such as failure to handle the excpeitons correctly, swallowing exceptions, failure to call cleanup code, etc...)

Exit Code

At times there are needs to call specific code at the exit of a block. Note that resource based exit requirements are better handled by a class with a declared destructor. As that is the case, this exit code will appear similar to a class declaration.

The intent here is to keep related code close together where possible.

a = gl.LockGLSurface();
@exit gl.FreeGLSurface( a );

Entry Code

As an extension to the above there is a potential to cleanup another programming mistake, relating to the Evil If and program optimization. If you have several variables in a function used through the function, though not always required, it would be nice to have them initialized when first used. (Is this really often required?)

A speicfic example of odd code using such a pattern needs to be found.

Exception Handling

Exception Handling have examples of use related to exceptions.

Each block can continued by means of a continuation operator.

b.SendValue();
 => b.Complete();

The difference between a continuation and simply specifying another statement is that continuations execute even in the case of abnormal program flow (such as exceptions). This is a generic way to specify that whatever happens, this next item needs to be done (and in the case of exceptions it may even handle alternate flows).

Personal tools