Enforcing the Formatting
Let's learn about how to enforce the formatting in CMake.
We'll cover the following...
Professional developers generally follow rules. They say that senior developers know when to break one (as they can justify the need to). On the other hand, it is said that very senior developers don't break rules because it's a waste of time having to keep explaining their reasons to others. We say, pick your battles and focus on things that actually matter and have a tangible impact on the product.
Coding style and formatting
When it comes to coding style and formatting, programmers are presented with a myriad of choices: should we use tabs or spaces for indentation? If spaces, how many? What is the limit of characters in a column? How about in a file? Such choices don’t impact the behavior of the program in most cases, but they do generate a lot of noise and start lengthy discussions that don’t bring much value to a product.
Some practices are commonly agreed upon, but most of the time, we're debating personal preference and anecdotal evidence. After all, enforcing 80 characters in a column over 120 is an arbitrary choice. It doesn't really matter what we're going to choose as long as we're consistent. Inconsistency in style is bad, as it affects an important aspect of the software: the readability of the code.
Formatting tools
The best way to avoid it is to use a formatting tool such as clang-format
. This can alert us that the code isn't formatted properly and even fix things that stand out if we let it. Here's an example of a command ...
clang-format -i --style=LLVM filename1.cpp filename2.cpp