Summary
“You’ll spend more time reading code than writing it, so optimize for readability over writability.” This principle is often echoed in various books on clean code. It’s supported by the experiences of many software developers, which is why even small details like the number of spaces, newlines, and the order of #import
statements are standardized. This standardization isn’t just for the sake of being meticulous; it’s about saving time. Following the practices in this chapter, you can forget about manually formatting code. It gets automatically formatted when you build, a step you’d do anyway to test the code. With ClangFormat
, you can make sure the formatting is up to the standard of your choosing.
Going beyond simple whitespace adjustments, code should also meet numerous other guidelines. That’s where clang-tidy comes in. It helps enforce coding that your team or organization agreed on. We discussed this static checker...