2 ms·
These are good points, but I don't think it relieves you of having to know whether your making a virtual function call or not, or wether you're passing an argum
by fauigerzigerk 14y ago
These are good points, but I don't think it relieves you of having to know whether your making a virtual function call or not, or wether you're passing an argument by value or by reference. You do have to know that, and in C++ you cannot know that by looking at the call site. In C and in many other languages you can.
- eridius 14y agoIn C there's nothing stopping the function you're calling from turning around and invoking dynamic dispatch. As a trivial example, objc_msgSend(). This is a C function, but it's also the entry point for objective-C's message sending (e.g. dynamic dispatch). Basically, what I'm trying to say is, focusing on the cost of the function call itself is useless if you don't know the cost of the function implementation.
- fauigerzigerk 14y agoAbsolutely, but to learn more about the implementation you have to look at the function's code. Every line of that code poses the same problem, so it's recursive down to every last expression.
- nostrademons 14y ago...which may involve loops or conditionals that then involve tracing more function calls or performing other dynamic dispatch, and so on farther down the tree until you have to know the whole codebase. Eventually you run into the halting problem: you can never know whether a given line in an arbitrary program will be executed, because if you could, just replace that line with "HALT" and you've solved the halting problem. Can't we just agree that you can't predict the performance of an arbitrary program without measuring it? (You can predict the performance of some programs quite accurately, but that has nothing to do with language choice and everything to do with coding standards that bound execution time.)
- fauigerzigerk 14y agoIf you're saying that it doesn't matter if you know whether you're calling a virtual function or whether a parameter is passed by value or by reference then we cannot agree on that. If you have reason to use C++ at all, these are not things you can simply ignore because they can affect performance rather dramatically. What we can agree on is that knowing these things is just a small part of what affects performance and that performance can be rather unintuitive.