Hello, Gleam!

--

Happy Friday! (If it’s still Friday as you’re reading this). I write this post with a genuine smile on my face. It’s been a while since I discovered a programming language that made be want to find an excuse to write some code in it.

Maybe it’s that darn happy star:

Gleam Star: “Lucy?”
The Gleam Star “Lucy” is nothing like the adorably terrifying star from the Mario Movie

The Old

The last time I had this feeling was with Scala on the JVM, which along with Cassandra as my first foray into NoSQL databases, and a bunch of other expectations, had attracted me to a new lead engineering role.

Unfortunately, though, Scala had its faults and failed to catch on with most of my future colleagues perhaps due to its complexity over Java and at the time the lack of integration into our standard engineering tools like code coverage, static type checking, some pretty painful migrations, even syntax highlighting in some of our code review tools.

I do have it to thank for discovering the actor model of concurrency, first with Scala Actors and then with Akka — which I used at the time to build a robust bi-temporal historical service / database which ran for years dynamically scaling to increasing demand without needing to be touched. (I mean this without exaggeration or pride: At one point it was 2 years between code changes on a very heavily used distributed system). It was also great fun using Scala for building various DSLs that underpinned our data model and code generation.

I also have nostalic for Haskell — though haven’t touched it for eons, very briefly looked at F# — which looked fun but never got an excuse to start using it, wrote a few necessary and exploratory bits and bobs in Kotlin — because Java has become boring but necessary, and regularly enough use Python but none of them have looked quite as fun to write (or read) as Gleam.

The New

Enter Gleam

Per its — so-slim it’s almost non-existent — wikipedia entry:

Gleam is a general-purpose, concurrent, functional high-level programming language that compiles to Erlang or JavaScript source code.

I recently finished the excellent Gleam Language Tour within a long lunch and came away thinking that they’ve created the perfect programming language!

An image of the gleam online ide gleam.run with a hello world program
Hello, World! in Gleam
import gleam/io

pub fn main() {
io.println("Hello, World!")
}

Now of course, there’s no such thing as the perfect programming language…

Gleam returns 0 when dividing by zero

Wait, what??…nevertheless it did have me beaming. Perhaps that’s the point: It’s called ‘Gleam’ because it rhymes with ‘Beam’ — the name of the Erlang Virtual Machine.

I’m a big fan of syntax sugar like this that makes code more readable, especially for anyone familiar with streaming/pipelines in *nix command shells. For example:

import gleam/io
import gleam/string

pub fn main() {
// Without the pipe operator
io.debug(string.drop_left(string.drop_right("Hello, Tahlia!", 1), 7))

// With the pipe operator
"Hello, Caiden!"
|> string.drop_right(1)
|> string.drop_left(7)
|> io.debug

// Changing order with function capturing
"havi"
|> string.append("a")
|> string.append("Z", _)
|> io.debug
}

Outputs:

"Tahlia"
"Caiden"
"Zhavia"

Further, Gleam ticks those familiar, necessary boxes for building scalable modern systems. From the website:

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.

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.

So my next long lunch, hopefully coming soon, looks like it will be experimenting with gleam otp to test that out.

So whether you’re an engineering manager, an engineer, or just intrigued in general I’d encourage you to give it a try — I know I will be. (We may not have long left to enjoy it to ourselves):

References

Next Steps

  • Comment & share your own opinions, favorite learning resources, or book recommendations.
  • Follow my blog (or digital garden) for future updates on my engineering exploits and professional / personal development tips.
  • Connect with @briancorbin.xyz on social media channels.
  • Subscribe!

--

--

Brian Corbin XYZ - TheCodeInfluencer

“I write because I don’t know what I think until I read what I say.”