Go to the first, previous, next, last section, table of contents.

Object-orientation

The algorithms should be object oriented, but only to the extent that is easy in portable ANSI C. The use of casting or other tricks to simulate inheritance is not desirable, and the user should not have to be aware of anything like that. This means many types of patterns are ruled out. However, this is not considered a problem -- they are too complicated for the library.

Note: it is possible to define an abstract base class easily in C, using function pointers. See the rng directory for an example.

When reimplementing public domain fortran code, please try to introduce the appropriate object concepts as structs, rather than translating the code literally in terms of arrays. The structs can be useful just within the file, you don't need to export them to the user.

For example, if a fortran program repeatedly uses a subroutine like,

SUBROUTINE  RESIZE (X, K, ND, K1)

where X(K,D) represents a grid to be resized to X(K1,D) you can make this more readable by introducing a struct,

struct grid {
    int nd;  /* number of dimensions */
    int k;   /* number of bins */
    double * x;   /* partition of axes, array of size x[k][nd] */
}

void
resize_grid (struct grid * g, int k_new)
{
...
}

Go to the first, previous, next, last section, table of contents.