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.

Post History

66%
+2 −0
Q&A Why is private encapsulation "good" in (C) programming?

Mistakes Human programmers make mistakes. The more the compiler can disallow actions that are unambiguously mistakes, the better. Strong type checking and encapsulation are probably the two most...

posted 19h ago by Olin Lathrop‭

Answer
#1: Initial revision by user avatar Olin Lathrop‭ · 2026-09-17T14:05:06Z (about 19 hours ago)
<h2>Mistakes</h2>

Human programmers make mistakes.  The more the compiler can disallow actions that are unambiguously mistakes, the better.  Strong type checking and encapsulation are probably the two most common means a compiler can "wall off" the human programmer from things they shouldn't be allowed to do.

In your ring buffer (FIFO) example, an application that uses the FIFO should only be allowed to put and get data into and out of the FIFO.  There is no need to an application to alter internal FIFO state.  Any attempt to do so would be a mistake.  Not making that state available to the application eliminates the possibility of such a mistake.

<h2>Levels of abstraction</h2>

Another somewhat orthogonal argument is that each level of the software should only know and care about what is appropriate for that level.  The application should not care how a FIFO is implemented, only be able to access it via a well-defined set of actions that are appropriate for applications to perform.

This concept allows for easier maintenance and ongoing modification of the code.  If a better way of implementing a FIFO comes along, the FIFO routines can be re-written in isolation as long as the interface to the application remains the same.  Therefore, the smaller and more limited that interface is, the more likely a new FIFO architecture can be implemented transparently to the rest of the software.

Note that some modifications of underlying functions, like FIFOs, might not be because something better comes along.  The modification might be to keep more statistics, to aid in debugging or trapping specific conditions, etc.

Another way to look this is that the application interface is a promise of what will always be kept constant.  Once you make a public promise, you have to assume someone somewhere out there is relying on it.  The less you promise, the more you retain future flexibility to change things underneath the publicly-visible interface.  Therefore promise only what the application actually needs.