Making illegal states unrepresentable is one of the practices Yaron Minsky from Jane Street preached in his Effective ML lectures on programming in OCaml some 10 years ago. Could this technique be applied in Erlang, which is known for being notoriously hard to typecheck? Let’s find out!
Minsky’s original example shows how to refactor a C-style “bag of things and an enum” (also known as a discriminated or disjoint union) representation of a state machine:
To a set of record types and an algebraic data type, which prevent misuse of fields in states in which these fields are not…
Note: this post was originally written in 2016. It’s been a while, but the points taken are still valid.
Some time ago I ran across Chris Smith’s very good overview of using Docker Compose to setup an Erlang system. The post is well written and I wholeheartedly advise you to spend a while on it if you’re getting into reproducible deployments or testing distributed systems. To the point, though. Chris writes:
One of the reasons I wanted to look at it [Erlang] is the intellectual challenge — getting your head round purely functional programming (no mutability allowed), actors and supervision…
It’s been a while since I last posted, but life has been so eventful that I barely had time for docsh, not to mention writing for the blog.
Still, since I wrote about the initial project goals in February, it’s changed a lot. The initial idea was to embed documentation and type information in .beam files and distribute such instrumented files. While this is implemented and works, it’s problematic to do the same with OTP applications’ modules. I considered a couple of approaches for using docsh with OTP:
Throughout the few years of writing Erlang I’ve noticed a number of uses of macros in source code, some of which I definitely agree with and some which in my opinion should have been expressed differently.
Before elaborating on whys and why nots, here’s a short recap for those who might be new to Erlang. This is how macros look like and how they can be used:
%% BAD EXAMPLE! Explained later.
io:format("~s:~b: " Format, [?FILE, ?LINE] ++ Args)).area(R) ->
?debug("radius: ~p~n", [R]),
?PI * R * R.
So, macros in Erlang are simple text…
TL;DR: To access module documentation in the Erlang shell use docsh.
For quite some time now I’ve been envying a few of Elixir’s features: protocols, a consistent standard library, the pipe operator, macros and online documentation (as in “when connected to a system”). Personally, I don’t like Elixir’s syntax, but I “love” it when people use this same argument as an excuse not to use Erlang. …
Erlang/Elixir engineer from Kraków, Poland