My impressions of Gleam
When I was about to go on paternity leave, the Gleam programming language reached 1.0. It's such a small language that I was able to learn it over the span of two days. I tried to use it to convert a GitHub Action from JavaScript to Gleam, but I ran into issues due to Gleam wanting to be the top of the language stack instead of the bottom. As such I ended up learning and using ReScript. But I still liked Gleam and wanted to try writing something in it, so over the winter holidays I did another project with it from scratch.
Why Gleam?
First and foremost, their statement about community on their homepage spoke to me:
As a community, we want to be friendly too. People from around the world, of all backgrounds, genders, and experience levels are welcome and respected equally. See our community code of conduct for more.
Black lives matter. Trans rights are human rights. No nazi bullsh*t.
Secondly, the language is very small and tightly designed which I always appreciate (Python's "it fits your brain" slogan has always been one of my favourite tag lines for the language).
Third, it's a typed, functional, immutable language that is impure. I find that a nice balance of practicality while trying to write code that is as reliable as possible by knowing that if you get passed the compiler you're probably doing pretty well (which is good for projects you are not going to work on often but do have the time to put in the extra effort upfront to deal with typing and such).
Fourth, it compiles to either Erlang or JavaScript. Both have their (unique) uses which I appreciate (and in my case the latter is important).
Fifth, it has Lustre. While I liked Elm and loved TEA (The Elm Architecture), I did find Elm's lack of FFI restrictive. Lustre with Gleam fixes those issues.
And finally, my friend Dusty is a fan.
My learning project
I decided I wanted to create a website to help someone choose a coding font. When I was looking for one a while back I created screenshots of code samples which were anonymous so that I could choose one without undue influence (I ended up with MonoLisa). I figured it would be a fun project to create a site that did what I wish I had when choosing a font: a tournament bracket for fonts where you entered example text and then have fonts battle it out until you had a winner. This seemed like a great fit for Lustre and Gleam since it would be all client-side and have some interaction.
The good
Overall, the language was a pleasure to work with. While the functional typing occasionally felt tedious, I knew there was benefit to it if I wanted things to work in the long-term with as little worry as possible that I had a bug in my code. The language was nice and small, and so I didn't have issue keeping it in my head while I coded (most of my documentation reading was for the standard library). And it was powerful enough with Lustre for me to need exactly less than 200 lines of Gleam to make it all work (plus less than 90 lines of static HTML and CSS).
The bad
I'm a Python fan, and so all the curly braces weren't my favourite thing. I know its for familiarity reasons and I'm not going to cause me to not use the language in the future, but I wouldn't have minded less syntax to denote structure.
The other thing is having to specify a type's name twice for the name be usable as both the type and the constructor for a single record.
pub type Thingy {
Thingy(...)
}
Once again, it's very minor but something that I had to learn and typing the name twice always felt unnecessary and a typo waiting to happen for the compiler to catch. Having some shorthand like pub record Thingy(...)
to represent the same thing would be nice.
The dream
I would love to have a WebAssembly/WASI and Python back-end for Gleam to go along with the Erlang and JavaScript one. I have notes on writing a Python back-end and Dusty did a prototype. Unfortunately I don't think the Gleam compiler – which written in Rust – is explicitly designed for adding more back-ends, so I'm not sure if any of this will ever come to pass.
Conclusion
I'm happy with Gleam! I'm interested in trying it with Erlang and the BEAM somehow, although my next project for that realm is with Elixir because Phoenix LiveView is a perfect fit for that project (I suspect there's something in Gleam to compete with Phoenix LiveView, but I do want to learn Elixir). But I definitely don't regret learning Gleam and I am still motivated enough to be working my way through Exercism's Gleam track.