26 February 2024

The Effect effect

I write this article sat in the departure lounge at Vienna airport following three exciting days at the world's inaugural Effect conference: Effect Days 2024. Eyes were opened, lessons were learned, and hopefully long-lasting relationships were forged.

It would be impossible to summarise Vienna, even crudely, without mentioning history, art and music. These are cultural pillars that run through it's very being, evident everywhere and at every time. I am not entirely sure what led to it being the choice for the event, but the emotion of the city flowed perfectly into the ethos of the event: exploring beyond the boundaries of what is established. It felt like the perfect place to do this.

Software developers do not exist in a vacuum, thank goodness. Our industry ebbs and flows in opinion and thought, and for the most part we follow and adapt. Of course this is true of any industry and society; time moves, things - priorities, sentiments, aspirations - change. There are plenty of observations to reflect on during my time in this industry but one staple would be that developers are almost always searching for something better. Unsurprising. Humans have an innate desire to improve. In our industry this manifests as a desire for better platforms, better tooling and better languages. From time to time we are presented with new options and sometimes these options enter the zeitgeist, changing the way we even think about software (React? Docker?). However, sometimes, these options are more personally profound. For me, learning Clojure, becoming "a Clojurian", was a transformative experience. It entered my peripheral vision at a time that I was disenfranchised with the classical array of "OOP" languages. It came into focus and I spent six years swimming in the crystal waters.

But the wheel of change revolves much more quickly in some places than in others, and without question that frequency is at its peak in the JavaScript ecosystem.

https://radixweb.com/blog/top-javascript-usage-statistics

The Japanese knotweed of programming languages. To deny it's influence is foolish, and to resist it is Sisyphean. Always bet on JavaScript! Warts and all. Additionally, as a hiring manager and someone accountable for the technological health of a company, it's too significant to ignore.

Fortunately, there are a multitude of tools now available which make working with JavaScript more tolerable. If you care about having a wide pool from which to hire then I also recommend picking a tool which isn't too far down the list (sorry ClojureScript). For me, TypeScript is the only way developers should be writing JavaScript in 2024.

Enter Effect

Having an efficient tool with which to answer 'the JavaScript problem' isn't quite enough. As much as brushes and paint don't make the art, TypeScript won't make the code. Each stroke needs purpose, to add something to the composition of the work, to complement, to blend. Even in the most abstract of paintings there is intent.

Enter Effect.

Functional programming is not a new concept. It's not even a popular concept, despite being repeatedly lauded as a "good idea". However, it continues to steadily gain mind share among developers and this is periodically accelerated by yet more tools and advances in the space. One such advance is Effect which brings functional programming to TypeScript, with flair.

At this point it would be amiss to mention Effect without a strong acknowledgement of perhaps its single largest influence: ZIO, a functional programming library for Scala. John De Goes, pioneer of ZIO, spoke at Effect Days in a proud, paternalistic fashion.

During John's talk he gave many reasons why Effect has the capacity to "win" and it was impressive to see him acknowledge some of the reasons why ZIO, in retrospect, failed to reach the mass-market. Somewhat ironically, the biggest reason that ZIO adoption will always be tethered is the same reason Effect's adoption could be monstrous: reach. Always bet on JavaScript.

https://star-history.com/#zio/zio&Effect-TS/effect&Date

Effective TypeScript

Put succinctly, and especially for the FP crowd, Effect is an "invariant trifunctor". I have almost no idea what this means, but it describes Effect's core form: the Effect.

Effect.Effect<A, E, R>

This small concept forms the basis for everything in Effect, because everything is an Effect. Well, most things. An Effect is exactly that, in the symbolic sense; think 'side effects', but very much 'front-and-centre effects' in this case. Another way to think about them are as isolated programs in and of themselves, and that's a good metaphor when we consider the A, E, R generics that form an Effect's definition.

From the docs:

In the Effect ecosystem, you may often encounter the type parameters of `Effect` abbreviated as `R`, `E`, and `A` respectively. This is just shorthand for **R**equirements, **E**rror, and the success value of type **A**.

So, unlike the peasantly function, Effects describe three channels:

  • A: Upon success, this Effect will return an A
  • E: Upon failure, this Effect will return an E
  • R: In order for this Effect to run, it requires an R

It leverages TypeScript to ensure that these conditions are respected and so applications running Effect immediately enter a realm of rationality, where they possess the prime ability to be "reasoned about" simply through the the guarantees provided to us by the compiler. Of course, this isn't new or novel, but it goes the extra mile in ensuring that TypeScript programs - which are now endemic in both frontend and backend - are easier to understand, more composable, stack safe, etc etc. It's a new paradigm but the payoff is huge.

Betting on Effect

At Kikin we made the decision a few months ago to begin embracing Effect and writing new components in a style that would integrate with our existing platform. Since then we have moved to begin replacing old components in Effect so that they can benefit from the improved experience of error-handling, concurrency and dependency injection.

As always, time is the only thing that will provide insight about this decision, but having navigated software for almost two decades I can confidently say that Effect brings some very strong ideas to the table and, from what I saw at Effect Days, the community is poised to land very deep inside TypeScript territory with a compelling offer that I believe will appeal to a lot of developers.

As it is, we are betting our business on Effect and I recommend you do the same.