week 27, 2021

Mutating and non-mutating Swift contexts

ne of the ways in which Swift helps us write more robust code is through its concept of value types, which limit the way that state can be shared across API boundaries. That’s because, when using value types, all mutations are (by default) only performed to local copies of the values that we’re working with, and APIs that actually perform mutations have to be clearly marked as mutating.

In this article, let’s explore that keyword, as well as its nonmutating counterpart, and the sort of capabilities that those language features provide.

Source: Mutating and non-mutating Swift contexts, an article by John Sundell.

Functional-ish JavaScript

Functional programming is a great discipline to learn and apply when writing JavaScript. Writing stateless, idempotent, side-effect free code really does solve a lot of problems:

  • It’s easier to test
  • It’s easier to debug
  • It’s easier to reproduce issues

Source: Functional-ish JavaScript, an article by Daniel Brain.

Inline In Rust

There’s a lot of tribal knowledge surrounding #[inline] attribute in Rust. I often find myself teaching how it works, so I finally decided to write this down.

Caveat Emptor: this is what I know, not necessary what is true. Additionally, exact semantics of #[inline] is not set in stone and may change in future Rust versions.

Source: Inline In Rust, an article by Aleksey Kladov.

Surgical Refactors

Refactoring is like surgery.

That’s not to say that clean refactors save lives. But messy refactors definitely hurt.

A surgeon is economical with their cuts, and refactoring requires the same mindset.

Source: Surgical Refactors, an article by Cameron Hashemi.

Write good examples by starting with real code

When I write about programming, I spend a lot of time trying to come up with good examples. I haven’t seen a lot written about how to make examples, so here’s a little bit about my approach to writing examples!

The basic idea here is to start with real code that you wrote and then remove irrelevant details to make it into a self-contained example instead of coming up with examples out of thin air.

I’ll talk about two kinds of examples: realistic examples and suprising examples.

Source: Write good examples by starting with real code, an article by Julia Evans.

What does 100% mean in CSS?

One of the CSS units I use most is the wonderful % — so handy for positioning elements on the page.

Unfortunately, the rules aren’t exactly straightforward. One question I’m always asking myself is:

Percent of what?

Hopefully this guide can help clear things up.

Source: What does 100% mean in CSS?, an article by Amelia Wattenberger.

Rust closures: How a closure can implement more than one trait

A pretty interesting conversation took place on a series of Tweets a while back on Rust closures. This was (and still is, although less than before) a confusing topic for me as a Rust newbie. So I was expecting some help from the Rust Twitter community. What I'm about to discuss today comes as a side effect out of that discussion; it wasn't my line of query initially.

Source: Rust closures: How a closure can implement more than one trait.

Minions (2015)

Minions Stuart, Kevin, and Bob are recruited by Scarlet Overkill, a supervillain who, alongside her inventor husband Herb, hatches a plot to take over the world.

In the evening Adam and I watched Minions. The movie is OK and I give it a 7 out of 10.

Compiling Rust is NP-hard

...though it's not the flagship borrow checking that's at fault. What I noticed, and would like to share with you today, is that the exhaustiveness checking performed by the Rust compiler on match patterns is a superset of the SAT problem.

Source: Compiling Rust is NP-hard.

How JavaScript Works: deep dive into call, apply, and bind

Call, Apply, and Bind help keep our code clean. And they make possible some advanced design patterns in JavaScript.

Also, they are extremely powerful tools in functional programming in JavaScript. They all have a relationship with the this variable in JavaScript and they can be applied in concepts such as function currying, function borrowing, and function binding.

Source: How JavaScript Works: deep dive into call, apply, and bind, an article by Lawrence Eagles.

Extensions are moving away from the kernel

From the outset, Mac OS X and macOS have been designed around a relatively small kernel which is given additional capabilities by kernel extensions. The kernel itself runs at a highly privileged level, giving it most direct access to resources such as the processor, memory and hardware devices, often known as Ring 0. Kernel extensions operate at a close level of privilege (Ring 1) so that they too can make hardware such as ethernet and Thunderbolt ports work, and they’re loaded once the kernel itself is running, before the rest of macOS. Big Sur’s kernel has just over 550 standard kernel extensions which extend it to make everything else work.

Source: Extensions are moving away from the kernel, an article by Howard Oakley.

The idea behind functional programming

The most popular programming approach within the declarative family is a functional paradigm, with its more conservative cousin — pure functional programming. Writing programs in this manner requires using composable functions encompassing conditions and expressions, preferably without side effects. Those functions are treated as first-class citizens and thus are valid arguments for other functions. It is common to construe logic where one parameter (data) is treated as an argument for the other parameter (function). This concept is present in implementations of map, reduce or fold, widespread across the programming world, and based on a functional approach.

Source: The idea behind functional programming, an article by Michał Skoczylas.

WebSockets vs. HTTP

In realtime applications it goes without saying that we need information from our servers as soon as it’s available – and, fundamentally, the classic HTTP request/response paradigm isn’t up to the job. That’s because the server will be silent, new data or not, unless or until a consumer requests an update.

Source: WebSockets vs. HTTP, an article by Martin Fietkiewicz.

Stories of Your Life and Others

Stories of Your Life and Others delivers dual delights of the very, very strange and the heartbreakingly familiar, often presenting characters who must confront sudden change—the inevitable rise of automatons or the appearance of aliens—with some sense of normalcy. With sharp intelligence and humor, Chiang examines what it means to be alive in a world marked by uncertainty, but also by beauty and wonder. An award-winning collection from one of today's most lauded writers, Stories of Your Life and Others is a contemporary classic.

In the evening I started in Stories of Your Life and Others by Ted Chiang.

I have already seen the movie "Arrival" which I liked a lot so I look forward to read this short story collection.

How disable comments make static analysis tools worse

Seeing disable comments in code has always made me feel uneasy. Whenever I encounter one, a bunch of questions pop into my head. What kind of error did the static analysis tool report? Was it something that didn’t apply? Why did the developer choose to ignore it? Were they being lazy? Did they understand the error? What is the risk of keeping it ignored? If it’s being ignored, why is the rule even enforced?

Source: How disable comments make static analysis tools worse, an article by Jeroen Engels.

git update: the odyssey for a sensible git pull

While git pull kind of works, over the years a slew of people have pointed out many flaws, and proposed several fixes. Some have even suggested that newcomers should be discouraged from using the command (as they often use it wrongly), and others to remove it entirely.

I spent several days digging through the entire history of the Git mailing list in order to document all the discussions related to git pull and its default mode. It’s a long story, so grab some coffee (a whole pot of it).

Source: git update: the odyssey for a sensible git pull, an article by Felipe Contreras.

Well Written Pull Requests

Writing better pull requests is one of the best improvements you can make as a software engineer. Well written pull requests create a smoother review process, help get your PRs merged faster and increase the level of trust and respect you earn from your team. This guide will present several easy to implement ideas that will help you write better pull requests.

Source: Well Written Pull Requests, an article by Matt McCormick.