*Published: 2024-04-23*
**tl;dr: I've been playing with Gleam lately and believe it will become my language of choice in my future projects.**
I've been programming Go for almost 10 years now, and enjoy the power, speed and reliability it gives me.
I've worked on several projects, written tens of thousands of lines of code, trained teams, owned products, all within the Go ecosystem.
One of the advantages I see often touted is that it eliminates an entire "class" of bugs that you'll see with more dynamic languages. This is the bug you often get in Ruby, Python or JS where the wrong "type" is pushed through to a function's arguments, resulting in runtime errors or surprising behaviour.
This is great, so let's go further in to squashing "classes" of bugs, the compromises needed to do so, and how Gleam manages to do it without sacrificing what makes Go great.
Gleam has been covered by two large YouTubers:
- [Primeagen](https://www.youtube.com/watch?v=9mfO821E7sE)
- [Theo](https://www.youtube.com/watch?v=_I-CSgoCgsk)
There's been a few blog posts on Gleam (the community is still quite small), but my favourite one is this one:
- [What if best practices were the norm?](https://giacomocavalieri.me/posts/what-if-best-practices-were-the-norm)
- [Things I like about Gleam’s Syntax](https://erikarow.land/notes/gleam-syntax)
## Go is good, but its also bad
![[go.png|center|200]]
The debate about whether or not [Go](https://go.dev/) is good language has been violently fought over a decade, with thousands of keyboard warriors going head to head. Ultimately the language is born of compromise. See for yourself:
- [Rust vs Go: A Hands-On Comparison](https://news.ycombinator.com/item?id=37675988)
- [Should I Rust or Should I Go?](https://news.ycombinator.com/item?id=37525069)
- [Ask HN: Should I learn Rust or Go?](https://news.ycombinator.com/item?id=31976407)
- [Why Go and Not Rust? (2019)](https://news.ycombinator.com/item?id=34552981)
- [Rust vs. Go](https://news.ycombinator.com/item?id=13430108)
- [Ask HN: Rust or Golang?](https://news.ycombinator.com/item?id=24490971)
- [Rust vs. Go in 2023](https://news.ycombinator.com/item?id=37107052)
Some people think its the worst thing since unsliced bread:
- "Go has nil pointer footguns"
- "Go has no generics"
- "Go doesn't have sum types"
- "Go has ignored the past 40 years of programming language research"*
\*I've seen this argument for SO long, its actually "50 years of programming language research" now
On the other hand:
- "Go is simple to learn"
- "Go is designed to onboard new developers quickly"
- "Go is maintainable"
- "Go is fast"
- "Go is stable"
Its the great circle of developer circlejerk life.
Honestly its getting kind of tiring, and let's not forget only the programming languages that actually get usage are the ones that get fought over.
## Elixir?
![[elixir.png|center|200]]
But what about Elixir, with whom I flirted with back in 2016, in [[PR-004 - Elixir]]?
Honestly, learning Elixir made me feel that they didn't really think through the ergonomics of the language, in particular the "one way to do things" philosophy. Just importing modules was enough of a pain to learn (there are four ways).
```
alias Foo.Bar, as: Bar
require Foo
import Foo
use Foo
```
Elixir also really leaned into its Ruby-ness (hard to quantify, sorry), and was dynamically typed by default, two things I am trying to avoid.
I really liked what Elixir was trying to achieve, but the approach was just not for me.
## Rust?
![[rust.png|200|center]]
[Rust](https://www.rust-lang.org/) and Go goes head to head often in debates, but to me it feels mismatched. Rust is much more difficult to learn, has a lot more mental overhead ([[PR-006 - Go, Rust and the cost of brain power]]), and does it for reasons I don't care about:
- Go is not as safe as Rust, but *its safe enough*
- Go is not as fast as Rust, but *its fast enough*
- ...etc
Rust solves a lot of Go's warts, namely its weird error handling, nils, etc. But it is at the cost of extra complexity,.
You guys want to build the next videogame engine, operating system, or GPU drivers? Go ahead. My interests and specialties lie elsewhere.
I do admit that I'm currently working on a Rust based videogame on [Bevy](https://bevyengine.org/), but only because it was the most suitable engine that satisfied some very strict parameters.
## Gleam is good, but its also goooood
![[gleam.png|200|center]]
[Gleam](https://gleam.run/) is a language built with Rust (obviously). Its built with a similar kind of philosophy to Go if you squint (I'm asian, I squint all the time):
- Learn quickly
- Keep simple
- Concurrency friendly
Most importantly, *it doesn't sacrifice what makes Go great*.
- Ceremony minimal
- One way to do things
- Fast compile times
It keeps all the appealing parts of Go! So what's left? Fixing the problems mentioned above. Gleam has all the improvements I (and everyone else, apparently) want on Go:
- Remove the nil pointer class of bugs
- Remove mutable struct fields and variables
- Removing the ability to ignore errors via `Result`
It does have some deviation in approaches to solving problems:
- Immutable everything
- No for loops (!!!)
- Reliance on BEAM
- Functional programming
- Pipelining and pattern matching
Instead of throwing more dot points at you, I will summarise it as such.
**Gleam takes what makes Go great, and fixes what Go does poorly without increasing complexity.**
## The future is now (in side-projects)
Gleam is *new*. Brand-spanking, 2024 was v1.0 new.
There's a lot of room for discovering the limits of the language, compiler bugs, drift in vision from the founders, development of new libraries.
Even if it calls itself v1.0.0, I wouldn't be forcing this upon my employer's codebase anytime soon. Instead all of my random unfinished side projects will now be in Gleam instead. It is exactly what I want in my programming language. Gleam's philosophy reminds me of Go's, but with a more modern take.
A simple, functional, statically typed, scalable frankenstein of Go and Elixir.