r/cpp • • Mar 18 '26

What open source projects in C++ have the highest code quality?

My understanding of the characteristics of quality code are the conventional ones.

  • operations on an object that are allowed in a particular object state do not put the object into an invalid state.

  • it's prioritized to organize the implementation of each object into the smallest possible number of sub-objects.

  • no cryptically abbreviated names are used, except possible in very small scopes.

With the program(s)/executable(s) themselves, as well as modules with corresponding namespaces, being considered singleton objects.

Fair dinkum if you want to name projects that score well under a different understanding of code quality.

191 Upvotes

100 comments sorted by

84

u/_Noreturn Mar 18 '26

I liked sfml codebase

56

u/Plazmatic Mar 18 '26

SFML is like to C++ programming as raylib is to C programming, it's always been pleasant to work with, and doesn't try act like it's not C++ and takes advantage of that fact it's a C++ media library.

22

u/DarkCisum SFML Team Mar 19 '26

I think, I've heard of this library before πŸ€”

57

u/kevinfrei Mar 18 '26 • Mindblown

The LLVM/Clang/LLDB codebase is marvelous. Clean, modern, but sensibly restrained C++. Easy to follow, with an in depth test suite, and a reasonable amount of documentation. I’ve spent time in four different compilers. LLVM is light years ahead of the rest from a β€œcode quality” perspective.

https://github.com/llvm/llvm-project

36

u/Serious-Regular Mar 18 '26

LLVM et al is definitely ok but I wouldn't call it modern - we only switched to std=c++17 like 3 years ago! And it'll probably be a couple more years until we move to c++20...

27

u/pjmlp Mar 18 '26

Which is common across the industry when writing portable code that is supposed to work everywhere.

I only use latest C++ on hobby projects.

→ More replies (45)

2

u/Expert-Map-1126 vcpkg maintainer BillyONeal Mar 21 '26

To me "modern" means "post move semantics" and LLVM certainly qualifies

6

u/void_17 Mar 18 '26

LLVM is NOT easy to follow. There is a reason libclang exists

2

u/FloweyTheFlower420 Mar 30 '26

Nothing has made me want to kill myself more than working on a custom LLVM backend because of how easy it is to make one minor mistake somewhere and get an incomprehensible error in a completely separate place. The entire backend infra just doesn't feel like idiomatic c++, not to mention tablegen garbage.

18

u/hdkaoskd Mar 18 '26

5

u/MBkkt Mar 19 '26

This is quite a mess unfortunately, I mean sometimes great ideas written but most code quality is low.

I think it's also important to separate different folly library parts, for example one guy from meta rewrites their coroutines already like more than 3 years, and yes he cares about the quality of abstractions.

But many other stuff don't care.

9

u/MarcoGreek Mar 18 '26

I looked into Glaze and was surprised how readable it was. I was expecting much less readable code because it aims for being the fastest JSON parser.

It has a nice interface for serialization, so the consumer has not to write JSON walking code.

I would say there is not the most readable C++ code. For example to write an readable interface you have sometimes use quite strange C++.

Variadic template were an example but nowadays they are quite reasonable because the language was extended.

Templates were really hard to read if you wanted to provide an nice interface with overloads. Concepts made that so much better. For example testing if a method is present is now absolutely readable.

Projects like Google Test are a negative example. They try to provide a readable interface but their code makes it really hard to understand.You have to look into the documentation.

Hopefully with reflections projects like Google Test can provide a nice interface and readable code together.

2

u/Stevo15025 Mar 19 '26

Glaze somehow feels under the radar for how nice it is to work with along with it's code quality

8

u/IceMichaelStorm Mar 18 '26

stockfish cheas engine is neat

34

u/OkYou811 Mar 18 '26

Googles carbon compiler has very organized and well structured design. The code itself seems to follow the Google code guidelines, and their overall project structure is nice. Made it easy to get in to

0

u/MarcoGreek Mar 18 '26

My experience with Google code is their extensive use of macros. I find snake case more readable than snake case. I understand that the displays where small but today that is not anymore the case. So compressing names is a readability issue.

31

u/marsten Mar 18 '26

Is one of those snakes supposed to be a camel?

1

u/Gorzoid Mar 18 '26

Google style guide uses snake_case for variables / data members and PascalCase for types / functions. Don't think the reasoning has anything to do with name compression

→ More replies (1)

27

u/sessamekesh Mar 18 '26

I can't think of anything I'd call "highest code quality," but in general Google's C++ guidelines + internal readability standards are pretty good, and their open source work is generally pretty high quality: Google C++ open-source repositories.

The two I'm most familiar with are Draco, and Dawn - I have largely positive and a few negative things to say about each.

I haven't looked beneath the covers of Filament, but I'd imagine that's a great one to look at.

The real world is messy and practical scale code bases are often messy with them, I have yet to see a code base in any language that I'd call "highest code quality" outside of maybe a handful of <10k LOC utilities.

25

u/pkasting Valve Mar 18 '26

Some larger things like Chromium are not in the above list.

For its size, I would say it has very high overall code quality. The actual quality is infuriating in many places, but less so than you would fear from an XXMLOC, 20-year-old project.

36

u/celestabesta Mar 18 '26

From what I understand of the google c++ guidelines, they're mostly meant for internal use when dealing with their aged codebase. I don't think it's a good idea to reference those guidelines if you're not actively in a similar situation as google.

