JEG2

JEG2

Author of Designing Elixir Systems with OTP

Thanks so much for the kind words!

2
Post #53
outluch

outluch

hi. thanks for book.
i want to tell about some inconsistence. on page 160 you say that poolboy is just another elixir dependency and we just need to configure it in our application.ex. but earlier you have shown that classical elixir dependency is usually an otp app and it even doesnt need to be added in the application.ex. it is weird a bit. as i know, poolboy is erlang library and we use it in the elixir app and that is why we need to start it manually. am i right?

0
Post #54
JEG2

JEG2

Author of Designing Elixir Systems with OTP

There are different strategies you can use to allow users of your projects to interact with your code. Chris Keathly has a nice breakdown of the choices in this blog post.

One strategy is, as you said, to just build your own application that’s started by the OTP (“OTP applications” in Chris’s post). Sometimes though, it’s better to allow other applications to start some of your processes in their application tree. This gives the calling code a lot of choices about what exactly gets started and how your code will interact with those pieces.

Poolboy uses the latter strategy (called “Providing a Supervision Tree” in Chris’s post). This allows you to configure how many worker processes are started and point them at your modules that you want to run.

Hope that helps!

2
Post #55
NicoGim

NicoGim

Hi!

I am following the book right now very seriously, writing every piece of code suggested and trying to understand as much as I can everything that’s going on.

Thank you for this work, it is an awesome book to learn about… how to actually shape programs. Basic syntax tutorials are great, LYSEFGG as well, but then when you start you first project without guidance, it can still be quite rough. This book fills this gap quite nicely.

I’ve got a little issue though with the code presented in the part that refers to the tests.
It is suggested to write this file. (Let me know if you want me to get it down from GitHub later).

When trying to run it with “mix test” I got:

warning: variable “right” does not exist and is being expanded to “right()”, please use parentheses to remove the ambiguity or change the variable name
nofile:1

  1. test a right response and a wrong response building responses checks answers (ResponseTest)
    test/test/response_test.exs:8
    ** (CompileError) nofile:1: undefined function right/0

So this “test” syntax for getting access to the new field in the context map does not work, right?
I need to use something like:

test “description”, context

And then access context fields directly? I tried, indeed, without success.

If that’s true then I think the book needs to be updated. The downloaded source code that goes together with the book contain different versions of the code, without this fixture.

0
Post #56
srowley

srowley

There’s nothing wrong with the file linked here; it is upstream. This file is using the QuizBuilders module to build up the fixtures used, and there is a typo in that module file in the function template_fields/1:

 11   def template_fields(overrides \\ []) do
 12     Keyword.merge(
 13       [
 14         name: :single_digit_addition,
 15         category: :addition,
 16         instructions: "Add the numbers",
 17         raw: "<%= @left %> + <%= right%>", #<---This should be @right, not right
 18         generators: addition_generators(single_digits()),
 19         checker: &addition_checker/2
 20       ],
 21       overrides
 22     )
 23   end

So the issue is not the pattern match on “right” (as in not wrong) in this test, it’s that when that little template is compiled, it thinks “right” (as in not left) is a function instead of an assign.

A tangent -

I read the first few chapters of this book and really enjoyed it. In particular the section on how important it is to pick the right data structures really improved how I approach any new project. I had not yet read the testing chapter, which I just skimmed as part of looking at your problem. I really didn’t like all of the fixture setup. Being able to write something like assert right.correct seems elegant on its face, but I had to trace that statement several levels up the call stack just to figure out what function was actually being tested. The whole set of tests would have been more readable (to me) if the setup was in a setup block at the top of the page (so I could see how the assigns were getting built step by step without tracing through a bunch of supporting functions), and the test actually called the function being tested so I could see what it was and what arguments were passed to it. This would mean some code duplication, but less magic, and that tradeoff would have been worth it to me as a reader of the code.

0
Post #58
JEG2

JEG2

Author of Designing Elixir Systems with OTP

That error isn’t actually referring to your test syntax. It’s a problem with this line:

https://github.com/NicoGim/elixir-learn/blob/master/test/support/quiz_builders.exs#L17

The right in that template should be @right.

Hope that helps!

1
Post #59
JEG2

JEG2

Author of Designing Elixir Systems with OTP

Thanks for the kind words!

0
Post #60
JEG2

JEG2

Author of Designing Elixir Systems with OTP

This is a fair critique. Our reasoning was that we were testing a pretty complex system in the book and we wanted to use some abstraction to ease the burden of keeping it all in your head at once. But I totally hear you that we could have over done it in some areas. I’m sure we did.

0
Post #61
NicoGim

NicoGim

Thanks for the help! :slight_smile:
Guess I still gotta improve my Elixir debugging skills.
Btw, I fixed all the small errors and typos and now it is passing all the test. For anyone in trouble going through the book, feel free to check out the GitHub repo.

0
Post #62
jmurphyweb

jmurphyweb

I’m currently reading Elixir In Action (chap 11) and have found it a beautiful introduction to OTP. (thanks @sasajuric :pray:)

Having flicked through some pages of Designing Elixir Systems with OTP, and it seems there are some similarities (building own genserver etc).

Whilst I’m certain Designing Elixir Systems with OTP would be a fantastic read regardless, I just wanted to get peoples thoughts on whether it is a good choice as a follow up for EIA?

Also, is there a 2020 Elixir Forum discount for PragProg books?

Very much looking forward to this!

4
Post #63