Event sourcing, JavaScript classes & a redecentralised web

Welcome to the third issue of Growing the Stack! This week we’ll dive into event sourcing, study object oriented programming in JavaScript and talk about the future of the web.

Enjoy!

Event Sourcing made Simple

Event sourcing is a hot topic (well, it’s heating up). Kickstarter’s engineering team decided to dive in and build their next product with a home-grown event sourced approach.

Author Philippe Creux compares event sourcing to Git:

Most software developers use a tool to keep track of code history. Git is a fantastic example that’s used widely across the industry. Type git log and you can see all the changes made to a codebase. Who made the change, when it happened, what the change was, why the change was made and how the change was performed. Git is also a time machine, that allows you to go back in time and see what the code looked like back then. You can also replay history and play what-if scenarios: go back in time, checkout a new branch, commit a change, and replay all the events commits that happened after that.

A more formal definition by Martin Fowler is:

All changes to an application state are stored as a sequence of events

The article serves as a hands-on guide to build a pragmatic event sourced system. It’s an interesting topic for both back- and frontend developers. If you’re a frontend developer, you might already be applying event sourcing ideas with state management libraries like Redux.

kickstarter.engineering

JavaScript Private Fields and Object-Oriented Design

Josh Justice shares his thoughts about the recent addition of private class fields in JavaScript.

Having this feature available in Babel has gotten me thinking about how we can use private fields in our code and how they influence our designs. And I think the possibilities are pretty significant. To see why, let’s look at a scenario when we might want to refactor our code to private fields, and the impact it has.

What really peaked my interest was thinking about why object oriented approaches aren’t as common in JavaScript as in other languages.

Whenever you need to add some functionality to your app, you can either add a standalone function or a method on an object. In many object-oriented languages, one of the main motivations for using methods is that they have access to private data on the object. But because JavaScript didn’t have private fields until now, this wasn’t an argument in favor of using methods.

There was, however, a strong argument in favor of using standalone functions: JSON. It’s incredibly easy to parse JSON into JavaScript objects that have data but no methods. It’s more effort to copy that data into a new instance of a class that has methods on it.

It’s feels more natural to pass around plain objects in JavaScript than intertwining your data and behaviour. This explains why functional programming concepts are so alluring in JS. Data and behaviour are separated by design in FP.

Even if you’re not that into JavaScript, this article is worth a read, especially if you’re a language design nerd like me!

codingitwrong.com

Vague, but exciting

Hidde de Vries, a freelance frontend developer from the Netherlands, had the honor to follow a lecture from no one else than Sir Tim Berners-Lee, inventor of the world wide web. Hidde recaps Sir Berners-Lee’s talk about the history, current state and future of the web.

Berners-Lee first showed a virtuous circle: if all goes well the web lets people publish, which inspires conversation and more publications. This is the utopian scenario and we’ve seen a lot of this actually happen. The web community itself it s a great example of this, we teach each other stuff and good blogs inspire other people to start blogging.

The creator of the web warns about a dystopian future, where algorithms decide what we get to see on the web, which in turn narrows our view. It’s time for a redecentralised web!

hiddedevries.nl