Ask HN: What is the best way to learn Erlang?

I have working experience of using java and javscript.But my current project requires me to learn erlang and in a faster pace as well. Currently I am looking into `LearnXinYmin` and learn you some erlang for great good book. But for me book is a very tough way to learn a language. So I started looking into exercism to practice erlang by doing hands on coding. Are there any better approach to learn the fundamentals and the progress through some more advanced concepts like ETS tables and amnesia as for the project i need to debug those tables.

97 points | by celurian92 11 days ago

22 comments

  • cliffwarden 11 days ago
    I always loved this one. https://learnyousomeerlang.com/
    • OWaz 11 days ago
      This is where I started with Erlang, learned it first then leaned Elixir. I really enjoyed working with Erlang/Elixir & OTP.

      I’d agree with previous suggestions, either this book or Joe Armstrong’s.

    • macintux 11 days ago
      By the same author, for more advanced topics: https://www.erlang-in-anger.com
    • BillFranklin 11 days ago
      +1 Fred's book is great -- I learned Erlang using it
    • AlphaWeaver 11 days ago
      +100! The whole book is online for free and I've found it explains things in a very plain and friendly way.
  • sbuttgereit 11 days ago
    Learning the syntax and libraries is one thing and there are any number of resources which can inform you and get you through getting those things under your fingers.

    I would suggest that "getting" Erlang is more than that however and is important as code that does "something", but not necessarily in a good way, can be avoided by understanding the broader ideas you're dealing with. On that count I recommend Joe Armstrong's doctoral thesis: https://erlang.org/download/armstrong_thesis_2003.pdf. It's basically a detailed examination of what the language and runtime environment are trying to achieve: it answers "what?" and "why?". It's not a difficult or obscurely technical read and even though it's a couple hundred pages, you could probably get through it pretty easily in a couple of days depending on how fast you read.

    I don't code Erlang myself, but I do a fair bit of Elixir work, and found it very enlightening for establishing the context from which all the details I do deal with using a BEAM language follow.

    • mixmastamyk 11 days ago
      I liked his “history of erlang” a bit better. Gets to point a lot more quickly about design choices and skips excessive code listings. Which I feel not as useful until you get some hands on experience.
  • kimi 11 days ago
    Elixir. It has the very same concepts (actually it IS a dialect of Erlang - it's just a different front-end for the same compiler), but with a saner syntax. After a while you do Elixir, you'll start grokking Erlang.

    (Of course, if you need to deep dive into some Erlang code tomorrow, "Learn you some Erlang" or Joe's book. But do your Elixir.)

    Also, https://ferd.ca/ , the guy behind Erlang in Anger and Learn you some Erlang, has a lot of very well thought-of contents.

    • macintux 11 days ago
      "saner syntax" is a very, very subjective take. "More familiar" sure.
      • kimi 11 days ago
        I'm with you for "subjective". Though "strings are UTF8 binaries" ain't that bad. Or first-class, MD documentation. Or the pipe operator. Or a number of other niceties. :-)
        • filmor 11 days ago
          Well, Erlang has been picking up :)

          - OTP27 added sigils[0], which allow you write UTF8 strings with just an additional tilde character

              ~"hallöchen" =:= <<"hallöchen"/utf8>>
          
          - Also, since OTP27, Erlang's own documentation[1] is written in Markdown and created using ex_doc[2] - doc attributes etc. have been added in OTP27 as well, I think - You can use ex_doc in your own Erlang projects using rebar3_ex_doc for a while now[3]

          I also miss the pipe operator, but there seems to be some opposition against it in Erlang-land (and it would need to be adjusted as Erlang's standard library doesn't put the "main" argument consistently in the first argument slot like Elixir does).

          [0]: https://www.erlang.org/blog/highlights-otp-27/#sigils [1]: https://www.erlang.org/doc/readme.html [2]: https://hexdocs.pm/elixir/writing-documentation.html [3]: https://hexdocs.pm/rebar3_ex_doc/readme.html

        • toast0 11 days ago
          The benefit of a syntax developed this century is that you can have the strings people probably want with the syntax for strings they probably want.

          But for someone coming from java and javascript, I don't think Erlang or Elixir are going to feel particularly sane. As a person who got into Erlang before Elixir, I was hearing about a new BEAM language with 'sane syntax', and then disappointed when I saw it didn't have what I was looking for most, angle brackets. Oh well, it seems to make a lot of people happy, and it gets more attention on BEAM, so it doesn't need to make me happy does it. :)

      • binary132 11 days ago
        “Oh no! How could anyone possibly learn to a sentence with a period?!”
    • freedomben 11 days ago
      Also second this. It might seem at first like an unnecessary lift, but it will be a great stepping stone. If you haven't used a functional language before, there are some differences you need to grok (such as immutability, looping) before you'll be able to kill it. Elixir's syntax will be a lot more familiar to you, but will get you used to all the data structures/types/patterns you'll need for erlang. At that point it's just learning some syntax differences.
    • mixmastamyk 11 days ago
      Gleam might be better if you never used ruby.
  • rkangel 11 days ago
    Once you are familiar with either Erlang or Elixir I strongly recommend the book "Designing Elixir Systems with OTP" (the one with the bee and honeycomb on the front).

    It's not a programming tutorial, but it shows how to structure real world programs to make best use of what you get with Beam+OTP+Er{lang,lixir}. It's written as an Elixir book, but it's talking about architectural concepts that map directly and easily to Erlang.

    [summary of the book: write as much as you possibly can in pure functional code, mostly because it's so easy to test. Then use GenServers (etc.) at the boundary to hold the state at the top of your stack of pure code]

    • codethief 11 days ago
      > [summary of the book: write as much as you possibly can in pure functional code, mostly because it's so easy to test. Then use GenServers (etc.) at the boundary to hold the state at the top of your stack of pure code]

      In my experience this is a good idea in pretty much any language, see also https://www.destroyallsoftware.com/screencasts/catalog/funct...

      • rkangel 11 days ago
        Indeed - that is the exact architecture that the book is talking you through. It maps it well on to the specific tools you have available in Elixir. Unsurprisingly, Elixir is an extremely good fit for this architecture.
        • codethief 11 days ago
          What is it that makes Elixir such a good fit? (I don't know much about Elixir.)
          • rkangel 11 days ago
            It's a functional language with all the usual bits that entails, so writing pure code is right in its wheelhouse. It's a pragmatic, dynamic language, so very much an easy on-ramp to functional programming. The testing library (ExUnit) is good too, so with pattern matching testing is a joy.

            Where it really stands out is the runtime model. You can spin up as many GenServers as you want to hold and update state - they're like goroutines so they're very cheap and you can have thousands. They're a great way to handle state as you just handle incoming messages one after the other and change your state appropriately. Then you arrange them with supervisors so that if one does something unexpected it's restarted and going again.

  • crabbone 11 days ago
    Regardless of the language, I found that the fastest (but not necessarily the least painful) way to learn a language is to join a project written in that language and try to contribute. This accomplishes multiple goals at the same time: seeing the usual tools and practices, seeing how larger projects are built, seeing where common problematic places are.

    Some helpful things about understanding Erlang: having familiarity with Prolog. While languages work differently, on a syntactical level they have quite a few things in common. Knowing one helps to anticipate how things may work in the other in terms of syntax. You would also benefit from familiarity with persistent data types. Often the way data can be accessed defines more high-level decisions within application. Coming from the world of mutable data structures it's easy to get trapped in situations where you realize something is impossible to do the "usual" way. There are, well... "patterns" that emerged in Erlang that might be quite unique (eg. ports), but I wouldn't know about a source that accumulates and catalogues such patterns. Just know that Erlang has quite a few of those. Sometimes the word describing a function or a module wouldn't make sense to a new programmer, because the jargon has changed (eg. ports, again), pay attention to those case, they usually describe some "super-structure" in the code.

    Finally, one more thing that I found that makes you understand the language better: writing native extensions. In this way you get very intimate and "first-hand" understanding of how some mechanisms work that cannot be properly exposed in the language itself.

  • dlachausse 11 days ago
    Programming Erlang by Joe Armstrong. It’s written by one of the language’s creators and is very engaging and accessible. There are a few features that have been added to the language since the book was published but they are easy to learn later.
  • toast0 11 days ago
    If you're debugging an Erlang system, you might want to look at Erlang in Anger. [1] As I recall, it's got more information on debugging real systems.

    Otherwise, the books and references will help you get the syntax and maybe some of the otp system libraries, but the learning part is coming to terms with the core concept of a process as something with a bit of state that reads its message queue and responds. Each process should be fairly simple as it only manages its state and processes one request at a time. Sometimes business requirements make that processing complex. Sometimes processing that request means gathering information from other processes --- this can get complex if there's ordering or consistency requirements; in that case, the least complex option is to make sure all the requests that need consistency among themselves are handled by the same process. If only one process accesses the data and it only processes one message at a time, transactional concerns are easy to manage.

    ETS works a little different under the hood, but think of each table as a process, if you want to read a key, you send it essentially { self(), read, Key} and it replies with the data. Same deal for writes, etc.

    Mnesia is processes that you send messages to, and then that process does what you asked and sends the result back.

    The beauty of an Erlang system is you can get a shell on it, and inspect all sorts of stuff. You can get a list of all the processes, and see how long their message queues are. If something has a long message queue, you can get a copy of the queue and inspect it. If it's a gen_server and it's not totally stuck, you can get a copy of its state.

    You can look at the ETS tables. You can look at the Mnesia tables. You can look at the ETS or DETS tables underneath the ETS tables.

    But you do have to be a little careful sometimes. If you are low on memory, and you get a copy of a big message queue, you could exhaust your memory and kill the whole VM. Many of the old footguns have been disarmed, but Erlang still gives you plenty of ammo to shoot yourself in the foot.

    [1] https://erlang-in-anger.com/

    • celurian92 10 days ago
      thank you so much. I will look into erlang in anger then
  • TudorAndrei 11 days ago
    I have used exercism for learning new programming languages in combination with doing Advent of Code. They have a learning track for Erlang (https://exercism.org/tracks/erlang) and you can get feedback for you implementations.
  • throwaway81523 11 days ago
    Erlang the language is pretty simple. What takes some grokking is first, the concurrency approach; and second, the OTP library. If you're used to Golang or using Python with threads communicating through Queues, Erlang works about the same way, with the additional feature that a process exiting also kills its parent unless the parent explicitly traps the exit signal. In OTP parlance, a process that traps exit is called a supervisor, since its usual function is to restart the crashed process.

    Learn You Some Erlang has some useful discussion of OTP, and it was a big help to me to read through the OTP library source code. That of course will also get you more comfortable with Erlang itself.

    • hazbo 11 days ago
      I think Erlang's concurrency model is quite a bit different to the likes of Go (and probably most other languages). With Go you still have to worry about shared memory and have to manage that correctly when using Go routines. In Erlang, there is no shared memory with processes. Parallel processes are completely independent, they have their own stack and heap, and so the only way one process is able to share or access data to/from another process is through message passing.
      • throwaway81523 11 days ago
        I haven't used Go all that much, but in Python I try to write in a style that avoids any mutable objects accessed by more than one thread. All communication is through queues and I tend to have a simple RPC scheme sending callables through the queues. This has always worked pretty well for me.
  • atemerev 11 days ago
    Learn how projects are organized. What are applications and releases (releases is what we call 'distributions' in other ecosystems). Install rebar3, create a new release. Write a hello world inside this scaffolding. Learn how to run it, how to enter the shell. Learn what is OTP and gen_server. Write a simple gen_server app. Make it fall randomly each minute. Learn what is a supervisor, and how it can restart the failing app. Play with supervisor settings.

    Write a highly parallel web scraper / downloader as your first project, with workers and supervisors, there are plenty of examples how to do this with Erlang.

    Then, learn the rest of the language, now that you know its raison d'être.

  • Rendello 8 days ago
    Niche, but the book Property-Based Testing with PropEr, Erlang, and Elixir [1] taught me a lot. It might be the only dead-tree book on PBT. If you don't know what it is, here's a short video on it [2], it's basically a tool to automate tests and automatically simplify (shrink) the failing cases.

    1. https://propertesting.com/

    2. https://www.youtube.com/watch?v=AfaNEebCDos

  • ryanatkins609 7 days ago
    One of my favorite strategies for learning a new language or a new tool is to browse official docs or guides and then use this AI chrome extension[0] to chat with those docs / guides.

    [0] https://chromewebstore.google.com/detail/rocky-ai/fdjoklehji...

  • tonyg 11 days ago
    Learn Scheme as well. It will help you separate general FP weirdness from Erlang-specific weirdness. Perhaps work through HtDP, translating the ideas to Erlang.
  • 29athrowaway 11 days ago
    I did not like Erlang.

    The actor model is a good idea, functional programming is a good idea... but the Erlang tooling experience is awful and many essential tools are dated. Hiring for an Erlang team is hard. Erlang projects can be an actor spaghetti.

    And many people in the Erlang community really have to check their ego. If you want to assert that Erlang is the best language, trying other languages first is a good starting point.

    • hazbo 11 days ago
      In recent years there has been some improvement with the available tooling with the likes of rebar3[1] and just a few months ago WhatsApp released ELP (Erlang Language Platform)[2] which integrates with your IDE as a language server that provides really nice support when working with Erlang.

      [1]: https://www.rebar3.org/

      [2]: https://whatsapp.github.io/erlang-language-platform/

      • dlachausse 11 days ago
        I did not know about ELP! That’s great.

        If you know Emacs, there’s a really good editor mode that’s included with Erlang. Shameless plug…I made a simple tool to make it easier to configure it…

        https://github.com/dlachausse/erlmacs

        • hazbo 11 days ago
          I've had such a good experience with ELP, though did have some issues getting it working correctly with my emacs setup (that's probably somehow my fault). I will say though that for VSCode, it's a case of installing the extension, zero config and it just works!
    • dlachausse 11 days ago
      Elixir is probably a better fit for you. You still get access to the best in class BEAM ecosystem with a more approachable and modern syntax and improved tooling.
      • 29athrowaway 11 days ago
        The "best in class" you refer is behind the reality of most tech stacks 10 years ago.

        Yes, the concurrency is great, but it is concurrency you would probably not need if the code executed faster in the first place. In most cases, you can do all the concurrency tricks you want but if you put the same code in Rust, it just goes brrrr, does what's supposed to do without the spaghetti actor mess and with a sane compiler that actually does work for me instead of the other way around.

        The ecosystem is full of circular statements like "[Erlang|Elixir] is the best because [Erlang|Elixir] is the best". Maybe in the 90s the only realistic way to achieve concurrency without going insane was Erlang, I give you that. But it's 2024 and it's a different world now and the successful ideas in Erlang have influenced other tech stacks to some degree. Yes, Erlang is still unique in useful ways but the cost is using tooling from the paleolithic.

        Let's use some common sense to try to find out if this is really true: If it is so great then why is it that almost nobody uses it? Who is claiming it is the best? The very few people that use it, who in their majority refuse to use anything else. That makes it look like a sad echo chamber at times.

        I wish everyone over there the best but trying to make friends by claiming everyone else has no idea about what they're doing for years is not effective. Your company is not WhatsApp or a telecom company and most likely you don't need Erlang. If you have the specific problem where Erlang shines, by all means use it, but that's space is very narrow.

        • pton_xd 11 days ago
          > In most cases, you can do all the concurrency tricks you want but if you put the same code in Rust, it just goes brrrr

          If "just go brrrr" is your idea of concurrency then I agree, Erlang is not the right tool for you.

          Concurrency can also be used for fault tolerance and high-availability. Erlang is known for its "just let it crash" philosophy of developing robust distributed systems that "run forever."

          Along those lines Erlang provides a whole host of useful tools right out of the box, like being able to inspect and modify! a live system without any prior planning or instrumentation.

          It's really an amazing language.

          • prophesi 11 days ago
            Yep, I think you'd be hard-pressed to find the actual Elixir code to be the bottleneck in a real-life application. But if you do encounter that, you can use something like Rustler[0] for the CPU-intensive bottleneck, as Discord did[1] while working on a data structure they needed. Slow DB queries are something else to look out for.

            edit: Didn't see Rustler was already mentioned in a sibling thread, but hopefully the Discord tidbit will be interesting to others.

            [0] https://github.com/rusterlium/rustler

            [1] https://github.com/discord/sorted_set_nif

          • 29athrowaway 11 days ago
            And then all that is undone and ran in a processor with registers which is essentially imperative with shared mutable state again. Congrats
            • hazbo 9 days ago
              Does this logic not basically invalidate anything that isn't imperative at a high level that eventually runs on a processor? Like, "why bother writing Haskell? It just gets compiled and ran imperatively." Isn't the whole point that you can reason about Haskell?
        • macintux 11 days ago
          > Yes, the concurrency is great, but it is concurrency you would probably not need if the code executed faster in the first place.

          If you're using Erlang concurrency for performance you're probably doing it wrong.

          • freedomben 11 days ago
            Well, it depends on the bottleneck. CPU-bound code, I would of course agree. For I/O bound though, especially network I/o with variable peers (which is the vast majority of code written nowadays) erlang's concurrency model is fantastic.

            Also worth mentioning is that you can write CPU intensive code in rust and invoke it as NIFs[1]

            [1] https://github.com/rusterlium/rustler

        • agos 11 days ago
          it's not only telcos which have concurrency problems. you'll find they are quite frequent in programming
  • kunley 11 days ago
    https://learnyousomeerlang.com/

    Much better than Learn X in Y min

  • beeburrt 11 days ago
    I used an LLM tool to give me little exercises to do, then i'd show my work and it would give feedback, and references for more info. Specifically, https://www.phind.com

    Edit* Look, it showed me this same Ask HN post as a reference:

    https://www.phind.com/search?cache=avz73b8uy17qz70rfoto0x8t

    Also, here is an Awesome list concerning Erlang:

    https://github.com/drobakowski/awesome-erlang

    And Elixir's HexDocs section on ETS:

    https://hexdocs.pm/elixir/erlang-term-storage.html

  • marianoguerra 11 days ago
    https://spawnedshelter.com/ is a great list of resources to get started
  • brudgers 11 days ago
  • liveoneggs 11 days ago
    here's a big video series on youtube (https://www.cs.kent.ac.uk/ErlangMasterClasses/ -- links to videos on the bottom)

    The syntax of erlang, while a little weird, is very small. I struggled the most with immutability.

  • Communitivity 11 days ago
    I dug up a blog post of mine that's no longer on the net, from 2012. Some of the resources are likely still valid. The links did not come through, so you'll need to do some searching.

    Top 10 Resources For Getting Started with Erlang

    These are the top ten resources that helped me when I started learning Erlang. I've not ordered them within the list because they complement each other. Your mileage may vary. Other Erlangers opinions may differ. These helped me greatly though. I cannot stress enough that there is no substitute for making. The below will help you much more if you start out trying to solve with Erlang some problem you know about. Decompose it into very small pieces and take each piece one at a time. For some more info on that see the post introducing the concept of Deliberate Practice.

    1. Learn You Some Erlang I started learning Erlang back in 2009 at about the same time Learn You Some Erlang chapters started being posted by Fred Trottier-Hebert. This is the first place I'd recommend someone go when they are learning Erlang, especially if they have good prior software writing experience. I found LYWSE easy to understand and packed with detail. Sometimes it goes into too advanced details for a beginner, but you can skip these and come back to them when you are ready.

    2. Joe Armstrong's Thesis Reading this thesis is drinking direct from the source. Joe Armstrong is one of the three fathers of Erlang. The other two are Bjarne Da ̈cker and Robert Virding. Reading A History of Erlang (PDF) by Joe Armstrong won't teach you Erlang, but it's a very interesting read.

    3. The Erlang Web Site Erlang.org has some good examples, the OTP Design Principles User Guide, the Erlang Reference Manual, the documentation for the Erlang OTP libraries (Erlang's stdlib), and an online self-paced course.

    4. The Erlang-Questions Mailing List The people on this list are very helpful. Chances are that your question has been asked before, so search the archives first. As with any mailing list it can take time to get an answer, so I tend to just use the archive. The FAQ, a link to the archives and instructions for subscribing are on their web site: http://erlang.org/mailman/listinfo/erlang-questions.

    5. Free E-Books and Other Web Resources The following books are good to use for times when you don't have time to get into the coding zone, or when you want to deep dive into a particular topic. Concurrent Programming in Erlang, Part 1 Erlang For Skeptics - An old, but still useful, e-book that you'll need to build yourself from this project site. It's worth it though. TryErlang.org - A free hands-on web tutorial for Erlang I remember going through some others, but it's been a long time and I don't remember them. If you read this and know of a good (and legal) e-book link then please post it in the comments and I'll add it below here, with credit.

    6. Commercial Books and Podcasts I bought some of the books on this list, borrowed others. They are all recommended, but in this economy it's important to stress you don't need them to learn Erlang, but they will make your learning Erlang easier. Erlang in Practice by Kevin Smith - From all accounts a very good series of screencasts on Erlang Erlang Programming by Francesco Cesarini and Simon Thompson Erlang and OTP in Action by Martin Logan, Eric Merritt, and Richard Carlsson Building Web Applications with Erlang: Working with REST and Web Sockets on Yaws

    7. Online Q&A sites If you have a question while learning Erlang the chances are someone else has had it as well. It's also good when you don't have a specific question but you have some time to spend on learning. When that happens go to one of these Q&A sites and search for unanswered Erlang questions, pick one, and then research it until you have an answer. Once you have an answer you can go back to the question and post your answer if there isn't one yet.

    Stackoverflow is probably the best known Q&A site. It is a great source for detailed Erlang information in their Erlang questions. They also have a decent number of unanswered Erlang questions at any one time.

    Another less well-known site is Quora (requires login via Twitter or Facebook). They are getting more popular and are more focused on social connections than score, whereas StackOverflow is focused more on the score. They a tag so you can find Erlang questions, but I've not found a link for unanswered questions, only for open Erlang questions.

    8. Twitter Twitter is always a great source for information, and for a dialogue with people that may be able to answer your questions. Feel free to follow me and tweet me if you have a problem. I also try to retweet anything on Erlang that I find interesting. My Twitter id is BillBarnhill.

    9. Source Code The best way to learn a language is by making useful software using that language. The second best way is to read good code, trace how it runs, and re-read until you understand what it does. Often this will lead into writing code to get the software to scratch a particular itch you have. The best source code to read in my opinion is the OTP sources, for the sole reason that they will be what you interact with the most. The second best is the Github account of Basho and the repos in it, because these folks know their stuff.

    10. Erlang Projects I Recommend This one isn't a resource as much as some recommendations from me on projects to learn about byt looking at the materials the developers publish, the source code, and building.

    Web servers and frameworks

    For web serving I recommend Cowboy. I started out on Yaws, then switched to Misultin for most things, Mochiweb for some others. When Misultin went away I switched to Cowboy and haven't looked back. There's some caveats though. Riak uses Webmachine and Mochiweb, and if you want to use Erlang professionally you need to know Riak. So you need to at least be comfortable with WebMachine and Mochiweb. The web framework Nitrogen lets you use Mochiweb or Yaws, and you should learn Nitrogen. Once you learn Nitrogen I suggest you learn Zotonic, which is a Content Management System (CMS) like Drupal and is built on top of Nitrogen. If you are coming from Rails, or want something that feels similar, then I suggest checking out the Chicago Boss web framework

  • darkof 11 days ago
    Just learn Elixir :) Tooling is so much better.