On 25/09/2022 1:12 am, Bernd Oppolzer wrote:
IMO, there are some really interesting use cases for such techniques,
for example
- sort routines where the comparison functions is generic, that is, a
function pointer
- same for search routines
- same for dynamic arrays of structs, indexed by key structs (I
implemented one, using AVL trees)
- a function package which prints or plots other functions
and so on.
In C, I did this using function pointers.
In Pascal, I can pass procedures or functions to procedure parameters
(procedures passed as
parameters to other procedures), which is virtually the same as
function pointers, but IMO
looks nicer. This is from the 1960s. I never considered this as being
OO, but in fact,
all the above things, although implemented in procedural languages
like C and Pascal,
are TEMPLATES.
If I really feel the need for such solutions (which I do sometimes), I
anyway like to stick
with procedural languages like, see above, Pascal and C, and I don't
use C++;
all the OO overhead makes me feel bad.
What is this overhead you talk about? The C++ mantra is "you don't pay
for what you don't use". If you don't want to use virtual inheritance
then don't! What you will gain is strong typing, RAII, STL with strings,
containers etc.
Modern C++ is heavy on generics (templates) which are stored in header
files so open up more possibilities for optimization at the cost of
compile times and module size. I would take the Pepsi Challenge in a
drag race between your AVL tree library using a callback with linkage
overhead against std::map<T> or
a similar generic library that generates bespoke code for the type. To
really make it interesting I could roll out the big guns and use a
highly optimized library from Google
https://code.google.com/archive/p/cpp-btree/wikis/UsageInstructions.wiki
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN