|
|
Subscribe / Log in / New account

Scope-based resource management for the kernel

Scope-based resource management for the kernel

Posted Jun 22, 2023 10:32 UTC (Thu) by mb (subscriber, #50428)
In reply to: Scope-based resource management for the kernel by make
Parent article: Scope-based resource management for the kernel

>because the source code flow in C++ and Rust is similar.

No, not at all.
Rust has no inheritance. Code flows between ideomatic C++ and ideomatic Rust are quite different.

It does not work to say that we're going to switch to C++ but only use RAII from it.
People *will* start using more and more of C++'s features.

It's better to keep that huge amount of stuff out of the kernel to begin with.
The C implementation might not be as pretty as C++, but pulling in C++ comes with a tremendous cost of arguing over and over again why this and that C++ feature shall not be used in the kernel.


to post comments

Scope-based resource management for the kernel

Posted Jun 22, 2023 18:38 UTC (Thu) by make (subscriber, #62794) [Link] (7 responses)

> No, not at all. Rust has no inheritance. Code flows between ideomatic C++ and ideomatic Rust are quite different.

You're missing the point. The article and this thread is about using RAII in the Linux kernel, not about inheritance. RAII works the same in C++ and Rust (and in C with GNU extensions, as it's going to be used soon).

The fact that C++ has features that Rust has not (which I didn't suggest to use and which do not affect the code flow) does not falsify my argument - it doesn't even have anything to do with this thread.

> It does not work to say that we're going to switch to C++ but only use RAII from it.

It works with other C language features or Rust language features or coding style policies or anything else. What makes you think policies about acceptable C++ features are different? Just because of "arguing over and over again"? Why is arguing over C++ features different? Bikeshedding discussions have existed as long as Linux exists, and will always exist. This argument seems rather arbitrary, because you can use the same argument to reject C11, C17, Rust (or anything else).

> The C implementation might not be as pretty as C++

Agree. We don't agree on the rest, but that's fine.

Scope-based resource management for the kernel

Posted Jun 22, 2023 18:55 UTC (Thu) by mb (subscriber, #50428) [Link] (6 responses)

>You're missing the point.

No. But you didn't read my full text, before answering on the first paragraph.

>What makes you think policies about acceptable C++ features are different?

So you really think that inheritance and virtual functions would not be one of the first next C++ features that people would demand, if we would compile the kernel with a C++ compiler?

Converting all manual implementations of virtual function calls is the next obvious transistion we would have.
And there goes your same code flow.

Scope-based resource management for the kernel

Posted Jun 22, 2023 19:07 UTC (Thu) by make (subscriber, #62794) [Link] (3 responses)

> No. But you didn't read my full text, before answering on the first paragraph.

Oh yes, you were missing the point, because instead of replying to the point I made (about RAII), you made up a new story and replied to this story of yours.

Now you came up with a new story, this time about virtual functions, only to prove that code flow in C++ and Rust is different after all, but that again misses my point. Don't you get it? This article and this thread is about RAII and nothing else.

Scope-based resource management for the kernel

Posted Jun 22, 2023 19:19 UTC (Thu) by mb (subscriber, #50428) [Link] (2 responses)

>only to prove that code flow in C++ and Rust is different after all

Nice that you agree.

Scope-based resource management for the kernel

Posted Jun 22, 2023 19:35 UTC (Thu) by make (subscriber, #62794) [Link] (1 responses)

> Nice that you agree.

No, I don't agree. Virtual functions don't affect the code flow; they are just syntactic sugar for dynamic dispatch, but the code flow is the same as with other ways of doing dynamic dispatch (no matter if C++, C or Rust). But, uh, we're now even more off-topic, you're dragging me away from the topic (=RAII) so much, that I'm confident you're just a troll, and I've already been feeding you too much, shame on me. That was unexpected on LWN.

Scope-based resource management for the kernel

Posted Jun 22, 2023 19:41 UTC (Thu) by mb (subscriber, #50428) [Link]

>but the code flow is the same as with other ways of doing dynamic dispatch (no matter if C++, C or Rust).

No it isn't.

Scope-based resource management for the kernel

Posted Jun 22, 2023 20:51 UTC (Thu) by marcH (subscriber, #57642) [Link] (1 responses)

> So you really think that inheritance and virtual functions would not be one of the first next C++ features that people would demand, if we would compile the kernel with a C++ compiler?

Of course it would; implementing classes in C is not fun at all and it's done all over the kernel already: https://lwn.net/Articles/444910/

BTW I suspect this is another reason people want to keep C++ out: Object-Oriented Obfuscation. There are some problems to which object-orientation maps well but C++ went really "all-in" and kept functional programming techniques out of developers' mindsets for much too long of a time, holding back the entire industry for decades.

Funny how Javascript out of all languages helped functional programming finally break out.

Rust is of course more functional than OO.

Scope-based resource management for the kernel

Posted Jun 22, 2023 21:02 UTC (Thu) by marcH (subscriber, #57642) [Link]

> There are some problems to which object-orientation maps well but C++ went really "all-in" and kept functional programming techniques out of developers' mindsets for much too long of a time, holding back the entire industry for decades.

Forgot the mandatory reference to the masterpiece, sorry for the extra email:

http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html

Yes this one is not about C++ but Java which is even worse. But: close enough.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds