News for hackers. Stuff that matters.
Re:Rust support in the Linux kernel by einpoklum on Wednesday December 08, 2021 @03:25PM (#29490021)
From the perspective of people who don't know Rust, it's not a sweet nectar, but a suspicious murky liquid.

From the perspective of people who don't like aspects of Rust, it's a yucky goo.

This is _not_ like with C. Few people are enamored with C, but - the language itself is relatively simple (Duff's device notwithstanding...), so in my analogy it's like water. You may not adore it, but you can see through it, and you'll be ok with gulping it down to quench your thirst.

Re:Rust support in the Linux kernel by nicoburns on Wednesday December 08, 2021 @03:57PM (#29490394)
> From the perspective of people who don't like aspects of Rust, it's a yucky goo. > This is _not_ like with C

I beg to differ. This is exactly how I feel about C. C is the language that's confusing as hell to read for anything other than really simple use cases AND makes it super easy for me to shoot myself in the foot.

Re:Rust support in the Linux kernel by b20000 on Wednesday December 08, 2021 @08:16PM (#29492676)
C is what you program is what you get. and i think that is pretty important.
Re:Rust support in the Linux kernel by kungito on Thursday December 09, 2021 @02:40AM (#29494842)
This is true for any programming language. The problem is being aware of what you really wrote
Re:Rust support in the Linux kernel by b20000 on Thursday December 09, 2021 @12:01PM (#29499872)
No, you are wrong. C++ is one example. I've been using that language now for about 20 years and I still don't use all of its features. It is possible to write code in that language that you assume will work a certain way but then in practice it does a lot of things you didn't think you signed up for. Recently I started using STL more, after having stayed away from it for most of my career, and the performance of my application went out the window, and I had to override all memory allocation related functions to fully understand where the problem was coming from. It's easy to use the STL and make assumptions about performance, then find out later you get a lot of issues that come with it that you never signed up for. And that is why I don't want rust in the kernel. If a language does a lot of stuff for you, there will be a price to pay.
Re:Rust support in the Linux kernel by nicoburns on Thursday December 09, 2021 @01:09PM (#29500826)
> It is possible to write code in that language that you assume will work a certain way but then in practice it does a lot of things you didn't think you signed up for

This is also possible for C. Most commonly around Undefined Behaviour. C only does what you expect it to do if you know the C spec inside out. Rust can have confusing behaviour too, but it is generally much better in this regard than C or C++.

You may find it easier to reason about C than Rust, but that's only because you know C better. I find it much easier to reason about Rust.

Re:Rust support in the Linux kernel by einpoklum on Thursday December 09, 2021 @02:50AM (#29494898)
With modern compilers, there is no such thing as what you program is what you get.
Re:Rust support in the Linux kernel by randomswede on Thursday December 09, 2021 @07:13AM (#29496480)
As long as you stay away from compiler-dependent, platform-dependent, and/or undefined behaviour, you should be fine. Main problem is that a surprising ab´mount of "looks normal" code is actually UB.
Re:Rust support in the Linux kernel by einpoklum on Friday December 10, 2021 @03:46AM (#29507805)
You would be "fine", but the compiler will optimize away alot of your code, and will rearrange a lot of the rest. I wasn't even talking about platform-dependent or undefined behavior.
Re:Rust support in the Linux kernel by pjmlp on Thursday December 09, 2021 @02:28AM (#29494797)
C is what you program is what you might get.

Know thy standard and thy compiler optmizations, least you be surprised by the outcome.

Re:Rust support in the Linux kernel by merb on Wednesday December 08, 2021 @04:27PM (#29490753)
> Few people are enamored with C, but - the language itself is relatively simple

if you don't use pointers, yeah. but like you can't built anything useful without pointers.

Re:Rust support in the Linux kernel by b20000 on Wednesday December 08, 2021 @08:15PM (#29492672)
if you do not understand pointers and cannot work with them, you probably should not be a software engineer.
Re:Rust support in the Linux kernel by danShumway on Thursday December 09, 2021 @12:06AM (#29494035)
I'm not sure that it's the concept of pointers that make C code harder to maintain than other languages. Lots of languages have pointers, including Rust.

It's a question of whether unguarded pointers (and a lack of language features that keep pointer math from devolving into an unreadable mess) are good to have in areas where pointer errors can result in critical bugs. We started discouraging goto statements not because developers didn't understand them, but because they did understand them, and they understood that the tools you use influence the type of code you write. And Rust doesn't even really get rid of pointers, it just adds rules around them.

We all accept some degree of abstraction/safety tradeoff, otherwise we'd program in lower-level languages than C that are even simpler and even easier to understand. C does introduce a lot of complexity over more primitive assembly languages. And Rust introduces a lot of complexity over C.

Different people pick different points where they think the tradeoffs are optimized. But we have a pretty large amount of data suggesting that even <quote>good</quote> programmers in industry make pointer errors in C. So it's pretty obviously not lack of understanding that's causing these issues, it's that unrestricted memory access and pointer math is inherently error-prone. Whether it's SO error-prone that's it's worth introducing a much more complicated, rigid language into the kernel is left as an exercise for the reader. There is a downside to introducing more complexity here, all abstractions have downsides.

But it's real dismissive to say that if everyone understood C pointers then their code wouldn't ever devolve into an unreadable mess. I just don't think that's an opinion that can be backed up by any real evidence, pretty much every org struggles to some extent with writing secure C code. And we have a lot of experience in the field of software engineering that should have taught us by now that sometimes unreadable code is the result of language affordances and patterns.

Re:Rust support in the Linux kernel by afiori on Thursday December 09, 2021 @04:31AM (#29495437)
Also there are many different ways to undestand and use pointers; there are many many programmers that are really good at using pointers and are able to engineer essentially safe architechtures, but many of those very good programmers would come up with incompatible architectures around pointer usage.

My wild guess is that most "simple" pointer errors (use-after-free, double-free, unintentionally using unitialized memory, ...) happens at interfaces where there isn't perfect comunication about what component is responsible for keeping track of each task.

Re:Rust support in the Linux kernel by danShumway on Thursday December 09, 2021 @12:19PM (#29500161)
Yeah, I think about a very offhand comment that Carmack made once that ended up resonating with me a lot, even though I don't think it's universally across the entire board true:

> "Most bugs are a result of the execution state not being exactly what you think it is."

There is an aspect of language design that is about making it hard to be surprised by things. And I vaguely suspect that a lot of pointer errors fall into this category; people assume something is being freed, they assume that a subroutine is cleaning up after itself or that it's not manipulating something, or that it doesn't need to call some setup method before it's run. These are boundary errors between interfaces where allowing users to (inadvertently) mask what is happening can lead to logic that feels very convoluted and hard to follow, and can also lead to simple errors around just forgetting to do stuff.

I wouldn't call that Carmack quote a mantra, I'm not saying it explains all programming (or that all architectural restrictions are good), it's just a lens that I keep coming back to when I think about language design and architecture; there's a real tradeoff in removing flexibility, but there is also a huge amount of value in systems/patterns that make it very hard to bury relevant information. And if a language can auto-surface some of those problems, that can lead to cleaner code.

Re:Rust support in the Linux kernel by viraptor on Thursday December 09, 2021 @07:09AM (#29496460)
It depends what level you mean. Understanding and using pointers on basic way is simple. Understanding pointer provenance, aliasing rules, etc. are a completely different level and people not very familiar with the spec (so almost everyone) do not understand a lot about pointers. http://open-std.org/JTC1/SC22/WG21/docs/papers/2019/p1434r0....