Hopefully you now feel comfortable writing basic Erlang programs, and understand roughly how modules and processes build into programs. You should be ready to experiment with writing Erlang code, but more importantly, you should be ready to explore other resources for mastering Erlang and its many powerful libraries. There’s a lot to explore!
The Erlang shell is a great place to test code and to poke and prod Erlang code. You’ll likely spend a lot more time in the shell if you keep using Erlang, but the way you use it may change.
You can compile and run Erlang code outside of the shell, which makes it much easier to integrate Erlang work with tools you typically use to manage code and related resources. Erlang’s make
module is a common place to start, letting you create Emakefile files that provide instruction to the erl -make
command. The escript
command, described at http://erlang.org/doc/man/escript.html, will let you run Erlang from the command line in a variety of different environments.
If you want to automate your Erlang builds further, you may want to explore rebar3. You can mix rebar3 with other tools to apply the strengths of each.
If you want to use Erlang from an IDE, you may want to explore http://erlide.org/, a set of tools for working with Erlang in Eclipse. Emacs users will want to explore the Erlang mode.
Almost everything you’ve learned in this book points toward a computing model that makes it easy to distribute programs across a network of Erlang nodes. Setting up a set of nodes isn’t that difficult. It may even be too easy (in some ways) to let security-obsessed administrators sleep easily. Designing for Scalability with Erlang/OTP (O’Reilly) explores this in greater depth.
Before you set up large sets of nodes, you’ll want to know much more about how Erlang schedules code to run, how messages get passed among nodes, and how to administer Erlang nodes remotely. All of that info is out there, providing the foundation on which tools like OTP and Mnesia can build.
Erlang includes a binary data type, binary operators, and a variety of libraries for processing binary data. If you need to build network protocols that handle bits on the wire, or ASN.1 data, for example, Erlang offers powerful tools for getting information into and out of binary form. If you see numbers or strings enclosed in <<
and >>
, you’ve encountered Erlang’s tools for handling binary data. They allow you to specify, pattern match, and process binary data structures.
Chapters 4 and 5 introduced you to the io:format
functions in the context of presenting information in the shell. The io
module offers much more, however, for reading and writing data, and the file
, filename
, filelib
, and io_lib
modules give you the tools you need to get into and out of files. If networking is more your style, you’ll want to explore the gen_tcp
, gen_udp
, and inet
modules.
Functional programming approaches should, once you get used to them, make it easier to create clean code. However, it is always possible to tie yourself in knots, especially as you move toward solving more complex problems than the ones presented in this book.
Unit testing is one approach to making sure that your code keeps working as you move forward. Focused on small components of your programs that should be able to reliably return a set of correct outputs from a given set of inputs, unit testing can both help to tell you when you’ve made your code work and warn you when it breaks. Erlang includes the EUnit framework for unit testing and the Common Test framework for system testing.
Erlang also includes Dialyzer, the discrepancy analyzer for Erlang, which can help you catch basic errors of sending wrongly typed data, code that never gets called, and similar issues that compilers for statically typed languages are usually good at catching. Erlang also includes profilers and coverage tools; you should explore the eprof
, fprof
, and cover
modules, and the cprof
tool.
If you’re excited about refactoring code—once you have more of it—you may want to explore Wrangler. It allows you to explore your code and automate a wide variety of common program modifications.
Erlang is a natural match for a world of web programming in which the number of users is constantly increasing, data needs to move smoothly among nodes, and customers are starting to expect critical web applications to work as reliably as the telephone system. Most web applications are large pipelines of data, well-suited for Erlang’s strengths.
Several Erlang frameworks let you build web applications. Cowboy, Yaws, and Mochiweb are web servers written in Erlang. They offer environments that should be fairly familiar to anyone building web applications. Yaws lets you mix Erlang code with HTML (and other) templates, making it fairly easy to get a website or application together on an Erlang foundation. For a more comprehensive framework that can run with any of these, take a look at Nitrogen.
If you have fallen for the siren song of REST-based service development, you may also want to explore Webmachine, a toolkit for HTTP processing that brings you very close to the core of the web’s foundation protocol. Even if you don’t end up using it, exploring its flow diagram will teach you a lot about what’s involved in processing a web request.
You already have ETS, DETS, and Mnesia. What else might you need?
Many people are using Erlang without knowing they are using it, as they interact with the popular NoSQL databases CouchDB and Riak. Their Erlang underpinnings make them easy to distribute and manage, and they’ve both reached large and growing audiences. For a great brief intro to them (and five other database options), you should explore Seven Databases in Seven Weeks (Pragmatic Programmers). It won’t teach you much about using them with Erlang, but it will give you a solid foundation that will help you explore their Erlang interfaces once their broad approaches make sense to you.
Many other databases have Erlang interfaces, and there is support for the classic ODBC connections.
If you need to wring out every drop of performance on a complex task, or want to avoid rewriting a library written in a language other than Erlang, you’ll want to explore Erlang’s tools for connecting with other programming languages. Erlang Programming (O’Reilly) explores Java, C, and Ruby connections, but also notes approaches you can use to connect with .NET languages, Python, Perl, PHP, Haskell, Scheme, and Emacs Lisp. You’ll also want to examine native implemented functions (NIFs) and drivers.
Erlang may put the fun in functional programming, but its structures may feel brittle if you’re used to the flexibility that many other languages provide. Elixir combines the Erlang runtime system with a very different (Rubyish) syntax more focused on polymorphism, metaprogramming, and associative data structures. If you prefer Lisp approaches to functional programming, you might want to explore Lisp Flavored Erlang.
Erlang’s runtime model and tools are powerful and unique, and there may be other great ideas coming that will let you apply them to work that might not seem on the surface to be written in Erlang.
As you learn more about Erlang, you’ll find a community happy to help you at every level. The erlang-questions mailing list welcomes beginners. During the writing of this book, I found its archives incredibly valuable. You can find subscription and archive information at http://erlang.org/mailman/listinfo/erlang-questions, and you will probably run into its archives regularly if you do searches on Erlang topics. If you prefer live chat to email, there is also an #erlang IRC channel on freenode and an Erlang slack.
If you prefer “real” live chat to the internet, Erlang has a thriving conference circuit. For completely Erlang-focused venues, check out Erlang Factory, which produces a number of shows around the world, including the Erlang User Conference. The Association for Computing Machinery (ACM)’s Special Interest Group on Programming Languages (SIGPLAN) also holds an Erlang workshop.
There are also a lot of more informal “Erlounges” in a wide variety of locations, and many larger conferences, like the Open Source Convention (OSCON), include Erlang sessions and tutorials.
If you want to explore Erlang code, there’s lots of it on GitHub; you can look around at the most active projects by visiting https://github.com/languages/Erlang.
It may seem easy to argue for Erlang. The broad shift from single computers to networked and distributed systems of multiprocessor-based computing gives the Erlang environment a tremendous advantage over practically every other environment out there. More and more of the computing world is starting to face exactly the challenges that Erlang was built to address. Veterans of those challenges may find themselves breathing a sigh of relief when they discover Erlang. They can stop pondering toolsets that tried too hard to carry single-system approaches into a multisystem world.
At the same time, though, I’d encourage you to consider a bit of wisdom from Joe Armstrong: “New technologies have their best chance a) immediately after a disaster or b) at the start of a new project.”
While it is possible you’re reading this because a project you’re working on has had a disaster (or you suspect it will have one soon), it’s easiest to apply Erlang to new projects, preferably projects where the inevitable beginner’s mistakes won’t create new disasters.
Find projects that look like fun to you, and that you can share within your organization or with the world. There’s no better way to show off the power of a programming language and environment than to build great things with it!