Skip to content

Instantly share code, notes, and snippets.

@modocache
Created January 19, 2017 16:34
Show Gist options
  • Save modocache/abac532468cdcfad2eb7d960591265e0 to your computer and use it in GitHub Desktop.
Save modocache/abac532468cdcfad2eb7d960591265e0 to your computer and use it in GitHub Desktop.

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:

  1. Is this a good way to organize C++ code? Or would it be more ideal if these declarations were broken down more? Why?
  2. 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?
@danielmartin
Copy link

  1. 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.

  2. 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.

@modocache
Copy link
Author

Awesome, thank you! I'll definitely read that book.

I had been using YouCompleteMe for Vim, but I didn't find it that useful. Sounds like I should give it another try. Thanks! 🙇‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment