Debugging chained operations
Throughout this book, we’ve used method chaining, whereby multiple operations are stacked one after another instead of assigning each operation to a variable each time. Method chaining not only removes the repetitive code but also helps you design your code with relevant operations in a chain. This helps readers understand your code easily and reduces the mental burden of making sense of the context of your logic.
The potential downsides of method chaining are readability and difficulty in debugging. The former can be solved by not chaining operations horizontally. When you put each operation on a new line, readability will be improved. What about debugging? The same thing is applied there. When you separate each operation on a new line, you’ll be able to inspect exactly why an error is occurring, especially with tools such as debugger in your IDE.
In this recipe, we’ll cover how you can troubleshoot, test, and debug your chained...