3 ms·
That's an implementation detail.
by runeks 10y ago
That's an implementation detail.
- cperciva 10y agoExactly! But because this is how objects are implemented, everything you can do with objects, you can do using structures and function pointers -- there's nothing magical about objects. Which means that as long as you understand structures and function pointers you don't need objects.
- runeks 10y agoRight, but all programming language constructs are eventually reduced to assembly code. So, strictly speaking, as long you understand assembly, you don't need any language constructs at all. This fact doesn't offer us any insight into the nature of language constructs, though.
- pg314 10y agoExactly. To quote Alan Perlis: Beware of the Turing tar-pit in which everything is possible but nothing of interest is easy.
- millstone 10y agoOf course a design centered around structs equipped with function pointers is, in fact, an object system.
- cperciva 10y agoSure. But realizing that objects are just structs with function pointers takes you from a binary "this code uses objects" vs. "this code doesn't use objects" to a more flexible "this code is designed in a more objecty way than that code". A lot of people think about objects as a language feature, when they're really a design paradigm; and like all good design paradigms, you can use more or less of them depending on how well the paradigm fits a particular piece of code.
- lacampbell 10y agoTo an extent - with the caveat that there are entire languages built around this design paradigm, such that using objects is the syntactic past of least resistance. I agree though, when I dabble in C I often end up writing objecty code. Sometimes it's even a bit functional..
- Ace17 10y agoEmbedded C programmer here. What you say is technically true, however, wiring interfaces and vtables manually in C is a real PITA, to the point that you think twice before introducing a new interface between two components. OO languages make this a lot more easy.
- pg314 10y agoThat is not always how objects are implemented. It is but one way to implement objects. A JIT-ing interpreter, for example, doesn't have to use function pointers to implement objects.