sidenote

Introduction to Gleam

9/25/24 - Elizabeth Jorgensen

Introduction

I recently came across this new programming language called Gleam. I found it when I saw that Fly.io sponsors them. I like what I've seen from Fly, and it’s awesome that they're sponsoring a language. I think it's cool when companies take the initiative to support cool projects in the community.

Reliable and Scalable

Gleam is reliable and scalable. “Running on the battle-tested Erlang virtual machine that powers planet-scale systems such as WhatsApp and Ericsson, Gleam is ready for workloads of any size.”

This is a big deal. WhatsApp is a massive application. I'm not as familiar with Ericsson, although that said, the Erlang VM is currently used by quite a few companies and growing with Elixir and Erlang. It also handles connections well, and it's able to do a lot of concurrent tasks.

Concurrent Garbage Collector

“Thanks to a multi-core actor-based concurrency system that can run millions of concurrent tasks, fast immutable data structures, and a concurrent garbage collector that never stops the world, your service can scale and stay lightning fast with ease.”

A concurrent garbage collector that never stops the world. That's valuable because it's a big concern with garbage-collected languages that the garbage collector needs to take cycles off the CPU to be able to go and clean up your memory. And because it's concurrent they found a way to make it so that it doesn't stop the world per se, or cause a slowdown in your program because it's doing that garbage collection in the background.

Here to Help

The next section says that Gleam is here to help. “No null values, no exceptions, clear error messages, and a practical type system. Whether you're writing new code or maintaining old code, Gleam is designed to make your job as fun and stress-free as possible.”

No null values are important. It has a lot to do with the fact that Gleam has immutable variables so you need to initialize everything. It helps you to avoid edge cases where you might forget to do something that causes crashes.

No exceptions are also valuable. I'm a big fan of this paradigm. It's just the idea of passing errors as values back from functions. It's very explicit about what errors a function can or are options for it to be able to return. This way you can handle them accordingly instead of it being this abstract kind of external outside-your-function thing that you have to know to catch it or at least guess and you can just end up with a bunch of tries and catches all over the place trying to handle these. I like that methodology and decision for the language.

Multi-lingual

It says that “Gleam is multi-lingual in that Gleam makes it easy to use code written in other beam languages such as Erlang and Elixir.”

So there's a rich ecosystem of thousands of open source libraries for Glean users to make use of. This is a really smart decision to make that kind of gear towards being able to import Erlang and Elixir packages. Whenever there's a new language, there's always a lack of utility libraries and functions to be able to help you get started on whatever you're trying to make. So by being able to leverage what's already existing in Erlang and Elixir, It allows Gleam to kind of spring forward and be able to be used immediately instead of waiting for the community to go and create a bunch of packages that everyone's gonna end up needing.

Compilation to JavaScript

“Gleam can additionally compile to JavaScript. enabling you to use your code in the browser or anywhere else JavaScript can run. It also generates TypeScript definitions so you can interact with your Gleam code confidently even from the outside.”

This is revolutionary. I am not sure how it works or what it looks like, but it is cool. One of the big selling points of JavaScript is that JavaScript is running in the browser. Gleam can compile to JavaScript which means that now you can use Gleam both on your front end and your back end. And make it a unified experience there for your developers. I'm not sure how that works, and I'm curious what that looks like in implementation, especially with this generating TypeScript definitions, which effectively sounds like you can interrupt your TypeScript code. It also makes it a consistent contract, because these are generated. They'll stay up to date with whatever your current Glean code is.

Friendly Language

From their front page, you can see that they're saying that “Gleam is a friendly language for building type-safe systems that scale. It has the power of a type system, the expressiveness of functional programming, and the reliability of the highly concurrent fault-tolerant early runtime with a familiar and modern syntax.”

This is interesting because of the style of functional programming, where you're taking your data, and mutating it with change functions programming languages are not strongly typed. I prefer strongly typed languages for my applications. After all, it allows me to keep strong contracts between functions and be able to refactor more easily because it just tells me everything where it's having an issue.

Ready When You Are

You can see that “Gleam is ready when you are. Gleam comes with a compiler, build tool, formatter, editor integrations, and package manager all built in. So creating a Gleam project is just running Gleam new.”

This is a pretty big deal because with a new programming language, making a compiler and coming up with the syntax and rules for a language is very complex and it takes a lot of time. On top of that, you have this whole other world tool of making it a good developer experience to work with. While you've got your compiler, you also have your build tool formatter, editor integrations, and package manager all built in. It's nice that they've put a lot of thought into this to make it a good developer experience.

Gleam Ecosystem

“As part of the wider Gleam ecosystem, Gleam programs can use thousands of published packages, whether they are written in Gleam, Erlang, or Elixir.”

This is a huge advancement. When a new programming language comes out, there's always this issue where you need a lot of packages to exist to function, to be able to make your web server or whatever you're going to make. And it's nice that you can leverage the existing Erlang and Elixir packages because then that gives you a head start to be able to be good and running in production. After all, you've already got the tools that you need to be able to function.