Member-only story
String Encodings Decoded With Elixir
Know the working of strings

It is time you gained membership in the secret society of the dark question marks �����. This may be the last explanation of encodings you will ever need to read.
I had run afoul of string encodings for years, but it wasn’t until I started working with Elixir that I finally really understood them. It’s been a few years since my string-enlightenment, but let me share with you all lessons I learned so you can put the misunderstandings behind you. Here follows my tale of hard-won bits of knowledge about strings and encodings that I wish somebody had told me. ☯⚡❁♛
Before you can really understand encodings, you need a greater appreciation for the string data type — yes, the backstory is necessary, and if you really want to blow your mind, I highly recommend reading “The String Type is Broken” by Edaqa Mortoray.
The particular koan to meditate on is that strings are different than any other data type. Booleans are simple on/offs; numbers can be constrained by their size (e.g. an 8-bit number). But a string? It could be infinitely long, comprised of virtually anything. Curious curious… (brew that confusion for a moment)…
I always felt that the academic studies surrounding software development were completely backwards: you learn early on about RAM and circuitboards, but rarely, if ever, do you get academic instruction on version control systems, how to debug, or any real-world info on the state of the industry. If you graduated with a degree in Computer Science, you could probably rattle off factoids about dated esoterica (because your course materials were probably at least five years old) but you might not know how to code your way out of a real software project if your life depended on it. Perhaps only the insanity of the developer interview process is more out-of-sync with the things you actually need to know and do on a daily basis.
Diving into strings and encodings marked one of the first times that sent me back into those college lectures. The important takeaways are these:
- Everything on a computer is represented numerically (i.e. 1’s and 0’s)
- You need to know the size of the number to properly store it