Identifying problems with our current approach
Aside from the lines of code responsible for building the user interface, our program is roughly 48 lines long.
The core of the program resides in the share-price
and avg
functions, which are responsible for querying the price service and calculating the average of a list of n numbers, respectively. They represent only six lines of code. There is a lot of incidental complexity in this small program.
Incidental complexity is complexity caused by code that is not essential to the problem at hand. In this example, we have two sources of such complexity—we are disregarding UI specific code for this discussion: the thread pool and the rolling buffer function. They add a great deal of cognitive load to someone reading and maintaining the code.
The thread pool is external to our problem. It is only concerned with the semantics of how to run tasks asynchronously. The rolling buffer function specifies a detailed implementation of a queue and how...