Introducing side effects

In Out of the Tar Pit, Ben Moseley and Peter Marks identify complexity as the single biggest obstacle to the successful development of large-scale software systems (you can read more at http://shaffner.us/cs/papers/tarpit.pdf). Essential complexity is directly inherent to solving the problem at hand. Accidental complexity is all that remains and is usually introduced by unnecessary tooling or infrastructure. The authors advocate for avoiding complexity and separating it where unavoidable. Managing our program's identity and making changes to its state should take place in well-contained locations of your code.

The with-open macro is an example of how to communicate with the outside world. It takes an input or output stream and binds it to a local var that our local expressions can interact with. The complexity here is dealing with an external resource (an input or output stream). The with-open macro handles the side effects of reading and writing to outside systems and performs resource cleanup after function completion.

The component pattern, popularized by Stuart Sierra, is widely used in the Clojure community. It isolates and manages the life cycle of units of code (called components) that have runtime state. Managing runtime state is a major area of focus for all programming languages. We've looked at Clojure's basic facilities for data transformation as well as its model of state and identity. More generally, though, we can also consider when you have to perform many simultaneous tasks. Next, we'll look at Clojure's facilities for doing this.

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

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