week 22, 2022

Arc and Mutex in Rust

When writing concurrent Rust you will encounter Arc and Mutex types sooner or later. And although Mutex might already sound familiar as it's a concept known in many languages, chances are you haven't heard about Arc before Rust. What's more, you can't fully understand these concepts without tying them to the ownership model in Rust. This post is my take on understanding Arc and Mutex in Rust.

Source: Arc and Mutex in Rust, an article by Piotr Sarnacki.

Compiling a Subset of JavaScript to ARM Assembly in Haskell

I recently got a copy of the book Compiling to Assembly from Scratch by Vladamir Keleshev, which details how to write a compiler for a subset of JavaScript to 32-bit ARM assembly code. The choice to use ARM assembly is mainly for its simplicity in comparison to x86.

Keleshev elects to use TypeScript to write the compiler, which, as he explains in the preface, is largely a compromise for its familiar C-like syntax while still providing many functional programming features desireable for writing a compiler. However, I chose to write my version of the compiler in Haskell as it's my favorite language, and the focus on functional programming from Keleshev makes it a natural choice for the translation.

Overall, I had a lot of fun writing this compiler as I got to learn more about the nitty-gritty low-level of how code is executed while getting more practice with Haskell. In this post, I won't cover every detail of the design of the compiler, but I'll try to hit on what I found to be the most important or interesting aspects of the code.

Source: Compiling a Subset of JavaScript to ARM Assembly in Haskell, an article by Micah Cantor.

The appeal of bidirectional type-checking

In this post I hope to explain why bidirectional type-checking has a lot of cultural cachet within the programming language theory community. To be clear, I’m an amateur and I have no formal background in computer science or type theory. Nonetheless, I believe I’ve learned enough and compared notes with others to motivate bidirectional type-checking.

Source: The appeal of bidirectional type-checking, an article by Gabriella Gonzalez.

Five Ducklings

On our way to the town centre we encountered a duck with five ducklings. I got off my bike and took some photos. I had seen the same duck with ducklings earlier this week but was too much in a hurry to take photos back then.

Mother duck with five ducklings
Mother duck with five ducklings.

I wonder if she's the same mother duck we saw last year, also with five ducklings.

Who Needs Modern Emacs?

Every now and again I come across some discussion on making Emacs “modern”.1 The argument always go more or less like this - Emacs doesn’t look and behave like and the world will end if we don’t copy something “crucial” from it.

Source: Who Needs Modern Emacs?, an article by Bozhidar Batsov.

Git Under the Hood

While I’m not a programmer per se, I do use git almost daily and find it a great tool for source control and versioning of plain text files. But I don’t think there can be any doubt that it is not the easiest tool to use. But despite its unintuitive user interface, under the hood git is quite simple and elegant. I believe that if you can understand the fundamental constructs git uses to store, track, and manage files, then the using git becomes a lot easier.

In this article we’re going to take a look under the covers and investigate git’s fundamental constructs. We’ll start off with its storage model and look at blobs, trees and commits. We’ll see how branches are implemented, and finally we’ll unpack the git index file to understand what happens during the staging of a commit.

Source: Git Under the Hood, an article by Greg Foletta.

perl v5.36.0 has been released

Yesterday, I released perl v5.36.0. I think this is the most exciting release of perl in quite some time, and I’m hoping that in a few months, I’ll still be as pleased with it as I am today. Here’s a summary of what we got done, what we didn’t get done, and (to some extent) how it got done.

Source: perl v5.36.0 has been released, an article by Ricardo Signes.

Everything you need to know about involuntary borgs in Python

Sometimes, sharing the same object within your code is exactly what you want.

For example, you can create a class that behaves de facto like a singleton by using the borg pattern. It’s called borg pattern as a reference to the Borgs in Star Trek where they are linked in a hive mind called the Collective.

I explained the Borg pattern in detail on my blog here.

In this article, however, we have learned how to avoid such pitfalls when we do not want to share information in presumably different variables. I sometimes refer to the examples in this article as involuntary borgs.

Source: Everything you need to know about involuntary borgs in Python, an article by Bas Steins.

God Emperor of Dune

Millennia have passed on Arrakis, and the once-desert planet is green with life. Leto Atreides, the son of the world’s savior, the Emperor Paul Muad’Dib, is still alive but far from human. To preserve humanity’s future, he sacrificed his own by merging with a sandworm, granting him near immortality as God Emperor of Dune for the past thirty-five hundred years.

Leto’s rule is not a benevolent one. His transformation has made not only his appearance but his morality inhuman. A rebellion, led by Siona, a member of the Atreides family, has risen to oppose the despot’s rule. But Siona is unaware that Leto’s vision of a Golden Path for humanity requires her to fulfill a destiny she never wanted—or could possibly conceive....

In the evening I started in book 4 of the Dune Chronicles by Frank Herbert: God Emperor of Dune.

Pointers, strings, and (im)mutability

I recently had a funny experience that turned out to be a great education in mutability of objects, especially strings, in Python. The experience came as a result of messing up on two Python brainteasers, getting annoyed about a seeming contradiction in the language functionality, and then going down a fascinating rabbit hole.

Source: Pointers, strings, and (im)mutability, an article by Danny D. Leybzon.