Chapter 13

Explain why side-effects must be as small as possible (in terms of code size).

In principle, side-effects should contain only the part of code that is a side-effect. However, when using existing libraries, the side-effect part often contains additional logic. This means that more code has to be tested, probably by using mocks. Since testing side-effects is more difficult than testing pure code, they should be stripped to the bare minimum.

What is the advantage of a protocol implemented without I/O?

A protocol implemented without I/O can be implemented only as pure code. As a consequence, such an implementation can be tested more easily and it can be reused on top of transport layers other than the original one intended.

What is the purpose of splitting logging and monitoring from features?

A feature, logging things that happen when providing this feature, and monitoring the health of this feature, are three distinct things. So, they each deserve a dedicated observable. This allows us to implement each part (feature, logging, and monitoring) without affecting the other parts.

Cite three reasons why an application is not behaving as expected.

When an application does not behave as expected, three frequent reasons are as follows:

  • A missing error handler in a subscription
  • An exception being raised by an operator (indirectly, via a function called by this operator)
  • An missing scheduler

How can a trace observer be used to debug an application where nothing happens?

Trace observers, used with the do_action operator, allow us to track where an issue came from. They can by used at different locations in the operator chains to find the operator that provokes the unexpected behavior.

What issue can occur when creating an observable without specifying an scheduler?

In applications with cycles, where cycles are handled with subjects, it is possible that a subject subscribes to an observable, but drops the received items because no observer has yet subscribed to it. One way to fix this issue is to use a scheduler so that root observable items are scheduled on the event loop.

What issue can occur when a cold observable is subscribed to several times?

A cold observable emits a new sequence of items at each subscription. So, the consequence is that as many sequences are emitted as there are subscribers. This usually leads to situations where something happens several times instead of only once.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.71.211