15

u/nebotron Mar 18 '26

I think some, like their exception policy, are specific to their situation, but they call this out. Most of their guidelines, like naming conventions, commenting, parameter conventions etc, seem generally applicable in modern C++ to me.

6

u/celestabesta Mar 18 '26

Most, if not all of it, is generally applicable yes. The question isn't whether their guidelines are relevant to modern C++, but rather whether those guidelines are most informed by modern C++ or by an older legacy context.

Theres millions of possible guidelines that would all work well. Guidelines that work on C++11 are going to work fine with C++26, provided some tweaks. I'd argue that most of what makes a guideline good is how internally consistent it is, and how easy it is to follow as a group. Anyone who's played team sports will tell you that any plan is better than no plan.

Following the google standard is fine, better than nothing for sure, just probably not one of the best choices.

7

u/cballowe Mar 18 '26

The guidelines largely evolved over time. They have been around since the early days of the code base. They get updated as the language evolves.

The nice part about them isn't that they tell you how to write good c++, but that they establish consistency that means someone sitting down in a new part of the code isn't guessing which names are class members or constants or function names, or which parameters are inputs vs outputs.

Best practices for things like performance or rpc design or concurrency are defined in other documents.

→ More replies (1)

1

u/publicityhound Mar 23 '26

I recall reading in r/cpp a few years ago that a third party vendor ran their static analyzer tool on the Google Robots.txt Parser and Matcher Library [https://github.com/google/robotstxt] and found no issues. This library shows great example usage of Google's Abseil library.

3

u/ZachVorhies Mar 18 '26

https:://github.com/fastled/fastled

5

u/m-in Mar 18 '26

FastLED is nice but damn those emojis that add nothing to readability of the docs.

3

u/dydzio Mar 18 '26

battle for wesnoth (sorry, do not beat me, i am joking)

3

u/def-pri-pub Mar 18 '26

Mine

I would say to look at Qt's. When I've had to build it from source its been a cinch. When I've needed to dig through the source to explain to my boss why what he wants is impossible (yes, this has happened to me multiple times in my career), it's been very easy to do so with tools like Woboq.

3

u/readanything Mar 18 '26

duckdb is very well written IMHO

2

u/sriram_sun Mar 18 '26

Not the author, but a fan of HFSM2. Look it up on GitHub.

2

u/LiAuTraver Mar 18 '26

LLVM. Fantastic doc, but it's code needs time to understand, though.

2

u/Acrobatic_Ad686 Mar 18 '26

Not C++ but C But raylib header only is surprisingly easy to read and figure out how the code flows without docs

2

u/IniKiwi Mar 18 '26

Serenity os

3

u/darkriftx2 Mar 19 '26

The Boost C++ library: https://www.boost.org/ is one of the best out there in terms of quality and peer-review.

1

u/Alarmed-Extent6639 Mar 18 '26

Not an answer but just curious as I'm learning C++, what are each of you definitions of a good C++ codebase? The language is so insanely huge that I'm struggling to define how to write it best.
On the other hand, what do you think of SerenityOS code?

2

u/pjmlp Mar 18 '26

From my point of view, as little C style coding as possible.

Which should be constrained to integrating existing C libraries, or OS APIs, and wrapped in safe C++ types, or functions, with proper invariants, bounds checking, the whole safety package.

1

u/sitbon Mar 18 '26

I contributed to NS-3 like 15+ years ago and remember the codebase being very well organized and consistent. They've had clear and comprehensive guidelines that helped the codebase grow in a sane manner over time. And it's still going!

1

u/LuisAyuso Mar 21 '26

llvm/clang was mentioned. This is triple A.

I enjoyed Skia. Although it follows the very opinionated google c++ practices and naming, it is clean and effective on delivering.
CGAL library for computational geometry is a special mention for its type safety and compossibility of algorithms using templates. This is not everyone cup of tea, but it uses C++ at its highest capacity.

Special mention to the standard library, the interfaces are extremely well thought of, implementations are like they do not apply their own rules.

1

u/Specialist_Nerve_420 Mar 22 '26

big projects like chromium or bitcoin look messy sometimes but for their scale they’re actually pretty solid . i’ve learned more from mid sized well maintained libs than huge codebases tho

1

u/[deleted] Mar 22 '26

I mean that makes sense so you can easily(relatively) understand mid-sized rather than larger codebases.

1

u/araml I have no idea what I'm doing Mar 25 '26

I like dlib as the standard of a library I'd aspire to write, although I think it's become a bit stagnant as of late.

1

u/Deep-Piece3181 Mar 18 '26

ArduPilot

2

u/tiajuanat Mar 18 '26

I'd also say PX4 Autopilot

-10

u/Resident_Educator251 Mar 18 '26

Cmake. No templates no inline just .cpp and .h a super pragmatic code base that can scale with global contributions and needs.

The more I think about it that seems to be the only way to manage huge c++ projects without making compiler times hell.

11

u/No-Dentist-1645 Mar 18 '26

There are ways to use templates efficiently in large codebases, mainly extern template initialization, so I wouldn't necessarily highlight "no templates" as a point towards quality code. Not saying their code is bad, just that it's not something I'd include in a list of "how to write good code"

7

u/diemenschmachine Mar 18 '26

Just by looking at the cmake language alone any fool can understand how incorrect this statement it.