Impressions of Gleam: A New Programming Language Experience

As I prepared for paternity leave, the Gleam programming language reached its 1.0 release. Remarkably compact in design, I mastered it over two days, initially trying to convert a GitHub Action from JavaScript to Gleam. However, issues arose due to Gleam’s preference to be at the top of the language stack, which led me to pivot to ReScript. Despite this, my curiosity was piqued, prompting a winter holiday project using Gleam.

Why Gleam?

Gleam’s community ethos appeals to me, emphasizing inclusivity and equality, a sentiment echoed on their homepage: “As a community, we want to be friendly. People from around the world, of all backgrounds, genders, and experience levels are welcomed and respected equally.”

Gleam is small yet robust, reminiscent of Python’s “it fits your brain” slogan. As a typed, functional, immutable language with impurity, it offers practicality and reliability. This design ensures that once the compiler approves your code, it’s likely error-free—a boon for infrequent projects requiring upfront effort.

Gleam’s compilation to Erlang or JavaScript is a distinctive feature, aligning with my priorities. Its integration with Lustre, addressing Elm’s FFI limitations, was an additional lure. Moreover, my friend Dusty is a fan, adding a personal recommendation to the mix.

Learning Project: Coding Font Selection

For my learning project, I aimed to create a website that facilitates the choice of a coding font. Inspired by my own search where I created anonymous code sample screenshots, the idea was to develop a tournament bracket for fonts. Users would input sample text, and fonts would compete until a preferred choice emerged—a task well-suited for client-side interaction with Lustre and Gleam.

Ironically, as I embarked on this project, “CodingFont” launched with a similar concept but superior design and maintenance-free for me. Consequently, while I didn’t release my site, the code remains available for personal use.

The Good and The Bad

Gleam proved delightful to work with. Although the functional typing could be tedious at times, it promised long-term stability and bug minimization. Its compact nature facilitated easy mental retention, with most documentation consultations limited to the standard library. The power of Gleam and Lustre was evident as my project required fewer than 200 lines of Gleam code, complemented by under 90 lines of static HTML and CSS.

Conversely, my Python affinity made Gleam’s curly braces less appealing, a minor grievance compared to the language’s benefits. Another small inconvenience was the necessity to specify a type’s name twice for a single record, which felt redundant, although manageable.

The Dream

My aspirations include a WebAssembly/WASI and Python backend for Gleam alongside Erlang and JavaScript. Although there are preliminary notes for a Python backend and Dusty has a prototype, the Rust-built Gleam compiler may not easily accommodate more backends. Thus, the feasibility remains uncertain.

Conclusion

My experience with Gleam has been positive. While my next project in this realm involves Elixir and Phoenix LiveView, I’m open to exploring Gleam’s potential alongside Erlang. Despite the challenges, learning Gleam was worthwhile, inspiring continued progress through Exercism’s Gleam track.