liveBook · Manning

Tree of function calls

As explained in Data-Oriented Programming: Reduce software complexity

A tree of function calls is a hierarchical model whose root is a function and whose child nodes are the functions called by each parent function, with leaves representing functions outside the application code base or functions that call no other functions.

Before writing a unit test, visualize the code flow as a tree. Put the function under test at the root, then expand each application function it calls. Stop at external functions or functions that call nothing; those nodes are leaves. Calls inside anonymous functions still belong beneath the function containing them. section 6.2.1

Use the tree to decide where testing effort belongs:

  • Cover lower-level functions with more cases because they tend to handle less complex data. section 6.6
  • Keep upper-level tests minimal when their called functions already have unit-test coverage and are assumed to work. section 6.2.3
  • For mutations, test the calculation-heavy function first; wrapper functions usually need fewer tests. section 6.4

From search flow to mutation

A search tree can begin at Library.searchBooksByTitleJSON and branch to Catalog.searchBooksByTitle, _.get, and JSON.stringify. A mutation tree begins at System.addMember, passes through Library.addMember, and reaches UserManagement.addMember, where the main state-changing behavior is tested. section 6.2.1 section 6.4

Figure 6.1 The tree of function calls for the search query code flow

View the search-query call tree as a visual starting point for mapping a function’s dependencies. section 6.2.1

How Data-Oriented Programming: Reduce software complexity covers it

How deep it goes
Defines recursive expansion through application functions and connects tree depth with data complexity and test quantity.
Examples
Uses Library.searchBooksByTitleJSON, Catalog.bookInfo, and System.addMember to demonstrate search, record transformation, and state mutation.
What you can do after
Apply it to map a function’s calls and allocate unit-test cases across lower-level functions, wrappers, queries, and mutations.
How it connects
Connects unit tests with mutations, queries, data manipulation, and function dependencies.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Oriented Programming: Reduce software complexity. The section links point to the parts of the book it draws on.