Steve Klabnik

“The most violent element in society is ignorance.” - Emma Goldman

Read this first

Rust has a static garbage collector

There’s a fairly common argument that pops up on programming forums, and it’s about the nature of what “garbage collection” means. In the research world, this is what GC means:

Garbage collection (GC), also known as automatic memory management, is the automatic recycling of dynamically allocated memory(2). Garbage collection is performed by a garbage collector which recycles memory that it can prove will never be used again. Systems and languages which use garbage collection can be described as garbage-collected.

Historically, there has been two major forms of GC: reference counting, and tracing. The argument happens because, with the rise of tracing garbage collectors in many popular programming languages, for many programmers, “garbage collection” is synonymous with “tracing garbage collection.” For this reason, I’ve been coming around to the term “automatic memory management”, as it...

Continue reading →


Who authors the most popular crates on crates.io?

I had a question this morning: who authors the most popular crates on crates.io?

First, we have to figure out what we mean by “most popular.” My first guess was “top 100 by recent downloads”, so I looked at crates.io. Once I got to 100, I found that even the next few crates were ones that I heard of and would think are used often. I decided to keep going until I felt the results were more tenuous. This is obviously pretty subjective, but I also realized something: I felt like the data got a bit more noisy when I got to the 100k download mark. Sorting by this and removing a few outliers (the rustc-ap-* crates don’t count, IMHO), I had a list of 264 crates in a text file.

Furthermore, how do I determine ‘crate authorship’? Many crates, especially popular ones, are worked on by more than one person. I’m trying to come up with some really rough numbers here, so I decided to go with the...

Continue reading →


Should you learn C to “learn how the computer works”?

I’ve often seen people suggest that you should learn C in order to learn how computers work. Is this a good idea? Is this accurate? I’m going to start with my conclusion right upfront, just to be crystal clear about what I’m saying here:

  • C is not “how the computer works.”
  • I don’t think most people mean this phrase literally, so that is sort of irrelevant.
  • Understanding the context means that learning C for this reason may still be a good idea for you, depending on your objectives.

I plan on making two follow-up posts as well, exploring more implications of this idea, but this is already quite a lot. I’ll update this post with links to them when I make them.


I’ve often seen people suggest this:

By learning C, you can learn how computers work.

I think that this idea is not inherently wrong, but does come with some caveats. As long as you keep those caveats in mind, I think this...

Continue reading →


You can’t “turn off the borrow checker” in Rust

Every once in a while, someone will talk about unsafe in Rust, and how it “turns off the borrow checker.” I think this framing leads to misconceptions about unsafe and how it interacts with safe code.

Here’s some code that causes a borrow checker error:

fn main() {
    let mut x = 5;

    let y = &x;
    let z = &mut x;

    println!("{}", y);
}

And the error:

error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable
 --> src/main.rs:5:18
  |
4 |     let y = &x;
  |              - immutable borrow occurs here
5 |     let z = &mut x;
  |                  ^ mutable borrow occurs here
6 | }
  | - immutable borrow ends here

Rust won’t let us have a &T and a &mut T to the same T at the same time.

If unsafe “turned off the borrow checker, we’d expect this code to work:

