When we discuss the architecture of a code base, we often qualify a piece of a given code by using terms such as high level or low level. This is common vocabulary and we all intuitively know what it means. A piece of code A (whether it is a method, a class, a namespace, or an assembly) is considered as higher level than a piece of code B if A is using B while B doesn’t know about A. From this simple definition, we can order pieces of a code in our program as shown in the following diagram:
Thus, we can say that our code that doesn’t use anything has a level of 0, and we can say that our code that is using only tier code or code of level 0 has a level of 1. Etc…
We have just defined a code metric that is named Level. To be computed, the Level metric just need a graph of dependencies. If you consider the graph of dependencies between the methods of your program, you can assign a Level to your methods.
The level metric could be used to understand how a use case works. The idea is to search for the methods called by a specific method with their levels and identify the complete workflow.
When discovering a code base we don’t know exactly where a use case begin, for this reason the level is very useful to detect high level methods using some low level treatments.
Let’s analyze the FileZila project using CppDepend and try to explain how the level metric could be helpful to understand the code base.
FileZilla is free; cross-platform FTP application software consists of FileZilla Client and FileZilla Server.
The main goal of FileZilla is to Transfer files in FTP, SFTP, and encrypted FTP such as FTPS and SFTP, for this reason it uses sockets. To discover methods related to the transfer, we have only to search for all methods using directly or indirectly the socketaddr_in struct.
High level methods using socketaddr_in and their levels of use:
We have identified two most high level methods using the sockets, and we can search now for all methods used by them to understand how they work.
The OnReceive method is the entry point of the treatments after receiving data. let’s search for the first level methods used by it.
To go deeper, we can search for the methods used in all levels. To do this, we can search for all the methods used directly or indirectly by OnReceive.
As we can discover in the treemap view which is shown in blue color , all the methods concerned with the above CQLinq query, more than 50% of the engine methods are invoked, therefore this query is not very interesting to explore.
However we can filter thie result and search only for methods used by OnReceive in the Level 1 and 2 and not existing in the third party librararies.
This result is more suitable to understand how the OnReceive method works.
The Level metric is very useful to navigate across the entire codebase from botom to up and vice versa. Which help to understand how some methods work internally.