6 ms·
Now there is no legitimate reason to lock out C++.
by ncmncm 6y ago
Now there is no legitimate reason to lock out C++.
- josephcsible 6y agoA lot of the reasons that Linus doesn't want C++ aren't true of Rust.
- arcticbull 6y agoThe biggest issue with C++ is it's an absolute atrocity -- an agglomeration of every feature under the sun, but half-built as many of those features can't possible co-exist. I mean, for example, std::move doesn't move... anything. std::move "just" static_casts the receiver as a template<class T> typename remove_reference<T>::type&&. Not that any sane human knows what that means. The source object remains alive and potentially invalid. Who even knows? Certainly not the compiler. This is just one example. All of C++'s new features are built like this. And the old ones are just so fragile. It's an incredibly dangerous, convoluted and absurd language, and every time I turn around it gets worse. It's time to leave C++ in the dustbin. It is an octopus made by stapling extra legs onto a dog.
- phkahler 6y ago>> It is an octopus made by stapling extra legs onto a dog. Never heard that before but it reflects my view of where C++ has been going very well.
- arcticbull 6y agoC++: an octopus made by nailing extra legs onto a dog. — Steve Taylor http://harmful.cat-v.org/software/c++/ http://harmful.cat-v.org/software/c++/
- imron 6y agoI used to be a C++ diehard, but modern C++ is the reason I started learning rust. I figured if I’m going to learn a bunch of new rules and idioms, I might as well do it with a language that has those things built in rather than bolted on as an afterthought.
- arcticbull 6y agoSame here tbh.
- runawaybottle 6y agoWhen I tell people their Typescript React projects look like a steaming pile of unrecognizable shit, I get downvoted. My precious simple shitty JavaScript is destined to be a bride dressed up in the shittiest possible gown sewn together in a hodgepodge of programming ideas implemented with the shittiest hacksaw one could afford. I guess I get you, you complete me.
- Aeolun 6y agoI guess Typescript, like C++ is just better than not having it at all. Plain javascript is a crime against the mind (and QA testers).
- runawaybottle 6y agoIt’s really not, but alas, the great crimes you won’t know about until after the fact. A crime is happening in the JS community, and one day we’ll all be writing the same thing OP wrote about C++, an amalgamation, a monstrosity, but whatever, it’ll be too late.
- sseagull 6y agoJust wait until Rust (or lots of new languages) get mature and start getting pushed in weird directions by niche use cases. In addition, languages always need to be seen improving in order to hold the attention of all the magpie developers. Who wants to use an old, stable language, amiright? Everyone will want their own small syntactic sugar to make their own ideas more easily expressed in the language they are currently using. It is just part of the lifecycle of programming languages. I am willing to predict that if Rust is still around in 30 years it will be unrecognizable to present-day developers, and newcomers at that time will decry it as 'an agglomeration of every feature under the sun'.
- rvz 6y agoDon't let your feelings get in the way of your valid argument about C++. The Linux kernel will eventually going use the FFI route from Rust and C someday, but it is no safer in both safe Rust and unsafe Rust according to this memory saftey assessment study that has Rust CVEs [0] [0] https://arxiv.org/pdf/2003.03296.pdf https://arxiv.org/pdf/2003.03296.pdf
- geofft 6y agoHere's our presentation at Linux Security Summit last year outlining why I think you can legitimately object to C++ and not Rust for this particular use case: https://youtu.be/RyY01fRyGhM?t=313 https://youtu.be/RyY01fRyGhM?t=313 (alternatively, slides 19-21 of https://ldpreload.com/p/kernel-modules-in-rust-lssna2019.pdf https://ldpreload.com/p/kernel-modules-in-rust-lssna2019.pdf)
- jhauris 6y agoThose slides are great. I love modern C++, but reading those slides makes me excited about trying out rust.
- deleted 6y ago[deleted]
- rhinoceraptor 6y agoMuch of C++ is inappropriate for a kernel. And defining which parts of C++ could be safely allowed would take so much time and bikeshedding that it's just probably not worth it.
- JoshTriplett 6y agoThere are plenty of reasons. As just one of them: C++ is unsafe by default. There's theoretically a safe subset, but there's no precise or consensus definition of that subset. There's no type-system or language support for helping you stay strictly within that subset (and requiring some kind of marker for if you don't). Often, the most obvious way of doing something is unsafe; for instance, in C++, arr[i] is unsafe, and you have to write arr.get(i) to be safe. (In Rust, arr[i] and arr.get(i) are both safe, and you have to write arr.get_unchecked(i) in an unsafe block if you truly want an unsafe indexing operation.)
- tptacek 6y agoCan you help me understand why locking C++ out of a kernel written almost entirely in C, and which receives huge volumes of new C code every year, wouldn't be an instance of making the perfect the enemy of the somewhat marginally better?
- JoshTriplett 6y agoI would question the "somewhat marginally better" part. (Please take all of this with a grain of salt, as I do not write "modern C++" in any professional capacity; its complexity has grown far beyond my knowledge.) I think introducing C++ into the kernel (and getting value from it) would require effort on par with introducing Rust, to provide safer interfaces for things. It would also require a substantial combination of tooling, documentation, and convention, to define a careful subset of C++ for use within the kernel, and to the best of my knowledge that tooling does not already exist. The C++ code would also have to continue interoperating with the existing C code, which means that even if there were a tool to say "warn/error about C++ code that uses one of the unsafe bits that comes from C", the kernel likely couldn't use that without substantial additional integration. And conversely, C++ introduces new potential errors that don't exist in C. The first example that comes to mind: if you use a C++ smart pointer, and do anything that gives you the raw pointer (e.g. &something->field, which is extremely common in kernel code), and put that in a data structure, and then let the smart pointer go out of scope, you now have a use-after-free vulnerability. In C, that would require explicitly freeing the object; in C++, there's no visible code associated with freeing the memory, and nothing in the type system tells you you've done something wrong there. A sufficiently well-trained modern C++ developer presumably would not make such an error very often. But what about a large number of expert-level C developers who are attempting to work with modern C++? Introducing C++ into the kernel would add a substantial amount of complexity, and I'm not at all sure that on balance you'd end up on "marginally better" rather than "worse". I'm not suggesting it couldn't be done, or that it couldn't eventually provide some improvements, but it's not clear to me that it's an obvious win.