|
|
Subscribe / Log in / New account

WHAT?

WHAT?

Posted Aug 31, 2024 3:30 UTC (Sat) by mikebenden (guest, #74702)
In reply to: WHAT? by roc
Parent article: Rust-for-Linux developer Wedson Almeida Filho drops out

> starting with a strong C++ background and some knowledge of the ideas of Rust, but never having written any Rust code, I was productive with Rust in under a week

You're the second data point (along with Cyberax elsewhere in the comments) who brings up "strong C++ background" as a precondition for "easily picking up Rust". That does make a lot of sense, actually.

As a C programmer with a good working familiarity on kernel and low level topics, I see both C++ and Rust as something that would take a LOT of getting used to, they are both heavily resistant to casual lecture of sources one didn't spend a lot of time and thought writing themselves :)

I don't see "know c++ well" as an obvious required skill for a kernel hacker, so the point that kernel hackers in general would all have to take lengthy detours in order to pick up Rust still stands (unless they're already C++ experts, which would help, but presuming they are is unreasonable, because they're *kernel* hackers, not high-level code monkeys :)


to post comments

WHAT?

Posted Aug 31, 2024 4:17 UTC (Sat) by roc (subscriber, #30627) [Link]

You don't need to know C++ well to understand Rust. There is a huge amount of C++ machinery that is irrelevant to Rust (e.g. inheritance, overloading, advanced templates (SFINAE), exceptions). OTOH some things do carry over like move semantics (much simpler in Rust though), smart pointers, RAII, abstract base classes (similar to Rust traits), and template member types (Rust associated types).

Then there are other concepts like ownership and lifetimes that are central to Rust that actually exist in C++ (and C) but the language doesn't let you write them down.

So it's not so much that I'm a strong C++ programmer but that I've spent a lot of time working with large C and C++ programs, which means I already had to internalize many of the concepts of Rust and also appreciate its benefits.

WHAT?

Posted Aug 31, 2024 4:30 UTC (Sat) by roc (subscriber, #30627) [Link] (1 responses)

> so the point that kernel hackers in general would all have to take lengthy detours in order to pick up Rust still stands

The thing is, most of what people fear about Rust is already stuff you have to think about in C in the kernel, you just can't write it down. You have to think about ownership (who is responsible for freeing each thing in memory) and how that is transferred. You have to think about borrowed references (i.e. pointers) and lifetimes. You have to think about whether the data you're referencing is immutable or could change behind your back. Rust traits are very much like the manual vtables of file_operations etc. Rust's Result just codifies the distinction between normal results and error result. Rust's Option just lets you write down "this could be null".

I think probably the biggest issue is going to be Rust's generic type system. It's easy to understand how Rust types like Vec<T> are similar to void*-based generic data structures in C (e.g. radix-tree), but in practice there's a lot more value and it takes a bit of experience to use well, especially when you're designing APIs.

Learning Rust vs C

Posted Aug 31, 2024 14:28 UTC (Sat) by kleptog (subscriber, #1183) [Link]

Anecdotally, for the junior developers I've had to help, Rust was way easier than C. C was just giving them segfaults all the time, because lifetimes and mutability are things you have to care about but C doesn't help you. When they were writing Rust however, the compiler basically trained them to think about these things, and how to structure programs while keeping object lifetimes in mind.

The end result is that after this experience with Rust, they can actually do C ok because they know what they need to look out for.

Why not C++? Well, because they needed to write things that worked with various C libraries, and C++ doesn't help you at all there, unless someone has written a C++ wrapper for those libraries. Fortunately, someone had written Rust wrappers for these libraries and cargo managed all the dependencies and installation. Managing C++ library dependencies is disaster in itself.

WHAT?

Posted Sep 1, 2024 1:49 UTC (Sun) by roc (subscriber, #30627) [Link] (1 responses)

Another datapoint, my son (second year university student) has been learning Rust and was able to produce useful code within a couple of weeks of work. He's smart but has very little C or C++ background. I answered a couple of his questions but didn't hold his hand. https://github.com/scrying-circle/nofi/blob/main/rust/src... Not the greatest Rust code, but not too bad. He felt the initial learning curve was steep but he feels like he's already surmounted it.

Learning Rust versus learning C

Posted Sep 1, 2024 9:29 UTC (Sun) by farnz (subscriber, #17727) [Link]

Ancedotally, one of the biggest things I see beginner programmers get wrong is the difference between "this code is correct" and "this code works for the test cases I give it on my machine". In this regard, C is a really painful language for beginners, because you can write code that is semantically meaningless C (IFNDR, UB etc), but that happens to work for the test cases the beginner gives it on their machine.

A language that enforces more rules is, paradoxically, easier for a beginner, because the enforcement means that the code does not work for the test cases they give it on their machine - it does not compile and run on their machine, so they have to fix it.


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