News for hackers. Stuff that matters.
Re:Google says replacing C/C++ in firmware with Rust is easy by jay-barronville on Saturday September 07, 2024 @09:40PM (#41477586)
As someone who writes, reviews, and maintains lots of C code professionally, here’s what I think a lot of Rust advocates don’t understand: We see and understand the benefits of Rust. That’s no longer something we need to be sold on. Every C programmer who’s written and reviewed any amount of nontrivial C code likely has firsthand experience dealing with memory safety bugs that would simply disappear with a memory-safe language.

The ultimate problem is that most of the muscle memory you’ve built using C over the years becomes useless when writing Rust due to so many of the semantic differences. If you were an expert and highly productive C programmer, your productivity will go out the window for what feels like a long time until you feel even just comfortable writing Rust. That makes Rust a very hard sell for C programmers who simply want to get things done. This is an area, by the way, that I think Zig does extremely well at—it provides safer semantics (despite its lack of guaranteed memory safety à la Rust) in a rather simple language and without rendering so much of your experience useless.

Re:Google says replacing C/C++ in firmware with Rust is easy by pveierland on Saturday September 07, 2024 @10:23PM (#41477766)
Having written quite a bit of C++ firmware and just now spending a few weeks getting into Rust, I have to say the learning curve was less challenging than I thought it would be, and that I feel pretty effective after a short amount of time. The feeling of how sturdy the program is after getting the additional compiler support during development feels very reassuring.

Already at this point I'm hoping that I never need to write C++ again, as the complexity of the language is maddening and only increasing.

(I've only spent a few days on Zig and it was also a very fresh breeze).

Re:Google says replacing C/C++ in firmware with Rust is easy by MBCook on Saturday September 07, 2024 @11:36PM (#41478015)
My question would be is the learning curve better or worse than, say, Swift?

If the curve is small moving from A to B can make a lot of sense. Rust is an obvious possible successor.

But as the curve gets bigger maybe looking at less obvious choices makes more sense. Maybe even a language with a runtime or VM like Java if you’re not doing low level programming like Google is in this post.

Swift is a strawman here. I know it’s probably not there for large non-Apple adoption today, but pretend it was

Re:Google says replacing C/C++ in firmware with Rust is easy by redman25 on Saturday September 07, 2024 @11:59PM (#41478117)
Rust can be written simply if you avoid more complicated features of the language. It depends on what you want to get out of it.

If you want to develop a library, you might have to dig into more complicated features in order to provide a convenient interface for users.

If you want to build an API, using a web framework is simple and doesn’t require understanding the more complicated parts of the language.

Re:Google says replacing C/C++ in firmware with Rust is easy by pveierland on Saturday September 07, 2024 @11:56PM (#41478107)
I wouldn't be able to answer for Swift as I don't know it. However Rust would seem to be a suitable replacement for all use-cases of C++ in an embedded context that I was involved with (including allocation control + static initialization + macro usage).
Re:Google says replacing C/C++ in firmware with Rust is easy by csomar on Saturday September 07, 2024 @11:14PM (#41477949)
So you are saying we should stick to the status quo because, otherwise, some C developers have to adapt and might lose their competitive advantage because of it?
Re:Google says replacing C/C++ in firmware with Rust is easy by jay-barronville on Saturday September 07, 2024 @11:42PM (#41478049)
> So you are saying we should stick to the status quo because, otherwise, some C developers have to adapt and might lose their competitive advantage because of it?

Can you point me to where I said or suggested any of that?

Re:Google says replacing C/C++ in firmware with Rust is easy by nixpulvis on Saturday September 07, 2024 @10:15PM (#41477732)
Could you give an example of how Zig is more C-like for the seasoned C developer?

Rust generally has a lot of what C has, you just might need unsafe to get it.

One notable omission is `volatile` but that sorta beside the point.

If the concern is just relearning a new STD lib and getting used to error handling with an enum instead of ints, then I suspect you could get up to speed pretty quickly.

Past that, sure the rust crate ecosystem might make use of a lot more complex bits of rust, just like C++ libraries can do wild things with templating.

If you are just comparing C, just avoid the complex stuff and write your Rust function like you write your C functions. It’ll work.

Re:Google says replacing C/C++ in firmware with Rust is easy by wtetzner on Saturday September 07, 2024 @11:15PM (#41477955)
Re:Google says replacing C/C++ in firmware with Rust is easy by bschwindHN on Saturday September 07, 2024 @10:53PM (#41477874)
> One notable omission is `volatile` but that sorta beside the point.

What do you mean here?

Re:Google says replacing C/C++ in firmware with Rust is easy by nixpulvis on Sunday September 08, 2024 @12:10AM (#41478152)
Re:Google says replacing C/C++ in firmware with Rust is easy by bschwindHN on Wednesday September 11, 2024 @11:08AM (#41512083)
I see, thanks!
Re:Google says replacing C/C++ in firmware with Rust is easy by ycombinatrix on Saturday September 07, 2024 @11:47PM (#41478072)
Rust doesn't require nearly as much muscle memory as C.
Re:Google says replacing C/C++ in firmware with Rust is easy by dwattttt on Saturday September 07, 2024 @09:54PM (#41477650)
Speaking as someone who has written C skirting both sides of the UB line & referenced the spec to see when something tipped too far over said line... The fear that I'd be less productive for a "long" time was quite overblown.

Rust hasn't replaced all the C I write, why should it? It's replaced lots of C I wrote around the periphery of the hairiest stuff, and frankly done it better than the C I might otherwise have written there.

Re:Google says replacing C/C++ in firmware with Rust is easy by jay-barronville on Saturday September 07, 2024 @10:02PM (#41477688)
> The fear that I'd be less productive for a "long" time was quite overblown.

I’m genuinely glad that was your experience!

I actually would love for more C programmers to have that same experience (or better), but my own experience with Rust and the experiences of many of my colleagues is that going from C as someone who’s productive with it to Rust entails at least a couple months just to get comfortable with the language and its semantics.

One could argue that spending that time is worth it for the memory safety benefits and I’d probably agree, but I’m just pointing out that it’s a pretty hard sell for many C programmers.

Re:Google says replacing C/C++ in firmware with Rust is easy by nixpulvis on Saturday September 07, 2024 @10:19PM (#41477751)
Who are these C programmers who are a hard sell on this? Any C programmer who knows how to write working code knows a lot of Rust’s rules implicitly because they have to deal with it manually!

What C programmer hears, “you can heap allocate without a GC and the compiler will place frees for you” and thinks, gosh… this sounds irritating?

Or what C programmer hears, “we make using multiple mutable references to the same data at the same time something only unsafe rust can do” and thinks, gosh… I do that all the time, and I have no issues?

I think the bigger issue is convincing people it’s worth the energy and risk to port existing, working, and tested C code.

Re:Google says replacing C/C++ in firmware with Rust is easy by charleslmunger on Saturday September 07, 2024 @10:32PM (#41477799)
>What C programmer hears, “you can heap allocate without a GC and the compiler will place frees for you” and thinks, gosh… this sounds irritating?

People who still use C rather than C++, which has this exact feature?

https://open.substack.com/pub/ryanfleury/p/untangling-lifeti...

Re:Google says replacing C/C++ in firmware with Rust is easy by xelamonster on Saturday September 07, 2024 @10:37PM (#41477815)
Did you make it to the end of that section you linked? It's pretty clear on Rust having significant advantages here still:

"This, of course, does not eliminate all possible bugs (misuse is still possible, and often not checkable in a language like C++)—so, this idea is often paired in newer languages with heavier (and more complex) compile-time checking features, which attempt to both automate this code generation, and prohibit misuse."

Re:Google says replacing C/C++ in firmware with Rust is easy by jmaker on Monday September 09, 2024 @02:40AM (#41486006)
I feel like most discussions touching on Rust revolve around the same lines - one person says they don’t want to use Rust (for whatever reason), a proponent starts regurgitating the selling points, the former feels misunderstood (because that all has been heard many times before), the latter snubs at taking the former as being stubborn.

I’ve been through my Rust hype phase, and I’ve been through thoughtfully applying it for web services and a greenfield messaging broker, albeit nothing systems level. With a decade or so C++ behind the belt, I don’t feel an app team is necessarily more productive over the lifecycle of the project if they pick Rust over C++, much less so if they pick it over Java.

I’ve been doing mostly low-latency JVM projects. I can extract better performance from a JVM and a given infrastructure than from Rust. Ease of development and the option to delegate the lifetimes to the GC, or just get a huge heap, is often the escape hatch you need to make through the tight deadline.

In Rust, you need just one “smart” colleague to make the project unmaintainable - wasting everyone’s time on optimizing the type signatures making it thereby impenetrable to anyone outside the team, or easy to forget the derivation a few months later on.

There was a nice suggestion on HN somewhere to distinguish between an area beneficial particularly to Rust (slow pace, settled architecture, more low-level) as opposed to the area with fewer fruits to reap for Rust where other semantics prevails.

Re:Google says replacing C/C++ in firmware with Rust is easy by xelamonster on Monday September 09, 2024 @08:27PM (#41495879)
Good points, the JVM is absolutely underrated these days imo and Rust won't always be a strictly better choice especially for established teams. From what I see though a lot of this repetitive back-and-forth starts with somebody saying that they personally prefer Rust or simply describing its advantages over other languages from their perspective, and every time there's backlash from people responding as if the author were trying to personally force them into using Rust in their own projects.

I think it's great that you can build solid projects efficiently in C++ or Java! People should be free to choose whatever works best for them; as someone who does love Rust I'm of course happy to see it gaining traction, but if the flavor of the month were to suddenly change I don't think I'd feel the need to go out of my way trying to tear the new thing down.

Re:Google says replacing C/C++ in firmware with Rust is easy by charleslmunger on Thursday September 12, 2024 @05:12PM (#41525635)
The real argument from that piece is that heap allocation is something to be avoided, and there are alternatives to malloc/free pairs. There are other benefits, but specifically having the compiler insert lots of frees is not one of them, for developers that prefer arena memory management for efficiency, simplicity, organization, and cache behavior.

In fact, there are lots of arena/bump allocator crates! It's not a negative point for Rust, but it solves a problem this author doesn't have.

Re:Google says replacing C/C++ in firmware with Rust is easy by jay-barronville on Saturday September 07, 2024 @11:40PM (#41478033)
> What C programmer hears, “you can heap allocate without a GC and the compiler will place frees for you” and thinks, gosh… this sounds irritating?

>

> Or what C programmer hears, “we make using multiple mutable references to the same data at the same time something only unsafe rust can do” and thinks, gosh… I do that all the time, and I have no issues?

Those are some nice strawmans, but ignoring the fact that this type of response very clearly goes against HN’s guidelines, I think it’d be great if you addressed the point I actually made instead of your own.

Also, I’d like to make it clear that you’re perfectly entitled to believe this problem I highlighted doesn’t exist and is somehow a figment of my imagination. I’m just sharing my perspective and experience. You’re free to take it or leave it.

Re:Google says replacing C/C++ in firmware with Rust is easy by nixpulvis on Sunday September 08, 2024 @12:14AM (#41478164)
Your point was that some developers you know would spend months getting comfortable with the language and semantics.

My point is, most of them already know a lot of the semantics. It’s the semantics they keep in their head while trying to be safe in C!

As for the HN guidelines. Sorry if you felt like I crossed a line. Never my intention.

Re:Google says replacing C/C++ in firmware with Rust is easy by jay-barronville on Sunday September 08, 2024 @02:50AM (#41478655)
> As for the HN guidelines. Sorry if you felt like I crossed a line. Never my intention.

I didn’t feel like you crossed a line—according to the HN guidelines [0], you very clearly crossed a line.

You responded with snarky strawmans instead of responding, in good faith, to the actual point I made.

To quote the guidelines:

> Be kind. Don't be snarky. Converse curiously; don't cross-examine. Edit out swipes.

> Please respond to the strongest plausible interpretation of what someone says, not a weaker one that's easier to criticize. Assume good faith.

[0]: https://news.ycombinator.com/newsguidelines.html

Re:Google says replacing C/C++ in firmware with Rust is easy by jay-barronville on Sunday September 08, 2024 @03:24AM (#41478777)
> Your point was that some developers you know would spend months getting comfortable with the language and semantics.

>

> My point is, most of them already know a lot of the semantics. It’s the semantics they keep in their head while trying to be safe in C!

The most fascinating aspect of interactions like these is that I’m literally sharing the real life experience shared by myself and my colleagues, and you’re just like, “Nope, that’s not the case!”

Well, thanks…I guess I have nothing else to add to this discussion then.

Re:Google says replacing C/C++ in firmware with Rust is easy by dwattttt on Sunday September 08, 2024 @04:56AM (#41479101)
There were quite a few times when patterns I expected to work were forbidden, but each time I learned why I learned something important (can't iterate a list of callbacks and pass a mutable reference of the list in? Iterator invalidation lesson incoming).
Re:Google says replacing C/C++ in firmware with Rust is easy by mplanchard on Sunday September 08, 2024 @11:04AM (#41480834)
I think it’d be interesting to see improvements to the ergonomics of unsafe rust (which already offers a lot of safety improvements over C), such that it becomes an easier on-ramp for experienced C programmers. Something to allow you to write Rust that feels more C-like while you get used to the language.
Re:Google says replacing C/C++ in firmware with Rust is easy by empath75 on Saturday September 07, 2024 @09:41PM (#41477591)
This is a problem that will resolve itself with time as C developers retire and new projects start in Rust.
Re:Google says replacing C/C++ in firmware with Rust is easy by doe_eyes on Saturday September 07, 2024 @09:49PM (#41477624)
C is 52 years old; C++ is nearly 40. That's more than a generation. Yet, I'd bet that there are more up-and-coming developers learning C/C++ than Rust today.

The problem isn't just personal preference or inertia. It's that all mainstream OSes, libraries, and system software are written in C/C++. You can't exactly ignore this and not learn the language if you want to work in this space.

Of course, there are many developers who don't work with system-level stuff, and they may be perfectly fine just knowing Java or JavaScript, but Rust is not positioning itself as a direct competitor to that.

Re:Google says replacing C/C++ in firmware with Rust is easy by MBCook on Saturday September 07, 2024 @11:38PM (#41478025)
The world has lots of important COBOL. You’re dead on. Even if everyone committed to all new code in Rust tomorrow, C/C++ will be around for a LONG time.

There’s just too much pre-existing code.

Re:Google says replacing C/C++ in firmware with Rust is easy by xelamonster on Saturday September 07, 2024 @10:33PM (#41477802)
How is "too much existing software uses C/C++" not just inertia? That can also change with time.
Re:Google says replacing C/C++ in firmware with Rust is easy by doe_eyes on Sunday September 08, 2024 @01:13AM (#41478334)
Inertia is doing things because you're used to doing them. This is pragmatism: until the arrival of mainstream Rust-based OSes, there's probably no escaping C/C++.
Re:Google says replacing C/C++ in firmware with Rust is easy by xelamonster on Sunday September 08, 2024 @03:11PM (#41482405)
My point is that the arrival of Rust-based OSes is absolutely in the cards, so while I don't disagree that it would be very difficult to fully escape at the moment that is also actively changing.
Re:Google says replacing C/C++ in firmware with Rust is easy by jay-barronville on Saturday September 07, 2024 @09:52PM (#41477638)
> This is a problem that will resolve itself with time as C developers retire and new projects start in Rust.

Respectfully, this is wishful thinking.

C programmers aren’t going anywhere any time soon. There are millions upon millions upon millions lines of C code everywhere running critical software, firmware, infrastructure, etc. that won’t be rewritten in Rust any time soon.

Re:Google says replacing C/C++ in firmware with Rust is easy by mav3ri3k on Saturday September 07, 2024 @10:34PM (#41477807)
From my perspective (college student), it is true that there is godly amount of C code in the world which would remain true for a long long time. In similar sense there are also quite a lot of new java developers who maintain the millions of lines of java code.

However a lot of new infrastructure is being developed in rust. Infact it can be argued that the very reason it should be in rust is because it is critical. I think there would be great value if a person can efficiently thread between both rust and c rather than competing.

Re:Google says replacing C/C++ in firmware with Rust is easy by MBCook on Saturday September 07, 2024 @11:43PM (#41478053)
Java is not an old “maintain the code” language as you seem to imply. Despite not being the new hotness for about 25 years it’s an extremely useful and productive language and I assure you there are tons and tons of new things being written in it every day. The language is still evolving and has been getting great improvements. Yeah it has some warts, but it’s been running and keeping backwards compatibility for 30 years despite evolving.
Re:Google says replacing C/C++ in firmware with Rust is easy by pjmlp on Sunday September 08, 2024 @12:44PM (#41481395)
Many seem to forget all the time, that the Java ecosystem powers the most widely sold mobile OS platform across the globe.
Re:Google says replacing C/C++ in firmware with Rust is easy by MBCook on Monday September 09, 2024 @04:47PM (#41493583)
Including me! I was referring to server stuff, since server side Java is my job and thus front of mind.

But you’re dead right. At this point Android apps may be the bigger set of code. Or at least put up a good fight.

[dead]
Re:Google says replacing C/C++ in firmware with Rust is easy by MBCook on Saturday September 07, 2024 @11:45PM (#41478066)
The entire graphics driver for Apple Silicon Macs in Linux, with zero memory bugs in the code despite being deployed to a large number of machines. including a fully conformant OpenGL implementation and most/all of Vulkan (I’ve lost track of the current state).
Re:Google says replacing C/C++ in firmware with Rust is easy by jay-barronville on Sunday September 08, 2024 @03:40AM (#41478829)
> Infact it can be argued that the very reason it should be in rust is because it is critical. I think there would be great value if a person can efficiently thread between both rust and c rather than competing.

I fully agree with that.

Re:Google says replacing C/C++ in firmware with Rust is easy by lenkite on Sunday September 08, 2024 @04:51AM (#41479090)
There are a ridiculous number of greenfield Java projects being started every day. Far more than Rust by orders of magnitude.
Re:Google says replacing C/C++ in firmware with Rust is easy by j-krieger on Sunday September 08, 2024 @02:05AM (#41478496)
> The ultimate problem is that most of the muscle memory you’ve built using C over the years becomes useless when writing Rust due to so many of the semantic differences

The horror. Lest someone make an argument that to earn a salary, you have to put in hard work.

Re:Google says replacing C/C++ in firmware with Rust is easy by jay-barronville on Sunday September 08, 2024 @03:36AM (#41478814)
> The horror. Lest someone make an argument that to earn a salary, you have to put in hard work.

To quote the HN guidelines [0]:

> Be kind. Don't be snarky. Converse curiously; don't cross-examine. Edit out swipes.

> Please respond to the strongest plausible interpretation of what someone says, not a weaker one that's easier to criticize. Assume good faith.

[0]: https://news.ycombinator.com/newsguidelines.html

Re:Google says replacing C/C++ in firmware with Rust is easy by j-krieger on Sunday September 08, 2024 @06:08AM (#41479432)
You're correct. A slip of etiquette.
Re:Google says replacing C/C++ in firmware with Rust is easy by mplanchard on Sunday September 08, 2024 @11:01AM (#41480823)
Rust interoperability with C is excellent, way easier than with C++, which is also pretty easy.

I think if you’re a good C programmer you’ll naturally be a good Rust programmer, and come up to speed faster than you expect.

There’s nothing forcing you to write everything with traits, generics, etc. You can write simple, fast, safe Rust without them.

Edit: read some of your other comments and realize this doesn’t quite address your point, but I do still think that writing small sections of logic in simple, straightforward Rust and then calling that from C is a nice way to get started. Doing so for places where ownership is complicated and the compiler can help enforce invariants can provide I think a meaningful ergonomic gain in a C codebase.

Re:Google says replacing C/C++ in firmware with Rust is easy by pornel on Sunday September 08, 2024 @02:46PM (#41482234)
Productivity tanks only temporarily.

I know that writing your first 10 lines of Rust code will give you 15 novel compile errors, and that feels like it's impossible to get anything done in Rust, but once you get over the hump, you get to use a very productive modern language that can be as low-level as C, and almost as high-level as Python, at the same time.

You will not regret leaving behind the muscle memory for all the preprocessor tricks, workarounds for gratuitous platform differences and 40-year-old footguns, all the trivia for old compilers, the never ending tweaking of snowflake build scripts, and the skill of writing yet another half-assed hash table with your eyes closed. You'll wonder how you ever got anything done in a language that kept you busy calculating malloc sizes by hand.