Interview with Steve Klabnik: How Rust Compares to Other Languages and More
How the Rust Programming Language Compares to C++, Ocaml, Go, and Erlang
With 273 repositories on GitHub, Steve Klabnik is known for his contribution to open source projects, where he is in 15 organizations. He is currently ranked #32 on the all-time Rails Contributors list, and has written the guide Rust for Rubyists. Rust is a relatively new programming language for developing reliable and efficient systems. As of June 2014, Steve has joined Mozilla to work on the official Rust Documentation.
Would you recommend coding newbies to learn Rust or should they learn some other language like Ruby first?
I think that they should use whatever gets them excited. Pick something, anything, and just try it. If you don’t like it, try something else. Humans are all different, and there’s no single answer here. That said, I think Ruby is a fantastic first language. Rust has a significant lack of resources because it’s so new, and so it’s much harder as a first language.
You’ve said before that Rails makes it hard to do ‘true’ TDD and unit testing difficult. How does Rust compare?
Rust has unit testing built right into the language, but it’s just the basics: asserts and such. We expect others to build neat stuff on top of that as the community grows.
How would you compare Rust to other system programming languages such as C++? Why do you think it should replace C++?
Historically, programming languages have had a tradeoff: you can have a language which is safe, but you give up control, or you can have a language with control, but it is unsafe. C++ falls into that latter category. More modern C++ is significantly more safe than it used to be, but there are fundamental aspects of C++ which make it impossible to ever be truly safe. Rust attempts to give you a language with 100% control, yet be absolutely safe. It does this through extensive compile-time checking, so you pay little (and often no!) cost at runtime for its safety features. This safety issue isn’t just about programmer convenience, though. C++ is unsafe in ways which cause serious security vulnerabilities.
For example, in the last Pwn2Own competition, Firefox had some serious vulnerabilities, due to C++ being unsafe. And so did the other browsers on that page. Many of these errors would have been compile-time bugs if those browsers were written in Rust, and the runtime ones would not have produced a security vulnerability.
For applications which requires high performance, people choose C++ but C++ is definitely too complicated, and Java might be too heavyweight due to the nature of running on top of JVM. There’s D which tries to be a better C++, but looks like only few care. Now there’s Go which starts taking off. Do you think that Rust could beat Go in this place?
Rust and Go are very different languages, and comparing them doesn’t make a lot of sense. It’s like asking if Ruby and C are competing. Now, it’s true that there are some programs that are written in C that could be written in Ruby, but the languages make fundamentally different tradeoffs. There are certain kinds of applications which Rust can work well in that Go never can. For example, writing a Ruby gem in Rust is pretty easy, but you can’t do that with Go. Two garbage collectors fighting over each other’s memory is a bad time. That said, Rust makes you care about a lot of details which you don’t have to worry about if you’re coding in Go, and so if you’re happy with Go’s downsides, programming in Go make more sense than in Rust. As always, it really depends on what your requirements are, and what tradeoffs you’re willing to make.
If all we’re talking about is safety, performance, and functional programming. Do you think that Rust could be better than OCaml? Or would Rust begin to make people aware of functional programming? As people are talking about functional programming, but few really pick one functional programming language to develop stuffs.
Rust is vaguely functional, but it’s not full-blown. OCaml is a better functional language than Rust. That said, it might make it easy to start to use some functional concepts, because you don’t have to go whole-hog. This is why OCaml is often easier than Haskell, for example.
Rust is quite an ambitious language which tries to be performant, therefore low level in some degree, while retaining safety and convenient at the same time. For systems programming, C dominates everything else. Do you think that Rust could replace C in such place?
Absolutely, you can use Rust anywhere you’d use C. There are practical reasons why you may choose not to, for example, there aren’t nearly as many libraries. But Rust can work well with C libraries...
For concurrency, Rust seems to support everything from Go and Erlang. Do you think Rust could replace them in those places?
So this question is complicated, and changing. We’re currently removing Rust’s green threading support, because 1:1 threads make sense as a default for a systems language. However, they will be available in a library. Rust has some strong advantages in the concurrency department due to its ownership model. For example, sharing mutable state across a concurrency boundary without a mutex is a compile-time error in Rust. This is super huge on the correctness side. Erlang is the king in this space, so if you can afford a garbage collector, and you don’t mind Erlang’s more eccentric syntax, it’s still the leader for building resilient software.
Do you see yourself going back to improve Rails with what you’ve learned from Rust? What are your plans for the future?
My work is less and less in Rails these days, and so I don’t expect to. You never know though! My plan is to continue supporting the Rust ecosystem in every way that I can. For now, that involves continuing to work with Mozilla, but I’m not an oracle. Anything can change.
How has philosophy affected the way you code?
In general, I think more about the meta-stuff around my code than I did before. For example, I spend a lot more time thinking “is the software I’m building ethical?” or “are there other ways of looking at this?” I’ve also found certain connections to be productive when trying to understand both topics. They inform each other. For example, Plato’s ‘theory of forms’ has helped me understand OOP, and functional reactive programming has helped me understand process philosophy.
What projects do you find inspirational?
If I had to pick one, I would have to say Tor. It’s a project that has helped so many people, and is so vitally important to the world.
What are your favorite tools?
Despite working primarily on open source projects, you seem to take a negative attitude toward it, where you say open source is a mega-capitalist conspiracy. Can you elaborate on your opinion?
Haha, that pull quote from this article is one of the most misunderstood of mine. When I say ‘conspiracy,’ I don’t mean a bunch of people in a room, making evil plans. I mean it in a loose sense: a bunch of people benefit from perpetuating the idea of open source. If you’re not familiar with the history of the term ‘open source,’ this article is pretty good. But basically, the Free Software movement was one based on an ethical imperative.
"Open Source" is a similar idea, stripped of ethics, and re-packaged so that companies benefit, not users. I have participated in open source because it’s a good way to change the world, but that doesn’t mean I don’t understand that many other people have made a ton of money off of the work that I’ve given them for free. If I hadn’t done that work for free, they would have had to pay someone else to do it instead, possibly even me! That’s just the reality of the situation.
You have a lot of strong opinions about the capitalism and its relationship to technology. What are some ways you think tech can create a better world and do you think it’s possible for technology to veer away from encouraging capitalism?
Technology and capitalism have always gone hand-in-hand. The Luddites, for example, would break textile equipment, because they saw the effect technology would have on their work. I’m not a luddite, but I’m also keenly aware that my role as a programmer is to automate others out of their jobs. So where do we go from here? Well, I’d like to think that with enough automation, people won’t actually need to work as much. And we wouldn’t have to, except that the profit from my automation work isn’t captured by me: it’s captured by my employer.
A simple way to think about it is this: If I make one unit of software per day, and then I learn some new vim keyboard shortcuts, and that lets me make two units of software per day, I still have to work eight hours per day. I can’t suddenly start working four and collect the same amount of money, because I’m paid by the hour, not by my productivity. And likewise, if I come into a factory and write some software for robots that replace the workers, the same work is getting done, but instead of them being able to take the time off, instead they’re out of a job. I would like to see a world where we as humans have more free time to explore our passions, dreams, and desires. Technology can build that world, but capitalism never can. Well, it’s not the end game, at least 😉