J
James Dow Allen
Jacob's mention of his library reminds me of my own
suggestion to help with software reusability.
Much software has the form
High Level -- application-specific code
Mid Level -- application-specific code
Low Level -- FREQUENT FUNCTION, use library
But often one encounters
High Level -- application-specific code
Mid Level -- FREQUENT FUNCTION
Low Level -- application-specific code
A familiar example where this form is encountered and
dealt with is qsort(), with the low-level handled
simply with a function pointer.
If the qsort() source were recompiled with the
application-dependent comparison etc. it would speed
up, perhaps by 25%. The qsort.c source wouldn't
even change; instead the variation would be provided
by a very simple application-dependent header included
by qsort.c.
For example, make this definition:
#define COMP(x,y) \
(((struct elem *)x)->key - ((struct elem *)y)->key)
visible to qsort.c, rather than just pass a pointer
to the function
int ecomp(const void *x, const void *y)
{ return COMP(x,y); }
I mention this simple case to make the idea clear,
but if all I wanted to do is speed-up qsort() by 25%
I wouldn't be posting this. Instead I'm thinking
of cases where the common function CAN'T BE USED
AT ALL, without this flexibility.
In these interesting cases, the application-dependent
variations are much too complicated to be represented
with a few function arguments, but a common source
code could still be used, with any variations
coming from #define's in an application-dependent header.
(I have specific examples in mind, but won't mention
them. I want to focus on the idea of reusing
source code in the way I imply, rather than any
specific example.)
How about it? Anybody do this, or want to do it?
(There are examples of it *within* a buildable
library, but I'm talking about library source where
the user is encouraged to recompile a routine,
like qsort() but probably more complicated, using
his own application-specific header.)
James Dow Allen
suggestion to help with software reusability.
Much software has the form
High Level -- application-specific code
Mid Level -- application-specific code
Low Level -- FREQUENT FUNCTION, use library
But often one encounters
High Level -- application-specific code
Mid Level -- FREQUENT FUNCTION
Low Level -- application-specific code
A familiar example where this form is encountered and
dealt with is qsort(), with the low-level handled
simply with a function pointer.
If the qsort() source were recompiled with the
application-dependent comparison etc. it would speed
up, perhaps by 25%. The qsort.c source wouldn't
even change; instead the variation would be provided
by a very simple application-dependent header included
by qsort.c.
For example, make this definition:
#define COMP(x,y) \
(((struct elem *)x)->key - ((struct elem *)y)->key)
visible to qsort.c, rather than just pass a pointer
to the function
int ecomp(const void *x, const void *y)
{ return COMP(x,y); }
I mention this simple case to make the idea clear,
but if all I wanted to do is speed-up qsort() by 25%
I wouldn't be posting this. Instead I'm thinking
of cases where the common function CAN'T BE USED
AT ALL, without this flexibility.
In these interesting cases, the application-dependent
variations are much too complicated to be represented
with a few function arguments, but a common source
code could still be used, with any variations
coming from #define's in an application-dependent header.
(I have specific examples in mind, but won't mention
them. I want to focus on the idea of reusing
source code in the way I imply, rather than any
specific example.)
How about it? Anybody do this, or want to do it?
(There are examples of it *within* a buildable
library, but I'm talking about library source where
the user is encouraged to recompile a routine,
like qsort() but probably more complicated, using
his own application-specific header.)
James Dow Allen