Erlang Blog Posts

Please post your Erlang blog posts here :023:

See #main-blog-post-threads for others in this series.

4 Likes

I just published one on Erlang Battleground today…

5 Likes

Great :ghost: Halloween :ghost: post!

3 Likes

Excellent blog post.

I will take the opportunity to explain what is happening in the compiler when it warns or remains silent. Consider this example, similar to the one in the blog post:

warn(X, Y) -> X+Y;
warn(6, 6) -> six. 

Here an early optimization pass in the compiler will see that the first clause will always match because all patterns are (distinct) variables and there is no guard. Therefore, the compiler will remove all clauses that follow it, and at the same emit a warning for each clause that is discarded.

I call warnings that are emitted when the compiler optimizes or attempts to optimize the code opportunistic warnings. Here is another example that produces an opportunistic warning:

atom_arith() ->
    X = 42,
    Y = a,
    X + Y.

The compiler will substitute the values of X and Y into the expression, get 42 + a and try to evaluate it. When the evaluation fails, the following warning will be emitted:

t.erl:7:7: Warning: evaluation of operator '+'/2 will fail with a 'badarith' exception
%    7|     X + Y.
%     |       ^

It might seem that opportunistic warnings are a great way to get useful warnings for free with no downsides, and I also thought so when I first implemented them. I was wrong.

Because of the opportunistic nature of the warning, the compiler could remain silent for code that is very similar to code that produces a warning. For example, the compiler will not emit any warning for this code (but Dialyzer will):

atom_arith(X) ->
    X + a.

The reason is that the compiler never attempts to evaluate X + a since X is unknown.

Many such “missing warnings” have been reported as bugs to the OTP team over the years.

Another downside is that when we introduce new optimizations in the early optimization passes, the compiler could start warning about legitimate code. We would have to add extra code to the compiler to ensure that no false warnings were emitted.

Because of those downsides, we don’t plan to introduce any new opportunistic warnings in the compiler, but we will keep emitting most of the opportunistic warnings that are currently emitted.

12 Likes

Amazing explanation! Thank you very much, @bjorng :pray:

3 Likes

just found this very detailed insight into an incident at Klarna.

9 Likes

Fantastic write-up, thanks to the author.

I’m going to keep this one (on single state entry extraction) in mind. :slight_smile:

3 Likes

Hi All. Did you hear about the Erlang spellchecker called Sheldon that Felipe Ripoll developed when he was at Inaka?
Thanks to amazing mentoring by @elbrujohalcon, I was able to write my first article dedicated to how I reviewed and improved this library.
Check it out at Erlang Battleground!

5 Likes

Maybe someone already seen it, but I’m see it a first time:

$ erl
Erlang/OTP 24 [erts-12.0.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]

Eshell V12.0.3  (abort with ^G)
1> et:phone_home(1, from, to, msg, opts).
hopefully_traced
2> 

:upside_down_face:

3 Likes

But compiler behaviour like this is quite common. Lots of C compilers can only detect certain warning causes when certain optimisations are switched on and also don’t find all of them, e.g. from gcc manual:

The effectiveness of some warnings depends on optimizations also being enabled. For example -Wsuggest-final-types is more effective with link-time optimization and -Wmaybe-uninitialized does not warn at all unless optimization is enabled.

I think its in the nature of warnings that they are somewhat fuzzy.

5 Likes

Hi All. Check out what new topic about new rebar3 plugin on Erlang Battleground for spell checking of the source code with Sheldon which we made together with @elbrujohalcon.

3 Likes

Hi folks! New week - new topic! In this topic together with @elbrujohalcon we are describing a great rebar3 template(GitHub - vkatsuba/rebar3_plugin: rebar3 plugin template) what we made for fast building your own rebar3 plugins.

6 Likes

I just republished one that I wrote a decade ago…

https://tealfeed.com/oldies-goldies-scaling-erlang-yi51p

4 Likes

Hi folks! New week - new topic! In this time described stuff about how to contribute into Erlang Open Source. Enjoy! Special thanks to @elbrujohalcon , @garazdawi, @bjorng!

9 Likes

Another old one that I brought back from the web archive…

4 Likes

Hi folks! New week - new topic from Ukrainian Erlanger for Erlang Battleground. In this time we discuss pretty interesting stuff about Erlang/OTP and ASN.1.

5 Likes

To keep up with the trend… a new republished article.

3 Likes

New week, new year, new old article…
This one from #2016, about the lessons that Hernán Wilkinson shared at
Inaka on a TechDay, but translated to Erlang

4 Likes

Talking a bit on peer in upcoming OTP 25.
peer: distributed application testing – The Erlang Journey (max-au.com)

15 Likes

Great stuff! I’m looking forward to using peer to test some distributed code later this year :grinning:

3 Likes