fn main() {
    let mut x = 5;

    unsafe {
        let y = &x;
        let z = &mut x;
...

Continue reading →


Is WebAssembly the return of Java Applets & Flash?

In my last post on WebAssembly, I made the following claim:

Some have compared WebAssembly to Java applets; in some ways, they’re very right, but in some ways, they’re very wrong. Eventually I’ll write a post about the wrong, but for now, the right: in some sense, WebAssembly is a different way of accomplishing what the JVM set out to do: it’s a common virtual machine that can be used to build very cross-platform software.

A lot of people expressed interest in me elaborating, so let’s get to it! For this post, I’m going to make three comparisons: to Flash, to Java Applets, and occasionally to PNaCL. Secondly, this post is going to focus on the web use-case for WebAssembly, even though the previous post was about non-web uses. We’ll make that comparison in the next post. Finally, this post is kind of like eating tapas, there’s a bunch of little sections. I feel like it’s a bit short...

Continue reading →


WebAssembly is more than the web

While WebAssembly was given its name for good reason, I also think it’s quite the misnomer. When you hear about WebAssembly, don’t just think of the web: think bigger.

Many programmers know that WebAssembly is a technology that lets you run non-JavaScript code in the browser. That is true, but there’s a lot more to it. You see, the spec is written in a very interesting way: there’s the core, what WebAssembly actually is. Here’s the opening section:

To support the embedding of WebAssembly into different environments, its specification is split into layers that are specified in separate documents.

  • Core specification - Defines the semantics of WebAssembly modules and its instruction set, independent from a concrete embedding.

  • API specifications - Define application programming interfaces enabling the use of WebAssembly modules in concrete embedding environments.

It goes on to say:

...

Continue reading →


“The Expressive C++17 Coding Challenge (in Rust)” Revisited

In October of last year, I wrote a post, “The Expressive C++17 Coding Challenge (in Rust)”. For various reasons, it got brought up again in the D world, and seb has written a new post. It’s good, you should check it out!

However, it links to my gist, not my blog post. As I said back then:

I held myself to the same constraints as the original contest; no external packages is a bit painful in Rust, but it’s not too bad. Mostly it would let me eliminate boilerplate while also improving correctness, and making the code a bit shorter.

So, that got me thinking: What would this look like if I could use external packages? I took about an hour, and knocked it out. I have two versions to show you today, one where I pay no attention to allocations, and one where it’s zero-allocation.

First, the “whatever just allocate” version:

extern crate csv;
#[macro_use]
extern crate serde_derive;
extern
...

Continue reading →


0b100000

As someone who has significantly different beliefs than Peter Thiel, today is likely my second-to-last power of two years alive.

Two years ago, I wrote a post about turning 30, and I pretty much feel the same way. Never enough time, tick tock, tick tock. I have today off (thanks Mozilla!), but am still considering working anyway, because I really care about what I’m working on, and am excited about it. We’ll see.

I feel like I have more to say here, but also don’t. So maybe let’s leave it at that.

View →


Looking back at Rust in 2018

A careful reader will note the date of this post; it’s fundamentally in response to this call for blog posts, with a rhetorical device of looking backwards as if my personal plans for Rust came true. If you’re reading this in 2019 or beyond, this may be a work of fiction.

It’s been an exciting year for Rust. Well, it depends on what you mean by “exciting”, exactly. In a word, this year has been about polish. I find this kind of thing exciting! It’s a very different kind of exciting than the “new and shiny” exciting. It’s “take what we have and make it shiny.”

Let’s recap the major achievements of the year.

 Rust 2018

First of all, we shipped our first epoch! If you type cargo new today, you’ll see a new shiny entry in your Cargo.toml:

[package]
name = "new-program"
version = "0.1.0"
authors = ["steveklabnik <steve@steveklabnik.com>"]

epoch = "2018"

[dependencies]

What does this...

Continue reading →


Five years with Rust

Today is five years since I first heard of Rust. I wrote a post last year about it. This year, I have something slightly different in mind.

Five years is a long time in tech. It’s also a long time for me to be focused on one specific thing; other than the pizza job I held in high school and college, I’ve never stayed in a single job for five years. (This is true today as well; it’s not like I got a job with Rust the first day I learned of its existence.) I started with Ruby and Rails in 2008/2009, and my final commits to Rails were in August/September of 2013. So at this point, my career has basically been split in half, rather than dominated by Ruby.

Five years ago tomorrow, I registered http://www.rustforrubyists.com/.

Yesterday, I had lunch with someone I’m very honored to call a friend. We talked about a lot of things, but also about Rust’s past, present, and future. One thing...

Continue reading →