Rust NYC: Jon Gjengset - Demystifying unsafe code
Rust Programming Language2 HN recommenders · recommended in 2 months, 2020–2024
talk · intermediate · evergreen · 2020–2024 on HN
Jon Gjengset's Rust NYC talk explaining what `unsafe` in Rust actually means, why it is dangerous, and why it is sometimes necessary. He works through the Rustonomicon to separate fair concerns from overblown ones.
HN recommends it as the best calm explanation of unsafe Rust, from a speaker commenters trust on the topic.
Up next
6 mo on HNGtk to Qt - a strange journey [linux.conf.au 2014]
Konstantin Bläsi
5 HN recommender · 2014–2024
9 mo on HNLISA11 - Fork Yeah! The Rise and Development of illumos
USENIX
9 HN recommender · 2012–2026
10 mo on HNWhy Your Vote Doesn't Count
CGP Grey
10 HN recommender · 2015–2025
8 mo on HNOnce you understand game theory, you understand the world.
Veritasium
10 HN recommender · 2023–2026
11 mo on HNCppCon 2015: Andrei Alexandrescu “std::allocator...”
CppCon
7 HN recommender · 2017–2025
12 mo on HNLexical Scanning in Go - Rob Pike
GoogleFOSSSydney
13 HN recommender · 2012–2025
10 mo on HNCppCon 2017: Matt Kulukundis “Designing a Fast, Efficient, Cache-friendly Hash Table, Step by Step”
CppCon
9 HN recommender · 2018–2026
9 mo on HNRustConf 2018 - Closing Keynote - Using Rust For Game Development by Catherine West
Rust Programming Language
9 HN recommender · 2018–2023
10 mo on HNCppCon 2016: Jason Turner “Rich Code for Tiny Computers: A Simple Commodore 64 Game in C++17”
CppCon
13 HN recommender · 2016–2024
9 mo on HNIdeas about a new programming language for games.
Jonathan Blow
7 HN recommender · 2014–2025
9 mo on HNCppCon 2014: Mike Acton "Data-Oriented Design and C++"
CppCon
9 HN recommender · 2015–2026
9 mo on HNHow I program C
Eskil Steenberg
8 HN recommender · 2017–2025
3 comments from Hacker News
While I might agree that it's easy if you use a reference counter, this is not going to be as performant as the typical linked list written in C, which is why the standard library uses unsafe for its implementation of stuff like this. If it were "easy" to just write correct `unsafe`, then it would be easy to do it in C as well. Note that the converse to this isn't necessarily true! People I trust way more to write unsafe Rust code than me than me have argued that unsafe Rust can be harder than writing C in some ways due to having to uphold certain invariants that don't come up in C. While there are a number of blog posts on the topic that anyone interested can probably find fairly easily by googling "unsafe Rust harder than C", I'll break my usual rule of strongly preferring articles to video content to link a talk from youtube because the speaker is one of those people I mention who I'd trust more than me to write unsafe code and I remember seeing him give this talk at the meetup: ▶ this video
There's a great new talk by on Gjengset on youtube that tackles just this question: Rust NYC: Jon Gjengset - Demystifying unsafe code ▶ this video
The rustnomicon is a very good resource. It's less of "the unsafe book" and more "the advanced book", covering lower-level details and advanced concepts that aren't touch on by the book. One gripe I have is that it kind of pushes the idea that unsafe is bad and evil, which is not true at all: > The Dark Arts of Unsafe Rust > THE KNOWLEDGE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF UNLEASHING INDESCRIBABLE HORRORS THAT SHATTER YOUR PSYCHE AND SET YOUR MIND ADRIFT IN THE UNKNOWABLY INFINITE COSMOS. I know it's a joke, and I laughed when I first read it. Unsafe is dangerous and requires care, but unsafe == evil is definitely not true. Jon Gjengset said it well in "Demystifying Unsafe Code" [0]: > One thing I keep observing about the Rust community is how we're all like allergic to unsafe code or we think that unsafe code is is totally fine and not nothing to worry about, and I wanted to take a little bit of time to talk about what unsafe is because I think a lot of where the communities lack of alignment on this particular topic comes from a fact that unsafe is a bit of a mystery to many of us Learning about unsafe is useful, and at time necessary, it's not inherently evil, nor should it be used too freely. [0]: ▶ this video