# Programming Erlang Book Club

**URL:** <https://forum.devtalk.com/t/programming-erlang-book-club/3243>\
**Category:** Journals & Book Clubs\
**Tags:** book-programming-erlang-2nd-edition, book-club, erlang\
**Created:** [18 October 2020 20:00 UTC](https://forum.devtalk.com/t/programming-erlang-book-club/3243 "2020-10-18T20:00:29Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Rainer](https://forum.devtalk.com/user_avatar/forum.devtalk.com/rainer/32/553_2.png) [@Rainer](https://forum.devtalk.com/u/Rainer)\
**Post date:** [28 October 2020 20:49 UTC](https://forum.devtalk.com/t/programming-erlang-book-club/3243/22 "2020-10-28T20:49:39Z")

</div>

Sometimes I had the same feeling 😉  
I thought that’s just a thing that functional programmers do differently (more math-like) than oop programmers (which I am in my job). But just needed to read it twice and then I was ok with it.

I did the second exercise of chapter 5 now, 2 different versions:

> **5.2 with recursion**
>
> ```auto
> map_search_pred(Map, Pred) ->
> list_search_pred(maps:to_list(Map), Pred).
> 
> list_search_pred([], _) -> {};
> list_search_pred([{K, V}|T], Pred) ->
> case Pred(K, V) of
> true -> {K, V};
> false -> list_search_pred(T, Pred)
> end.
> 
> ```

> **5.2 with list comprehension**
>
> ```auto
> map_search_pred2(Map, Pred) ->
> [H|_] = [{K, V} || {K, V} <- maps:to_list(Map), Pred(K, V)],
> H.
> 
> ```

Maybe we shouldn’t use the second version as it will performe bad I guess, but I like it for the small amount of code needed 😃

---

<div class="post-metadata">

**Author:** ![AstonJ](https://forum.devtalk.com/user_avatar/forum.devtalk.com/astonj/32/7_2.png) [@AstonJ](https://forum.devtalk.com/u/AstonJ)\
**Post date:** [29 October 2020 22:49 UTC](https://forum.devtalk.com/t/programming-erlang-book-club/3243/23 "2020-10-29T22:49:31Z")

</div>

I’m up to List Comprehensions so still quite a while behind you. I wanted to re-read part of the chapter but hopefully I’ll be able to catch up a bit tonight. Nice to see you are still flying thro it 😛 😆

---

<div class="post-metadata">

**Author:** ![AstonJ](https://forum.devtalk.com/user_avatar/forum.devtalk.com/astonj/32/7_2.png) [@AstonJ](https://forum.devtalk.com/u/AstonJ)\
**Post date:** [31 October 2020 06:45 UTC](https://forum.devtalk.com/t/programming-erlang-book-club/3243/24 "2020-10-31T06:45:38Z")

</div>

Another maths orientated thing I spotted (and what left me scratching my head) is on page 54, where we encounter `lists:filter(P,L)` _“which returns a new list of all the elements E in L such that P(E) is true”_.

E is easy enough to figure out (elements) as is L (list) but what’s P stand for? Felt like I was missing something 🤷‍♂️

On the quicksort example (which is as far as I’ve got atm) I was hoping to be walked through each step of the recursion too, just for that extra bit of reinforcement and clarification of what is going on exactly.

This did get me wondering whether it might be worth reading another Erlang book alongside this book - what’s better than someone teaching you something? Two people teaching you the same thing! 😆

I find getting two different perspectives on something can help, [hence wondering](https://forum.devtalk.com/t/learn-you-some-erlang-for-great-good-no-starch-press-paid-free/3598/4) what you think of reading this alongside [Learn You Some Erlang for Great Good! (No Starch Press) (Paid/Free)](https://forum.devtalk.com/t/learn-you-some-erlang-for-great-good-no-starch-press-paid-free/3598)…

* * *

**Edit** :

From the top of this post:

> [@AstonJ](#):
>
> Another maths orientated thing I spotted (and what left me scratching my head) is on page 54, where we encounter `lists:filter(P,L)` _“which returns a new list of all the elements E in L such that P(E) is true”_.
> 
> E is easy enough to figure out (elements) as is L (list) but what’s P stand for? Felt like I was missing something 🤷‍♂️

On page 60, it’s explained:

> Filters are either predicates ( **functions that return true or false** ) or boolean expressions

I don’t think I’ve heard functions that return true or false being described as _predicates_ before, at least not explicitly like this. (Would have been cool if this was mentioned nearer page 54 🙃😆)

---

<div class="post-metadata">

**Author:** ![Rainer](https://forum.devtalk.com/user_avatar/forum.devtalk.com/rainer/32/553_2.png) [@Rainer](https://forum.devtalk.com/u/Rainer)\
**Post date:** [31 October 2020 22:17 UTC](https://forum.devtalk.com/t/programming-erlang-book-club/3243/25 "2020-10-31T22:17:00Z")

</div>

In exercise 5 ‘Pred’ is also used, i just noticed it then 😃

I agree it would be good to read a second book parallel to deepen the knowledge, just I fear then we’ll never end 😛

I was busy renovating a room for my new home office, so no progress today…

---

<div class="post-metadata">

**Author:** ![AstonJ](https://forum.devtalk.com/user_avatar/forum.devtalk.com/astonj/32/7_2.png) [@AstonJ](https://forum.devtalk.com/u/AstonJ)\
**Post date:** [31 October 2020 22:33 UTC](https://forum.devtalk.com/t/programming-erlang-book-club/3243/26 "2020-10-31T22:33:11Z")

</div>

> [@Rainer](#):
>
> In exercise 5 ‘Pred’ is also used, i just noticed it then 😃

Least I know what it means now 😅

> [@Rainer](#):
>
> I agree it would be good to read a second book parallel to deepen the knowledge, just I fear then we’ll never end 😛

I usually find books are split into separate parts, which helps make it easy to match similar books together. So we could start [Learn You Some Erlang for Great Good! (No Starch Press) (Paid/Free)](https://forum.devtalk.com/t/learn-you-some-erlang-for-great-good-no-starch-press-paid-free/3598) at the end of part 2? (So after chapter 10)… or we can see how it goes for now? If things start getting hairy we could always start it sooner or if we find it’s not needed, hold off 🤓

> [@Rainer](#):
>
> I was busy renovating a room for my new home office, so no progress today…

That’s good to hear Rainer! It’ll give me chance to catch up 🤣

Post pics when it’s all done! 👍

---

<div class="post-metadata">

**Author:** ![AstonJ](https://forum.devtalk.com/user_avatar/forum.devtalk.com/astonj/32/7_2.png) [@AstonJ](https://forum.devtalk.com/u/AstonJ)\
**Post date:** [1 November 2020 08:00 UTC](https://forum.devtalk.com/t/programming-erlang-book-club/3243/27 "2020-11-01T08:00:44Z")

</div>

Split this topic on 1 November 2020 08:00 UTC

3 posts were split to a new topic: [Which of the Visual Studio Code extensions do you use for Erlang development?](https://forum.devtalk.com/t/which-of-the-visual-studio-code-extensions-do-you-use-for-erlang-development/3650)

---

<div class="post-metadata">

**Author:** ![Rainer](https://forum.devtalk.com/user_avatar/forum.devtalk.com/rainer/32/553_2.png) [@Rainer](https://forum.devtalk.com/u/Rainer)\
**Post date:** [3 November 2020 07:31 UTC](https://forum.devtalk.com/t/programming-erlang-book-club/3243/28 "2020-11-03T07:31:15Z")

</div>

I’ll proceed with only reading this book at the moment, as long as I don’t get into bigger troubles 😉  
I shouldn’t start more things, already have too many spawned processes 😃

Finished reading chapter 6, nothing exceptional here (ok, bad joke, it’s about exceptions).  
Error handling isn’t the most exciting topic for me, but I like Erlangs ‘fail fast’ & ‘let it crash’ strategy.

Do we have a homeoffice thread? Or so far just the standing desk thread?

---

<div class="post-metadata">

**Author:** ![AstonJ](https://forum.devtalk.com/user_avatar/forum.devtalk.com/astonj/32/7_2.png) [@AstonJ](https://forum.devtalk.com/u/AstonJ)\
**Post date:** [3 November 2020 12:14 UTC](https://forum.devtalk.com/t/programming-erlang-book-club/3243/29 "2020-11-03T12:14:47Z")

</div>

> [@Rainer](#):
>
> I’ll proceed with only reading this book at the moment, as long as I don’t get into bigger troubles 😉  
> I shouldn’t start more things, already have too many spawned processes 😃
> 
> Finished reading chapter 6, nothing exceptional here (ok, bad joke, it’s about exceptions).  
> Error handling isn’t the most exciting topic for me, but I like Erlangs ‘fail fast’ & ‘let it crash’ strategy.

Haha, cool, I’ll stick with it too for now then - tho I haven’t had much time for it. Hope to catch up soon tho! Wel done on getting through chapter 6!!

> [@Rainer](#):
>
> Do we have a homeoffice thread? Or so far just the standing desk thread?

There’s this one 🤓

> [@Post Your Workspace](https://forum.devtalk.com/t/post-your-workspace/293):
>
> Figured this would be a cool topic and maybe provide some inspiration for those who are just starting to work from home. Feel free to share your remote and/ or office setups here! Side Note: My twins needed a playroom, so I gave up my office and built a nook next to our fireplace. It’s definitely a lot smaller than what I’m use to, but it’s been really nice having a window/view. Also not having toys scattered across our house has helped with my sanity. joy

---

<div class="post-metadata">

**Author:** ![AstonJ](https://forum.devtalk.com/user_avatar/forum.devtalk.com/astonj/32/7_2.png) [@AstonJ](https://forum.devtalk.com/u/AstonJ)\
**Post date:** [6 November 2020 21:48 UTC](https://forum.devtalk.com/t/programming-erlang-book-club/3243/31 "2020-11-06T21:48:55Z")

</div>

Whoo hoo welcome to the club DG 🤓 I am sure you will catch up to me pretty soon as this time of year is always hectic for me.

Unfortunately I haven’t had much time to get further into the book (sorry @Rainer!) but I keep meaning to post a thread about visualising recursions - I’ll try to do that soon and mention it in this thread 😃 How you getting on @Rainer - bet you’re way ahead now 😆

---

<div class="post-metadata">

**Author:** ![Rainer](https://forum.devtalk.com/user_avatar/forum.devtalk.com/rainer/32/553_2.png) [@Rainer](https://forum.devtalk.com/u/Rainer)\
**Post date:** [7 November 2020 20:48 UTC](https://forum.devtalk.com/t/programming-erlang-book-club/3243/32 "2020-11-07T20:48:22Z")

</div>

This week was very busy at work, so no big progress 😉  
Just this:

> **Exercise 6.1**
>
> -module(ex6).  
> -export([read1/1, read2/1]).
> 
> read1(File) -\>  
> {ok, Bin} = file:read\_file(File),  
> Bin.
> 
> read2(File) -\>  
> case file:read\_file(File) of  
> {ok, Bin} -\> Bin;  
> {error, Why} -\> throw({filenotfound, Why})  
> end.

I did 2 different versions, in the first one I just let pattern matching throw the exception, in the second I did it myself.

---

<div class="post-metadata">

**Author:** ![AstonJ](https://forum.devtalk.com/user_avatar/forum.devtalk.com/astonj/32/7_2.png) [@AstonJ](https://forum.devtalk.com/u/AstonJ)\
**Post date:** [8 November 2020 01:35 UTC](https://forum.devtalk.com/t/programming-erlang-book-club/3243/33 "2020-11-08T01:35:37Z")

</div>

> [@Rainer](#):
>
> This week was very busy at work, so no big progress 😉

No complaints here - it gives me and @DevotionGeo a chance to catch up 😆

Glad you are managing to get through the challenges tho 👍

---

<div class="post-metadata">

**Author:** ![DevotionGeo](https://forum.devtalk.com/user_avatar/forum.devtalk.com/devotiongeo/32/1140_2.png) [@DevotionGeo](https://forum.devtalk.com/u/DevotionGeo)\
**Post date:** [8 November 2020 02:16 UTC](https://forum.devtalk.com/t/programming-erlang-book-club/3243/34 "2020-11-08T02:16:10Z")

</div>

Thank you Aston!  
I can spare only a small chunk of time to this book so you and @Rainer will be ahead of me, but I shall try to catch up.

---

<div class="post-metadata">

**Author:** ![Rainer](https://forum.devtalk.com/user_avatar/forum.devtalk.com/rainer/32/553_2.png) [@Rainer](https://forum.devtalk.com/u/Rainer)\
**Post date:** [11 November 2020 20:19 UTC](https://forum.devtalk.com/t/programming-erlang-book-club/3243/35 "2020-11-11T20:19:04Z")

</div>

Welcome to our club @DevotionGeo 🙂

I skipped exercise 6.2 as it’s not so interesting for me at the moment, and continued reading.  
I’m now in middle of chapter 7, and it’s exciting 😃  
It’s about binaries and how we can pattern match on single bits, that’s cool stuff. Especially if I think how I’d do it in C++ and what amount of awkward code I’d produce…

On a side note: In one example the notation 16#12345678 is used, which I seem to have missed (or already forgotten again) in chapter 3. It means this is Base16 notation, which is HEX. Another example: 2#11 is binary and evaluates to the integer 3.

---

<div class="post-metadata">

**Author:** ![DevotionGeo](https://forum.devtalk.com/user_avatar/forum.devtalk.com/devotiongeo/32/1140_2.png) [@DevotionGeo](https://forum.devtalk.com/u/DevotionGeo)\
**Post date:** [12 November 2020 07:35 UTC](https://forum.devtalk.com/t/programming-erlang-book-club/3243/36 "2020-11-12T07:35:58Z")

</div>

Thank you @Rainer! 🙂

---

<div class="post-metadata">

**Author:** ![Rainer](https://forum.devtalk.com/user_avatar/forum.devtalk.com/rainer/32/553_2.png) [@Rainer](https://forum.devtalk.com/u/Rainer)\
**Post date:** [15 November 2020 21:58 UTC](https://forum.devtalk.com/t/programming-erlang-book-club/3243/37 "2020-11-15T21:58:04Z")

</div>

The exercises for chapter 7 are quite tricky, but finally I finished them 😃

> **Exercise 7**
>
> ```auto
> -module(ex7).
> -export([reverse_binary/1,term_to_packet/1, packet_to_term/1, test/0, reverse_bits/1]).
> 
> % 7.1
> reverse_binary(Binary) ->
> reverse_binary(Binary, <<>>).
> 
> reverse_binary(<<>>, Binary) ->
> Binary;
> reverse_binary(<<Head, Tail/binary>>, Accumulator) ->
> reverse_binary(Tail, <<Head, Accumulator/binary>>).
> 
> % 7.2
> term_to_packet(Term) ->
> Binary = term_to_binary(Term),
> N = byte_size(Binary),
> <<N:4/unit:8, Binary:N/binary>>.
> 
> % 7.3
> packet_to_term(Packet) ->
> <<N:4/unit:8, Binary:N/binary>> = Packet,
> binary_to_term(Binary).
> 
> % 7.4
> test() -> 
> P = term_to_packet("DevTalk"),
> "DevTalk" = packet_to_term(P).
> 
> % 7.5
> reverse_bits(Binary) ->
> Bitlist = [X || <<X:1>> <= Binary],
> Reversedlist = lists:reverse(Bitlist),
> << <<X:1>> || X <- Reversedlist >>.   
> 
> ```

especially 7.2 took me a while…

---

<div class="post-metadata">

**Author:** ![Rainer](https://forum.devtalk.com/user_avatar/forum.devtalk.com/rainer/32/553_2.png) [@Rainer](https://forum.devtalk.com/u/Rainer)\
**Post date:** [25 November 2020 20:54 UTC](https://forum.devtalk.com/t/programming-erlang-book-club/3243/38 "2020-11-25T20:54:14Z")

</div>

I’ve read chapter 8, or better skimmed, as Joe recommended 😉  
Most interesting thing for me: Dynamic code loading. A very nice thing in Erlang 🙂

Also I started the exercises, but not yet finished:

> **Exercise 8.1**
>
> ```auto
> count_dict_exports() ->
> Modinfo = dict:module_info(),
> {_, Exports} = lists:keyfind(exports, 1, Modinfo),
> length(Exports).
> 
> ```

> **Exercise 8.2**
>
> ```auto
> count_exports(Mod) ->
> {_, Exports} = lists:keyfind(exports, 1, Mod:module_info()),
> length(Exports).
> 
> module_fn_count() ->
> List = code:all_loaded(),
> Touples = [{Module, count_exports(Module)} || {Module, _} <- List],
> Touples.
> 
> max_exports({Mod, Count}, []) -> {Mod, Count};
> max_exports({Mod, Count}, [{_, C} | T]) when Count > C-> max_exports({Mod, Count}, T);
> max_exports({_, Count}, [{M, C} | T]) when Count =< C-> max_exports({M, C}, T).
> 
> run()->
> max_exports({init, 0}, module_fn_count()).
> 
> ```

Still thinking how I should solve the next Exercise 😃  
Hope you’ll catch up soon, it’ll be very interesting to compare our solutions.

---

<div class="post-metadata">

**Author:** ![AstonJ](https://forum.devtalk.com/user_avatar/forum.devtalk.com/astonj/32/7_2.png) [@AstonJ](https://forum.devtalk.com/u/AstonJ)\
**Post date:** [26 November 2020 01:58 UTC](https://forum.devtalk.com/t/programming-erlang-book-club/3243/39 "2020-11-26T01:58:56Z")

</div>

I’m so sorry for not being able to read anymore Rainer! This time of year is always a bit hectic for me, hopefully I’ll be able to get back to it soon 😃 Hopefully it’s given some time for @DevotionGeo to catch up as well 🤓

What do you think of the book so far? Dynamic code loading - I can’t wait to get to that!

---

<div class="post-metadata">

**Author:** ![Rainer](https://forum.devtalk.com/user_avatar/forum.devtalk.com/rainer/32/553_2.png) [@Rainer](https://forum.devtalk.com/u/Rainer)\
**Post date:** [28 November 2020 21:14 UTC](https://forum.devtalk.com/t/programming-erlang-book-club/3243/40 "2020-11-28T21:14:07Z")

</div>

My time is also very limited at the moment, but usually I’m reading a bit just before sleeping 😉  
I like the book, but the more I progress the more annoyed I get by C# (my daily business) 😛 I’m liking the Erlang syntax, which came unexpected 🙂

I continued with the exercises, so here’s the second (of three) part from 8.2:

> **Exercise 8.2 part 2 (most common function name)**
>
> ```auto
> -module(ex8).
> -export(most_common_funname/0]).
> 
> all_functions() ->
> Exports = [lists:keyfind(exports, 1, Module:module_info()) || {Module, _} <- code:all_loaded()],
> Functions = lists:flatten([Funlist || {exports, Funlist} <- Exports]),
> Functions.
> 
> get_function_counts([{Funname, _} | T])->
> case get(Funname) of
> undefined -> put(Funname, 1);
> X -> put(Funname, X + 1)
> end,
> get_function_counts(T);
> get_function_counts([]) -> get().
> 
> most_common_funname() ->
> [{Funname, _} | _] = lists:sort(fun({_, A}, {_, B}) -> A > B end, get_function_counts(all_functions())),
> Funname.
> 
> ```

I really wonder how someone experienced wold solve this. I used the process dictionary that was introduced in chapter 8 as a mutable data structure, but I think this can’t be considered ‘good practice’…

---

<div class="post-metadata">

**Author:** ![mafinar](https://forum.devtalk.com/user_avatar/forum.devtalk.com/mafinar/32/723_2.png) [@mafinar](https://forum.devtalk.com/u/mafinar)\
**Post date:** [30 November 2020 18:57 UTC](https://forum.devtalk.com/t/programming-erlang-book-club/3243/41 "2020-11-30T18:57:01Z")

</div>

Thanks to all the encouraging comments in this thread, I ordered the book. It arrives on Saturday! I’ll join y’all then!

---

<div class="post-metadata">

**Author:** ![AstonJ](https://forum.devtalk.com/user_avatar/forum.devtalk.com/astonj/32/7_2.png) [@AstonJ](https://forum.devtalk.com/u/AstonJ)\
**Post date:** [30 November 2020 19:50 UTC](https://forum.devtalk.com/t/programming-erlang-book-club/3243/42 "2020-11-30T19:50:50Z")

</div>

Whoo hooo welcome to the club @mafinar 👍 👍 👍

I hope to get back in to this in the next week or two so you have plenty of time to catch up 🤓

[Previous page](https://forum.devtalk.com/t/programming-erlang-book-club/3243.md?page=1)

[Next page](https://forum.devtalk.com/t/programming-erlang-book-club/3243.md?page=3)
