Rusts type system requires that there only ever is one mutable reference to a value or one or more shared references. What happens when you need multiple references to some value, but also need to mutate through them? We use a trick called interor mutability: to the outside world you act like a value is immutable so multiple references are allowed. But internally the type is actually mutable. All types that provide interior mutability have an UnsafeCell at their core. UnsafeCell is the only primitive that allows multiple mutable pointers to its interior, without violating aliasing rules. The only way to use it safely is to only mutate the wrapped value when there are no other readers. No, the garantee has to be even stronger: we can not mutate it and can not create a mutable reference to the wrapped value while there are shared references to its value. Both the book and the std::cell module give a good alternative explanation of interor mutability. What are some patterns that have been developed to use interior mutability safely? How do multithreaded synchronization primitives that provide interior mutability follow similar principles?
In Practical guide to writing more functional Javascript, we walked through how to reason about our code in functional programming terms. In this guide, we will talk about a few utilities I like to use to reason about these concepts and help us navigate through the imperative constructs JavaScript natively provides.
I googled test patterns in Go, then I invoked the Spirits of the Core Library. As soon as I realised where to look at, I finally saw a sign. It was Brad Fitzpatrick.
n this post, I aim to:
— Shed light on some of the presumed benefits of small functions
— Explain why I personally think some of the benefits don’t really pan out as well as advertised
— Explain why small functions can actually prove counterproductive sometimes
— Explain the times when I do think smaller functions truly shine
Ever wondered how large enterprise scale systems are designed? Before major software development starts, we have to choose a suitable architecture that will provide us with the desired functionality…