6 ms·
> Since you mentioned error handling as a reason to choose C++, what else could you possibly mean? I believe he means RAII. It makes it almost impossible to fo
by netheril96 9y ago
> Since you mentioned error handling as a reason to choose C++, what else could you possibly mean?
I believe he means RAII. It makes it almost impossible to forget to release resources or rollback transaction.
- hawski 9y agoI understand RAII as resource management solution. What use does RAII have in error handling? It makes things convenient, but it does not make error handling go away.
- pjmlp 9y agoNo, but exceptions aren't the only way to handle errors in C++. There are also library types that enforce checking for errors, something currently impossible in C. Also thanks to its stronger type system, it is possible to do type driven programming thus preventing many errors to happen at all, which is also not possible in plain C. Finally everyone is moving to C++, C for OS development is stuck on UNIX and embedded devs that wouldn't use anything else even at point gun.
- varjag 9y agoC++ has shrunk a lot in the mindshare since its peak in mid-90s. And Rust is the trendy thing now in the same space.
- pjmlp 9y agoOnly if we are speaking about enterprise CRUD apps that used to be done in MFC, OWL, VCL, Motif++. OpenCL lost to CUDA because it did not natively supported C++, only when it was too late. NVidia has designed Volta specifically to run CUDA C++ code. There is no C left on game consoles SDKs or major middleware engines. All major C compilers are written in C++. Microsoft has replaced their C runtime library by one written in C++, exposing the entry points as extern "C". Beyond the Linux kernel, all native parts on Android are written in C++. The majority of deep learning APIs being used from Python, R and friends are written in C++. Darwin uses a C++ subset on IO Kit, and Metal shaders are C++14. AUTOSAR has updated their guidelines to use C++14 instead of C. All major modern research OSes are being done in C++, like Genode. Arduino Wiring and ARM mbed are written in C++. As for Rust, while I do like it a lot, it still cannot compete with C++ in many key areas, like amount of supported hardware, GUI frameworks and available tooling.
- mlvljr 9y agoWill be call OP a liar, fanboy gents?
- lemoncucumber 9y agoIOKit dates to c. 2000 so it’s hardly a modern example and even people at Apple bitch about the fact that they went with C++.
- pjmlp 9y agoMost likely because they dropped Objective-C driver framework from NeXTSTEP. They are surely a vocal minority, otherwise Metal shaders wouldn't be C++14.
- Matthias247 9y ago> AUTOSAR has updated their guidelines to use C++14 instead of C. Really? Interesting thing. You mean for "standard/legacy" autosar, or for the new "dynamic" variant? When I was back in automotive, the autosar design(s) where probably the ones software people were mostly complaining about.
- pjmlp 9y agoBMW were the ones pushing it. I am no expert there, learned it from their presentation at FOSDEM last year. https://archive.fosdem.org/2017/schedule/event/succes_failure_autonomous_driving/ https://archive.fosdem.org/2017/schedule/event/succes_failur... Page 12 on the second slideset.
- naasking 9y ago> There are also library types that enforce checking for errors, something currently impossible in C. This is a weak form of checking for a kernel. L4 Hazelnut was written in C++ for this reason, but they didn't use it much, mirroring Shapiro's experience with EROS. And when they had to revise the kernel design to plug security holes and they wanted to formally verify its properties, they switched to C because C++ was too complex and left too much behaviour unspecified, and thus we got verified seL4 written in C.
- knorker 9y agoIt's easier to get this right: { Resource foo(path); if … { return -ENOMEM } return 0; } Than to get this right: { Resource* foo = acquire(path); if … { release(foo); return -ENOMEM } release(foo); return 0; } Even if you do the goto-style: { Resource* foo = acquire(path); int rc = 0; if … { rc = -ENOMEM goto out; } out: release(foo); return rc; }
- willtim 9y ago> It makes it almost impossible to forget to release resources or rollback transaction. No. For that you need a better type system. Linear types show great promise for this.
- sedachv 9y agoLinear types don't "show" promise, they solve the issue, and this has been known since linear logic was popularized by Wadler[1] and Baker[2] in the early 1990s. The problem is that programming with linear logic is very inconvenient for a lot of things, and very inefficient for when you actually want to share data. [1] http://homepages.inf.ed.ac.uk/wadler/papers/linearuse/linearuse.ps.gz http://homepages.inf.ed.ac.uk/wadler/papers/linearuse/linear... [2] http://home.pipeline.com/~hbaker1/LinearLisp.html http://home.pipeline.com/~hbaker1/LinearLisp.html
- naasking 9y ago> I believe he means RAII. It makes it almost impossible to forget to release resources or rollback transaction. This kind of pattern doesn't exist in a microkernel. I agree it might be useful in a monolothic kernel, but that's not the context here.