-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
decimal_literal_representation is subjective #2421
Comments
@vorner it's configurable (e.g. I agree that 4096 is something I'll trivially recognize. 8192, too, but from there on I don't recognize them anymore. |
My point isn't about the limit, but about the lint itself. Whether I write a number in hexa or decimal is based on context, not on the value of the number. If I care about the bit/byte patterns, I use hexa, because it preserves positions ‒ for example, when writing an RGB color, typing 0x0000FF is more readable blue, opposed to 255. But that's a rather small number. On the other side, when talking about sizes, 1_073_741_824 is much more readable gigabyte for me (well, I'm not sure it's exactly one gigabyte ‒ but counting the triplets of digits gives a lot of insight) than 0x40_000_000, since in the later case I know it is binary-round number, but I don't have a clue about how large it actually is in some human-accessible units until I take a calculator and let it translate it for me. |
I wrote this lint and also thought about the context problem. Therefore the limit exists. For big numbers like If you have a constant like So what should we do:
|
Hello
The lint about decimal literal being better written as hexadecimal feels very subjective. For me, if I see 4096, I know at once it's 4 kilobytes. If I see 0x1000, I have to really think how approximately large the number is. Sure, the second conveys the fact it is power of two more strongly, but the actual size of the number is better expressed in decimal, at least to me ‒ so I think it very much depends on the context, what is more important.
I find most of clippie's lints reasonable and based on some sane argument ‒ eg. performance, better suited method, etc. This one kind of seems to be out of line with that.
The text was updated successfully, but these errors were encountered: