DEV Community

Pan Chasinga
Pan Chasinga

Posted on

Concurrency in Go vs Erlang

Liquid syntax error: Variable '{{_, StatusCode, _}' was not properly terminated with regexp: /\}\}/

Top comments (7)

Collapse
 
felbit profile image
Martin Penckert • Edited

Good article, thank you. I always wanted to take the time reading up, how Go handles this. Just a few notes on Erlang, here:

First, I wanted to make the point Alexander did already. Erlang’s built in functions with a need for performance are written in optimized C. Also you can easily cross compile Erlang code to C and get pretty good performance.

And another thing: you second Erlang program has a bug: in line 4 you reference Code, but Code is unbound at that point.

Furthermore, just as a side note, the Erlang code is not idiomatic (function names should be snake_cased, deep pattern matching like in line 3 should be a descriptive call (e.g.

print_status_code(Url) ->
  %% ...
  {ok,StatusCode} = get_status_code(Res),
  %% ...

get_status_code({_,StatusCode,_},_,_}) -> {ok,StatusCode}.
get_status_code(UnknownFormat) -> {error, UnknownFormat}.

), and I personally wouldn’t take a foreach (ever) but map over the list).

Collapse
 
pancy profile image
Pan Chasinga

Thank you for the corrections!

Collapse
 
alexwb1 profile image
Alexander Barnard

One thing to mention, you brought up a good point that Erlang is bad at numerical linear algebra, computer vision, etc., which is why these types of routines in Erlang are actually C functions that are called from Erlang. This way, numerical calculations are actually run as C code

Collapse
 
zigster64 profile image
Scribe of the Ziggurat

Update for 2021
Erlang now has jit compilation since otp24 which narrows the speed gap (or perceived gap anyway)

Erlang's gc model avoids the problems that go suffers from which can affect performance.

Erlang has a much cleaner interface to C or Rust or Zig for performance work

So if performance Is important, I would choose Erlang over go any day if the week.

Collapse
 
pancy profile image
Pan Chasinga

Thanks for the update. Love it.

Collapse
 
anshumanr profile image
anshumanr

Good to read. You have me interested in functional programming.

Collapse
 
wongjiahau profile image
WJH

Can you also compare these concurrency model with Rust or C?