Open ccczzc opened 4 months ago
I don't think this is necessary. Personally speaking, I prefer the current design. You can provide an implementation of your design, though.
I agree encapsulating all functionalities in a class is more modern C++. I'm not a production-level C++ programmer so I did not realize I could do that though. However, we are just writing a small toy program with no more than 1K LoC. Writing in C or C++ style hardly makes a difference.
This approach aims to eliminate the need for passing parameters between functions and minimize the usage of global variables.
I don't think there is anything wrong with global variables. Sharing states among class members across compilation units is eventually implemented as global variables with implicit compile-time checks, which can help preventing bugs in production. But again, we are a toy project.
Considering that our codebase is written in C++, I would like to suggest encapsulating the functions and global variables in the
main.cc
,resolve.cc
, andrelocation.cc
files within aStaticLinker
class. This approach aims to eliminate the need for passing parameters between functions and minimize the usage of global variables.By encapsulating the relevant functionality within a class, we can achieve better organization and modularity in our codebase. The class can act as a container for related functions and variables, allowing for better encapsulation and reducing the reliance on global state.