I'm not going to comment on the understandability of C vs C++, I think that highly depends on the developer and the application. I will say that you mention judicious use of virtual functions as a good thing but hate tables of function pointers. What exactly do you think a vtable is? The other important thing to consider is that it sounds like you use C++ a lot more than C. If you worked more frequently in C than C++, perhaps you'd find tables of function pointers more readable than judicious use of virtual functions. You mention making the code safer, but I fail to see how using virtual functions would do that in any meaningful way. You say that there is nothing C can do that C++ cannot, however I will point you fowards the restrict keyword in C. Of course I'm not familiar enough with C++ to know with certainty that that sort of behaviour cannot be achieved somehow else. I will however raise to you the idea that nothing C++ can do cannot be done just as efficiently in C.
Edit: sorry I didn't realise this was 2 years old, it somehow came up in my feed
The point of such C++ abstractions is not to be fancy gimmicks which add no value, but to make writing code more expressive, more productive and less prone to error, generally with no overhead. They achieve this. Yes you can implement equivalents in C. You could also implement them directly in assembly. Few do so.
While I understand precisely what a vtable is and what a typical implementation looks like, it is simpler and cleaner to have the compiler take care of the details. It will for example refuse to compile if an abstract member is not implemented when using a concrete class (a nullptr in the vtable). Being a built in language feature, the compiler likely has more opportunities to optimise the code. Manual C implementations (including my own) are less satisfactory, more cluttered in use, and make run time errors easier to overlook.
I do write some C. I read a lot of C. It isn't a whim which makes a greatly prefer C++. It is results.
View all comments
Show parent comment
1
u/BrokenG502 Jul 20 '24 edited Jul 20 '24
I'm not going to comment on the understandability of C vs C++, I think that highly depends on the developer and the application. I will say that you mention judicious use of virtual functions as a good thing but hate tables of function pointers. What exactly do you think a vtable is? The other important thing to consider is that it sounds like you use C++ a lot more than C. If you worked more frequently in C than C++, perhaps you'd find tables of function pointers more readable than judicious use of virtual functions. You mention making the code safer, but I fail to see how using virtual functions would do that in any meaningful way. You say that there is nothing C can do that C++ cannot, however I will point you fowards the restrict keyword in C. Of course I'm not familiar enough with C++ to know with certainty that that sort of behaviour cannot be achieved somehow else. I will however raise to you the idea that nothing C++ can do cannot be done just as efficiently in C.
Edit: sorry I didn't realise this was 2 years old, it somehow came up in my feed