Showing 10 posts
Thought that the Rust review was over? Think again; I was just on vacation! I’m back now to conclude the series with a bunch of random thoughts and a surprise follow-up post. The series is coming to an end. It’s time to summarize everything we have discussed so far and to cover a few more items that didn’t really deserve full posts of their own. Most of these miscellaneous items were thoughts that I jotted down while reading TRPL book. I will follow the same good/bad/ugly structure I used for the Go review a couple of years ago.
July 10, 2018
·
Tags:
<a href="/tags/programming">programming</a>, <a href="/tags/rust">rust</a>
Continue reading (about
5 minutes)
In this part of the review, I would like to focus on Rust’s ecosystem: in other words, how Rust plays with other parts of a functioning system and how Rust’s standard library vs. external libraries interact with each other. There are a lot of pieces to cover in these areas and they have left me with mixed feelings. Let’s look at some. The standard library The std library feels generally well-thought out and full of features.
June 22, 2018
·
Tags:
<a href="/tags/programming">programming</a>, <a href="/tags/rust">rust</a>
Continue reading (about
4 minutes)
“The Rust Programming Language” is one of the free books that the community has put together to teach the language. The book does a good job in general, but there are some things that could be better. Let’s cover these, but first, some background. A couple of years ago, right after getting started with Rust, I tried to go through the book’s first few chapters. It all sounded cool… but the first edition of the book moved at a glacially slow pace because it covered things in excruciating detail. E.g. the first chapter I remember was about string formatting, which detailed pretty much all there is on this topic. “Who cares? You don’t need to know all these details upfront to get started.” I thought. So I gave up.
June 19, 2018
·
Tags:
<a href="/tags/programming">programming</a>, <a href="/tags/rust">rust</a>
Continue reading (about
4 minutes)
A commonly-acclaimed feature of Rust is its match keyword: a “conditional on steroids”. match lets you take the value of an expression and compare it against a bunch of values—or, more generally, patterns. As you write and read Rust, you will notice that this keyword is used everywhere because it’s the way to access certain types, like Option values or error codes. For example: match node.get_parent() { // node is an Option<Something>. Some(parent) => { // Do something with "parent", which we know points to a node. }, None => { // There is no parent so do something else. } } In the snippet above, we have a match statement with two arms. One key detail to observe is how the parent variable, which was used as a pattern to peek inside the Some value, is only available in the first arm. The None arm has no access to the parent variable, which is obvious because there is no parent in this case.
June 15, 2018
·
Tags:
<a href="/tags/programming">programming</a>, <a href="/tags/rust">rust</a>
Continue reading (about
3 minutes)
Rust resembles a functional language in many ways although it does not claim to be one. In fact, I have been thinking of Rust as a “pragmatic Haskell” or as a “well-balanced mixture between C++ and Haskell”. One of the ways the functional aspects show up is via expressions and how pretty much any construct in Rust can be treated as an expression. But before we begin, a little warning: the examples below are, by no means, idiomatic Rust—I just hope they are simple enough to illustrate what I want to show.
June 12, 2018
·
Tags:
<a href="/tags/programming">programming</a>, <a href="/tags/rust">rust</a>
Continue reading (about
4 minutes)
Writing Rust code is not restricted to programming gurus—but there is no denying that the learning curve is steeper than that of other languages. Or is it? In this post, I’ll try to convince you that the curve does feel steep, but it isn’t when taken into perspective. Let’s first start by stating that learning a language is not the same as learning its syntax. Learning a language involves learning the syntax, of course, but it also involves familiarizing oneself with its common idioms and grabbing a good sense of what the standard libraries provide. Picking up the syntax can be easy as is the case for Go and Python—both of which can be learned in a single day—but the idioms and libraries require weeks, if not months, of frequent practice.
June 8, 2018
·
Tags:
<a href="/tags/programming">programming</a>, <a href="/tags/rust">rust</a>
Continue reading (about
4 minutes)
The one thing that blew my mind about Rust is its approach to data sharing in concurrent situations. I had always thought of mutexes as something that is easy to get wrong and was convinced that the use of a RAII pattern to prevent lock leaks never happen (like with Abseil’s MutexLock) was the panacea. (I’m a fan of RAII in C++ by the way, in case you haven’t noticed.) As Rust has taught me, that’s far from the truth: in Rust, you protect the data, not the code. What this means is that, e.g. a mutex is not an object to control access to a piece of data: a mutex is a container for a piece of data. It is impossible to access the data without going through the mutex.
June 5, 2018
·
Tags:
<a href="/tags/programming">programming</a>, <a href="/tags/rust">rust</a>, <a href="/tags/sandboxfs">sandboxfs</a>
Continue reading (about
5 minutes)
Aaaah, the borrow checker: the dreaded enemy lurking within the Rust compiler, ready to make its move to bring pain to your life by preventing your code from compiling. Or that’s what everyone seems to say, which is one of the reasons I put off learning Rust for so long. In reality… the borrow checker is a blessing, but it is true that getting past its gates is difficult at first.
June 1, 2018
·
Tags:
<a href="/tags/programming">programming</a>, <a href="/tags/rust">rust</a>, <a href="/tags/sandboxfs">sandboxfs</a>
Continue reading (about
3 minutes)
Let’s start the deep dive by looking into a powerful feature of Rust: all variables and references are immutable by default unless qualified with mut. To understand why this is important, let’s cover some context first. One of my pet peeves when reviewing C++ code is to ask authors to sprinkle the const qualifier everywhere: if something ain’t mutated, say so explicitly. This includes marking local variables, function arguments, function return values, class attributes, etc. Unfortunately, there are plenty of people that argue that doing so is stupid: const doesn’t help the compiler apply optimizations and it makes the code harder to write. So why should everything be marked immutable?
May 29, 2018
·
Tags:
<a href="/tags/programming">programming</a>, <a href="/tags/rust">rust</a>
Continue reading (about
3 minutes)
I had been meaning to learn Rust since I first toyed with Go a couple of years ago. During this period, I’ve written a non-trivial amount of Go code both inside and outside Google, but never found the chance to sit back and learn Rust. This changed a month ago during my yearly family trip to Korea. This time around, I decided upfront that I would not work on any personal or work projects for the 2-week long vacation. Instead, I would focus all spare time in reading. And I would read “The Rust Programming Language”, second edition. The plan worked: getting through the book took the two weeks and I barely wrote any code.
May 25, 2018
·
Tags:
<a href="/tags/programming">programming</a>, <a href="/tags/rust">rust</a>, <a href="/tags/sandboxfs">sandboxfs</a>
Continue reading (about
3 minutes)