This allows you to understand the technical constraints you have when making changes to the class. Continue adding log messages further up the call stack until you get a meaningful picture about where this class gets used, and for what purposes. Execute use cases, look for the log messages. Once you have a picture in your head how the code is organized, think of the codebase in terms of use cases. Figure out if this is an algorithm class (it calculates stuff) or a coordinator (it coordinates the actions of some number of other objects).Know where, within the architecture, does this class reside.Determine where this application interfaces with other systems or subsystems.Understand the major modules of the application.Where does data access go? Data validations? User interaction logic? Raw business logic? Understand the big picture architecture of the application.Your challenge as a developer is to find the path from one end to the other. Think of the locations where use cases begin as one end of a spectrum, and where member functions of this class get called as the other end of the spectrum. A GUI application will likely start a use case with some kind of event (application-generated or user-initiated). For a web application, an HTTP request kicks things off. You haven't specified much about the application, but generally you need to identify where the major use cases of the application begin. The biggest challenge I've had analyzing a single class is understanding the use cases that are impacted if you make changes. Knowing where in the codebase these functions get called is good. Keep this goal in mind as you trace through the code. Since we don't often read code for the sake of reading code, presumably you need to make changes to the class. ![]() And with a million-line codebase, you could go on forever. If you don't have this, you have no idea when to stop. I'm working on unbuntu 20.04 and the code is in C++.įirst, you need a goal when analyzing a class. The above snippets are very simplified depiction of the code but the pattern is the same. ![]() Here is a simplified snippet of the code just to give you an idea, this is our CLASS_inc.hxx #ifndef CLASS_inc_includedĪnd then the members of the above class somewhere in the code in other functions are called as the following example: &CLASS_inc::CLASS().LADP_set() So is there any methodology or tool or strategy in such cases to attack such problems?įor the information of those of you who might suggest "read the document", "read the comments in the code", "try to understand from the name of the member functions or class" I should say that there is absolutely no comment in the code, the name of the variables, classes and functions don't suggest anything (for instance one member function is called LADP). Now here comes the challenging part, the remaining member_functions constituting around 70% of the original member_functions are called in other functions in the code and I have no idea how to understand what they do!!! So I deleted these useless member_functions compiled my code and ran the Test_Cases (there is a huge test base in the code) and all tests passed without problem. I could understand that some of the member functions are completely useless, I simply ran the command grep -rwin member_function in src of the code which returned no trace of the memeber_function anywhere in the code, because it is simply declared but never called in any corner of the code. The members of this class are called in a couple of different parts of the code using scope resolution CLASS::member_function (well it's more complicated than that but I'm simplifying, you can also see a simplified snippet of the code down below). I need to analyse and understand the structure and utility of a file called CLASS_inc.hxx.Ī class called A_CLASS is declared in the header file CLASS_inc.hxx with all it's member functions. so you can imagine it may get messy when you have a million lines of code being developed by hundreds of developers. The reason? Because as I mentioned the code has been in development for decades and it's been through major changes, upgrades etc. The task on which I'm working at this point is understanding the use of a specific class whose functionality is unknown to almost every developer of the team. ![]() I am working on a huge code base (more than a million lines of code with a sophisticated architecture) written in C++ over the span of a couple of decades.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |