5 ms·
I had to make an application framework something like this with ANSI C in the 90s. Make a structure (or two) full of function pointers as an "interface", pass
by Roboprog 13y ago
I had to make an application framework something like this with ANSI C in the 90s. Make a structure (or two) full of function pointers as an "interface", pass it (them) as the first parameter to all the relevant functions as "this"/"self". (wait, that kinda looks like what "Go" does - hmmmm)
Of course, some in the company tried to pad their resumes with actual (gahd-awwwful) C++. Lovely jewels like this:
if ( output_format == A) {
a.write_pg_header();
} else {
b.write_pg_header();
}
Guess they never heard of a virtual method. Then there's the fun of all the memory leaks from copy constructors and other silly C++ pitfalls.
Simulated OOP in C is an interesting exercise. I suppose if I had not learned an OOP language other than C++ first, I would have thought C++ is just how (hard) it's supposed to be :-)
- Roboprog 13y agoAlso did an OOP emulation a few years earlier than this using Clipper 5, of all things. No structs, but you could make constants for array indices, and assign a closure/block to each array element, using the array as a virtual method table.
- coldcode 13y agoI did as well in 1988, but mine was missing a lot of things as I didn't have any good examples to base it on. All I had ever read was the Smalltalk issue of Byte.