Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Comments on Where to place digit separators in C23?
Parent
Where to place digit separators in C23?
C23 introduces the digit separator '
which can be placed anywhere inside an integer constant for the purpose of clarity and self-documenting code. These are otherwise ignored by the compiler when determining the value of the number.
However, the language standard provides no guidance regarding how to sensibly use digit separators. These were introduced to C with proposal N2626 which in turn provides no guidance either - for example it suggests that 2'3434'5323
might be clearer to read than 234345323
, which I as a frequent user of engineering notation don't quite agree with. I believe the same feature was introduced in C++14 but with no guidance there either.
Are we to add '
at a whim or will are there any recommended practices to follow?
Post
This probably makes for a thoroughly unsatisfying answer, but there's probably far stronger cultural pressure than technical pressure. In European-derived cultures, we mostly group numbers by powers of one thousand as you suggest, and anybody doing something else should either have an extremely good reason ("it actually represents a series of decimal values, but we store them together, because we learned programming in 1967") or would get laughed out of any code review.
However, people in East Asian cultures group digits as factors of ten thousand in speech, even though they'll (usually) write it following European conventions. And India generally does pairwise separation, except for the final three digits. I assume that other approaches exist, but those get commonly cited.
So, while in power-of-two bases, it's probably safe to assume that some natural word-multiple boundary (eight in binary, three in octal, and four in hexadecimal seems consistent in what I've seen over the years, but as another answer points out, architecture may easily figure in, here) could and should become a strongly-encouraged convention, we'd want to take care that a convention for decimal representation doesn't ask billions of people to write code that's less readable for them.
1 comment thread