They are both deeply immutable, so you no longer need to Object .freeze() your objects or use libraries like Immutable .js to gain unchangeable objects, and do you know what's even more awesome?
You can compare them with the strict equality comparison (===), ...
... which negates the need for library functionality like deepEquals to check if two objects are the same.
2️⃣ Records
Records are immutable objects. They can contain other primitive types, but no plain Objects (which are mutable again).
To create one, you combine the syntax of private class fields and the object-creation shorthand syntax.
Nesting a mutable object results in a TypeError.
You can also create Records from plain Objects by using the new constructor function Record().
All methods you'd usually use with Objects are applicable to Records.
You can log them, use a for..of-loop, or destructure them.
And the greatest addition Records bring with them is the ability to use the strict equality comparison to compare them.
If you've ever written a deepEquals() function you'll know that this is to be valued really really high, as it saves developers a lot of time.
And lastly, Records can be converted back to mutable Objects whenever you want to.
3️⃣ Tuples
Tuples are immutable array-like structures. They can, like Records, only contain other (compound) primitives.
You couldn't nest an Array or an Object within a Tuple, e.g. That would result in a TypeError.
Tuples bring with them all methods you know from Arrays already, except those that would alter its contents.
But besides that, you can use them like you usually would.
Of course, Array destructuring also works with tuples, and spreading, too!
You can also use all forms of loops with Tuples like you usually would and use the strict equality comparison to compare two Tuples.
And now, before you think that it's a little difficult to add an element to a Tuple and create a new Tuple, to keep it immutable, there's a method that does exactly that!
4️⃣ JSON Support
The proposal currently suggests adding a new method to JSON, namely JSON .parseImmutable() that creates a Record or Tuple out of a JSON string and not plain mutable Objects or Arrays.
5️⃣ What Is The Real Benefit Of Tuples And Records?
Well, there is more than one benefit you can get from those two new types.
First of all: Built-in immutability. No longer do you need a library or Object .freeze to prevent mutation of your Objects.
The next benefit is that both of them are usable as Map keys and Set values, as they are strictly comparable.
Until now it never really worked to use a plain Object or an Array as a key. Even if it somehow worked, the Objects could be mutated while being set as a ...
... key, which could lead to very strange effects occuring.
Immutable types can't be changed and thus give guarantees to make them a valuable choice for Map keys or Set values.
• • •
Missing some Tweet in this thread? You can try to
force a refresh
You hear some people talking about it, you might have a basic idea, but let's take a closer look because, in the end, it's not as difficult as it might seem from the outside!
🧵⏬
1️⃣ What Is It?
Test-driven development (short: TDD) is a software development technique.
Instead of writing all your code first and only then writing your tests, you start with tests, then code a little, then test again, and so on.
It is one specific form of the test-first approach and aims at making software development faster, more reliable, and safer to do. And it especially forces developers into a user role.
By writing tests first, you become a user. You are the first one to ...
WebAssembly has the chance to become for JavaScript what C, C++, and Fortran are for Python.
JavaScript has its limitations, as well as Python does. Python solves this by having an awesome native interface that allows easy integration ...
... of low-level libraries. JavaScript has C/C++ in Node. But in the browser? Sure, floating-point arithmetics can well be done with the help of WebGL and shader language, but there is no common low-level target for all of JavaScript.
Here are some resources that help you to get into the language!
🧵⬇️
1️⃣ "The Book"
This is the official Rust book. It covers everything the language has to offer and introduces feature after feature while enabling especially newbies to follow along from the simpler to the more difficult topics.
This project gives you small exercises that aim at getting you comfortable writing Rust code. Especially if you don't feel creative enough to think of a new project, this is a great way of still writing code.
The most-loved language, according to StackOverflow's yearly developer survey that not enough people seem to use professionally.
🧵⏬
1️⃣ What Is Rust?
Rust is a systems programming language that is compiled to binary. It has no runtime and instead uses a concept called "borrow checking". Developers don't need to explicitly free memory, the compiler does it for them.
The language itself is multi-paradigm, offering functional, generic, imperative, structured, and concurrent programming with a huge emphasis on performance, memory safety, and developer productivity.
What are NFTs? Everyone seems to be talking about them but what are they, and how can you use them?
Interested? Then this thread is for you!
🧵🔽
1️⃣ What Is An NFT?
Non-fungible tokens (NFTs) are digital assets. Just imagine a trading card where each card has unique information engraved into it. No two NFTs are the same and they are thus not interchangeable.
Other than crypto where one BTC is one and two BTC are two BTC, two NFTs are one NFT and one NFT. Only because you have two NFTs of the same type simply doesn't enable you to sum them up together.