Before contributing effectively to a C++ project , it’s recommended to take a tour in the existing code base, and identify some of its design and implementation choices. Indeed your contribution must be coherent with the existing source code.
Here are some basic steps to follow before contribute to a C++ project:
1-Build
Before going further, the first step is to build the project, it’s an obivious task for some projects but it could be a headache for other ones. If the build is very complicated, it’s recommended to well document it or create one entry point script to build the project.
Every C++ developer should know the basics of preprocessing, compilation and linking, there are many web resources to explain these phases. Indeed many C++ beginner developers spent many hours to understand why a code does not compile or link, and they could win a lot of time if they dedicate only few hours to understand how the build phase works.
2-Debug
Debugging is your first friend to understand how a code works. You must ensure that you can debug your project without problem. Furthermore it’s recommended to master some advanced debug techniques to gain many hours when resolving a bug or try to understand the behavior of a specific source code.
3-Identify the paradigms used
C++ is a multi paradigm language and it’s very important to know for a defined project which paradigm is mostly used. Indeed each one has its specificities and a developer must master some basic concepts of the paradigm used before study the project code base.
For generics don’t hesitate to discover the static polymorphism, Traits and Policy-based design techniques and for OOP it’s recommended to master virtual methods, polymorphism and inheritence.
4-Identify the style used
Before adding your contribution, it’s recommended to know which coding style is used, sometimes it’s documented like the google style guide, but usually it’s not the case and you have to read some source code files to check:
- Naming convention.
- Code formatting.
- Is smart pointers used instead of raw pointers?
- Comment style.
- Uses of exceptions.
- Include guard technique used.
- ……
The goal is to still coherent with the existing code base. You can be assisted by CppDepend and its CQLinq query language to ensure that some coding rules are not violated.
5-Identify the C++ frameworks and libraries used by the project
Using frameworks and libraries accelerate the development. It’s very important to know which libraries are used and most important what perimeter they cover. It helps to avoid reinventing the wheel or use another library.
If you have to use a feature from a third party library, the best way is to search in the existing code where it’s used. It could be used differently in many places, and in such case prefer the code snippet from the well tested source code.
6-Identify a use case and debug it
The best way to have a concrete idea about the project design and implementation choices is to study a use case from the front to the back. For that you can add breakpoints in some places and debug it step by step to identify:
- The use case workflow.
- How the different levels communicate between them.
- The design patterns used if any.
- How the third party libraries are used, and check if the code is highly coupled with them or not by using abstract classes.
7-Master the basics of the version control system used
The version control system is the management of source changes . Changes are usually identified by a number or letter code, termed the “revision number”, “revision level”, or simply “revision”. Revisions can be compared, restored, and with some types of files, merged.
Many version control systems exist like Git, SVN, CVS, ClearCase and it’s recommended to master their basics, many times the beginner developers did some big mistakes when managing their source code.and it impact a lot their contributions.
And don’t forget to Communicate with the team
Communicate with the other project developers is the easy way to accelerate your integration into a specific project and ensure a good quality for your contributions. Don’t hesitate to talk with them about the build process, the style used, the third party libraries used and so on. However avoid to disturb them each 5 min.
Summary
Be coherent with the existing source code is very important to let it more readable and maintainable. Before contributing it’s better to discover how the existing code is designed and implemented and even it could take few days it will improve the quality of your contributions.