[PATCH] D49114: Add a clang-tidy check for "magic numbers"

Florin Iucha via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 9 20:05:10 PDT 2018


0x8000-0000 added a comment.

In https://reviews.llvm.org/D49114#1156878, @Quuxplusone wrote:

> The cult of "no magic numbers" is horrible and we should be trying to //deprogram// its adherents, not create a whole new generation of them. I would be happy if this clang-tidy patch were quickly abandoned. //But//, it's just a clang-tidy check — it's easy for people who don't want it to ignore its existence — so I'll just plan to be in that group of people.


There are several problems with magic numbers but the worst one is when you have a few of them sprinkled through the code (4, 5, 24) and you make one change - let's say 4 needs to become a 5. Now: how many other values do you need to change? Do you change the 5 because it is 4 + 1? Do you change 24 because is it 4 * 6? Do the 4s in these sub-expressions relate to the same concept/constant/value or not?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49114





More information about the cfe-commits mailing list