5 ms·
This is as bad an idea as 'OO' C. having had to deal with the grief that was a late-90s attempt at OO C.... stay away from this. Tooling is designed for idiom
by TickleSteve 10y ago
This is as bad an idea as 'OO' C.
having had to deal with the grief that was a late-90s attempt at OO C.... stay away from this.
Tooling is designed for idioms of the language. Attempting to be 'clever' means you have to throw away all the benefits of that tooling as well as reducing your maintainability and confusing the optimiser.
- jjnoakes 10y agoPlenty of successful projects use some form of 'OO' C. The Linux kernel is probably one of the most successful. I'm not saying all C programmers should use OO techniques, and I'm not saying all OO programmers should reach for C, but I don't think blanket statements like "OO C is a bad idea" and "stay away from [OO C]" are useful without context (and with context they are almost meaningless).
- TickleSteve 10y agoThe linux kernel is an extremely mild form of OO. Mild to the extent that is effectively idiomatic C code. What I'm referring to is the manual creation of virtual pointer tables and dereferencing everything through it. This completely defeats the optimiser as it can't see thru the pointers. The case I'm referring to was a complete WTF in hindsight.
- jjnoakes 10y agoWhat is the difference between what you are calling virtual pointer tables and what the kernel does in a lot of places? http://lxr.free-electrons.com/source/fs/ext4/symlink.c#L93 http://lxr.free-electrons.com/source/fs/ext4/symlink.c#L93
- TickleSteve 10y agoIts the extent to which it is done. virtual pointer tables are an age-old 'C' mechanism of providing runtime configuration for drivers and such like. the WTF project, took that idea and had virtual pointers for everything methods, data, superclasses, etc. Every line consisted of something like the following: obj->vptr->methodA(obj, objB->vptr->methodB()); it very rapidly becomes a readability and maintainability nightmare.
- jjnoakes 10y agoSorry, I'm still not following your argument.
- TickleSteve 10y agodereferencing the vptr in the Linux device tables tends to happen once per (say) function. the WTF project would have '->vptr' and worse '->super->vptr->method(), maybe 20 or 30 times per function. every call in the codebase or data reference would be via a '->vptr'. That really makes a difference.... its unreadable. literally.
- jjnoakes 10y agoSo based on one project's misuse of a technique (OO in C) you dismissed it as "bad" idea, "stay away from this", it's "attempting to be clever", and the rest? I think that's why I'm not following you. You've dismissed OO in C in its entirety, and advised others to do the same, based on your experience in one project which misused/overused the feature.
- TickleSteve 10y agono. The level to which it is used in Linux is effectively idiomatic. The project I'm referring to used the technique properly. Its just a bad technique.
- jjnoakes 10y agoYou've said it is a bad technique no matter how it is used, and you have said it is an ok technique if used at some levels (like the Kernel) but not others (like the WTF project). So you can see how I'm confused about what your opinion really is, I hope.