I've been reading a lot of C++ code in the Swift and LLVM codebases recently. Some of the class declarations span thousands of lines of source code, with many nested class declarations. There are also multiple sections marked protected:
-- in other words, not all protected methods can be found in a single place. Example: swift::Decl
, which is ~700 LoC.
Experienced C++ coders:
- Is this a good way to organize C++ code? Or would it be more ideal if these declarations were broken down more? Why?
- Is there an easy way to determine, for example, whether
swift::Decl
is an abstract class? With 600 LoC and several layers of nesting, it's easy for me to get lost when scrolling through the code in Vim. Is this why people use IDEs?
In large-scale C++ projects, the physical design of a system is very important in order to reduce compile and link time. By physical design I mean for example which class definitions are part of a component, how dependencies are managed, how to include header files, things not appropriate for header files, etc. There's a good book named "Large-Scale C++ Software Design", by John Lakos, which explains about some of those design decisions. I think the Swift/LLVM teams have followed many of the rules from that book, and in some cases they prefer to have bigger files or classes, but better compile/link performance. I don't know about the particular case of
swift::Decl
though.If you use a plain text editor, you need some kind of code navigation tool, preferably based on Clang. For example, I use Rtags for Emacs (I think there's support for Vim, too). As this tool is based on Clang, the symbols are tagged appropriately with type, visibility, references, usages, etc. so that code navigation is easier.