Making the most of bit arrays in Gleam

Gleam’s bit arrays: fans thrilled, skeptics yelling, emojis packed

TLDR: A community guide demystifies Gleam’s bit arrays—tiny packed data blocks used for speed and control—filling gaps in the official docs. Fans celebrate the power and pattern matching, while skeptics argue it’s complexity newbies don’t need and wonder how consistent it’ll be on JavaScript, making this a practical debate worth watching.

Gleam’s newest deep-dive on its quirky “bit arrays” has the community doing victory laps and spit-takes at the same time. The guide explains how those double angle brackets are basically tiny suitcases for raw data—texts, numbers, even emojis—packed super efficiently, with options for size, order, and type. Beginners cheered, calling it the missing manual, since the official docs are still sparse (link). But the hottest take? A full-on culture clash: performance nerds love binary packing, while web folks yelled “just use JSON,” the easy-to-read text format.

The endianness debate (that’s just the byte order) went nuclear, spawning memes of “Little vs Big: holiday family drama.” Floats (computer decimals via the IEEE 754 standard) got dragged for being fussy, while UTF-8 (the web’s text encoding) won hearts for turning “Hello 🌍” into a neat stream of numbers. Someone joked every time they see “<< >>” they hear chevron fanfare, and another posted “Erlang cosplay” gifs because Gleam borrows the idea from Erlang.

Strongest opinions? One camp says this unlocks serious speed and clean pattern matching (think Lego for data). The other warns it’s overkill for most apps and will scare newcomers. And yes, JavaScript support questions sparked anxiety: “Will this work the same in the browser?” Cue popcorn.

Key Points

  • Gleam’s bit arrays are enclosed by << >> and built from comma-separated segments with options defined as value:option1-option2-option3.
  • Default segment type is Int; integers encode as 8-bit signed by default, while echo prints them using 8-bit unsigned representation.
  • Float segments default to 64-bit IEEE 754; non-literal floats require the :float option, and sizes can be set to 16 or 32 bits.
  • String segments default to UTF-8; encoding can be changed to UTF-16 or UTF-32, and :utf8 is needed for non-literal strings.
  • UTF codepoints can be encoded using the built-in UtfCodepoint type; the guide addresses syntax differences from Erlang and outlines further topics like endianness and signedness.

Hottest takes

"This is Erlang cosplay and I'm here for it" — beam_bae
"Just use JSON; stop traumatizing newcomers" — soft_dev_sigh
"Endianness isn't a vibe, it's a bug farm" — endianEnvy
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.