Chapter 10. Functional-Friendly OOP

Modern programs require asynchronous programming; these days servers must scale better than ever, and end-user applications must be more reponsive than ever. Developers are finding that they must learn asynchronous programming, and as they explore this world, they find that it often clashes with the traditional object-oriented programming that they’re accustomed to.

The core reason for this is because asynchronous programming is functional. By “functional,” I don’t mean, “it works”; I mean it’s a functional style of programming instead of an procedural style of programming. A lot of developers learned basic functional programming in college and have hardly touched it since. If code like (car (cdr '(3 5 7))) gives you a chill as repressed memories come flooding back, then you may be in that category. But don’t fear; modern asynchronous programming is not that hard once you get used to it.

The major breakthrough with async is that you can still think procedurally while programming asynchronously. This makes asynchronous methods easier to write and understand. However, under the covers, asynchronous code is still functional in nature, and this causes some problems when people try to force async methods into classical object-oriented designs. The recipes in this chapter deal with those friction points where asynchronous code clashes with object-oriented programming.

These friction points are especially noticeable when translating an existing OOP code ...

Get Concurrency in C# Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.