|
|
Evolution - Actions |
|
By the early 80's it became common practice to group data into structures so that related data could be kept together always. Functions were rewritten to use these abilities.
The same matrix library could then be redefined to the following:
/* The matrix structure. Groups the data with the number of rows
and columns. */
typedef struct { double* a; int nr; int nc; } matrix;
/* Initialize a new matrix with nrows and ncols. */
matrix* matrix_init (int nrows, int ncols);
/* Print the matrix to the screen. */
void matrix_print (matrix* m);
/* Replace the values in matrix a with the sum of a and b */
void matrix_add (matrix* a, matrix* b);
/** Free the memory associated with the matrix. */
void matrix_free (matrix* a);
This methodology is sometimes referred to as Data Oriented or Action Oriented and is characterized by functions that are related by the structure that they take as the first argument.
This is the dominant paradigm in the C and F90 world. Common C examples include: