AI has become prevalent across many fields, including software development. Many developers use generative AI to assist them with coding. Let's explore the newcomer Llama 3 and assess how useful it is for C++ developers.
According to Meta, here's a brief description of Llama 3:
Our new 8B and 70B parameter Llama 3 models are a major leap over Llama 2 and establish a new state-of-the-art for LLM models at those scales. Thanks to improvements in pretraining and post-training, our pretrained and instruction-fine-tuned models are the best models existing today at the 8B and 70B parameter scale. Improvements in our post-training procedures substantially reduced false refusal rates, improved alignment, and increased diversity in model responses. We also saw greatly improved capabilities like reasoning, code generation, and instruction following making Llama 3 more steerable.
Some developers may not be interested in generative AI tools because they feel the results are not yet mature enough. This is particularly true of experienced developers, who can quickly identify areas where generated code could be improved. Nevertheless, I believe that for most developers, generated code can serve as a valuable starting point for implementation, refactoring, or understanding existing code.
Let's find out whether Llama 3 is useful for C++ developers.
Writing New Code
We asked Llama 3 to implement the dining philosophers problem in modern C++, and the outcome is interesting. It effectively utilizes modern C++ features, resulting in clean and comprehensible code.
However, we wondered whether Llama 3 was trained to use some of the most popular C++ libraries. To investigate, we asked it to use the Boost library to implement several algorithms, and the results were impressive. Llama 3 demonstrates a strong ability to use Boost features effectively.
Similarly, we tested Llama 3's proficiency with the Qt library by asking it to implement a login form. Once again, the results were noteworthy and demonstrated Llama 3's ability to use the Qt library effectively.
Code refactoring
After testing Llama 3 on several pieces of C++ code, we noticed that its refactoring capabilities go beyond the following tasks:
- Renaming variables.
- Removing duplicate code.
- Reformatting code.
- Removing unnecessary code.
- Modernizing C++ code.
It can also improve the design by splitting large methods into smaller ones, making the code cleaner and easier to maintain.
Explaining existing code
Understanding legacy C++ code is an important task, especially for developers who are new to a C++ project. Asking Llama 3 to explain a piece of code can be very useful—it provides a detailed description of what the code does.
Mastering C++ features
When prompted to discuss a C++ feature, Llama 3 provides concise documentation accompanied by numerous examples.
Conclusion
Based on our tests, we found that Llama 3 can be an excellent assistant for C++ developers. It is useful for tasks such as writing new code, refactoring, explaining legacy code, and learning C++ features. Therefore, to all C++ developers, I recommend giving it a try — you may be pleasantly surprised by its results.
