Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

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?

+7
−0

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?

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Out of curiosity, do you know why they chose this character? I'm asking because many languages use `_... (3 comments)
Post
+4
−1

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.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

Regarding culture (3 comments)
Regarding culture
Lundin‭ wrote 6 months ago

It really doesn't matter how average Joe in country x likes to write numbers. What matters is how the average engineer in country x writes them. Good engineers and scientists around the world follow engineering notation and the SI system. Good engineers follow technical standards - which are publications and not just "convention". Otherwise programmers in East Asia would already be writing source code using their local alphabet. But they aren't, they write it in English. Because of technical standards.

Karl Knechtel‭ wrote 6 months ago

I'm inclined to agree with John here. Numeric literals exist in programs for a wide variety of reasons, most of which are not engineering related. East Asian programmers typically don't use "localized" programming languages (these are a novelty at best anyway) but they do comment code in their native tongue all the time. As do programmers from around the world, from what I've seen.

Lundin‭ wrote 6 months ago

Karl Knechtel‭ Sure, there are plenty of bad programmers everywhere. Those who name identifiers in their native language or use their native language in comments are not professional - it will not get accepted in professional organizations nor during code review. The purpose of using coding standards, technical standards and conventions are to suggest how people should be doing things the right way. Not to look at whatever bad/sloppy/crazy practices that are already in use and then document that those practices exist.