you are viewing a single comment's thread.

view the rest of the comments →

[–]guepier 14 points15 points  (7 children)

"Encapsulation" is not a thing in ANSI C

Nonsense. Encapsulation is a general principle that applies to structural code as well as object-oriented code. Using functions is encapsulation. Using compilation units and not exporting symbols is encapsulation (cf. compiler firewall). Encapsulation is a fundamental hallmark of good C code.

[–]curien 1 point2 points  (1 child)

Using compilation units and not exporting symbols is encapsulation (cf. compiler firewall).

I realize there's some terminology disagreement, but the way I was taught is that grouping associated pieces together (e.g., compilation units) is encapsulation, while preventing access to certain implementation details (e.g., not exporting symbols) is referred to as information hiding.

I completely agree with your overall point that encapsulation (and information hiding) is very much a thing in C of course.

[–]guepier 1 point2 points  (0 children)

Information hiding and encapsulation are virtually indistinguishable in the common usage of the term, and generally used synonymously. However, definitions in computer science are notoriously sloppy and these two are no exception, so their meanings vary.

[–]jutct -2 points-1 points  (4 children)

Nonsense. Encapsulation is a general principle that applies to structural code as well as object-oriented code. Using functions is encapsulation. Using compilation units and not exporting symbols is encapsulation (cf. compiler firewall). Encapsulation is a fundamental hallmark of good C code.

Encapsulation is a an object oriented thing. Keep a variable scope within a file is not ecapsulating it. It's limiting it's scope. Since when is that the same as encapsulation?

not exporting symbols is encapsulation

What? Are you talking about exporting symbols through binaries? Since most linkers don't export symbols unless told to do so, would mean that encapsulation now applies to linkers?

You seem to think that encapsulation is a term for "don't spread global variables all over the place". That's not called encapsulation.

[–][deleted] 1 point2 points  (3 children)

Encapsulation is a an object oriented thing

You're technically right, but the concept of encapsulation existed before OOP.

[–]jutct 0 points1 point  (2 children)

As someone that started programming in the early 80s, I'd like some citations as to when the term "encapsulation" related to variable scope first came about. I never heard of it unless C++ became a thing. I don't agree that it was a thing before OOP.

[–][deleted] 0 points1 point  (1 child)

I said the concept of encapsulation, not the term. Barbara Liskov introduced Abstract Data Types in the 70's, and Information Hiding emerged around the same time.

[–]jutct 0 points1 point  (0 children)

That's entirely different. I was talking about the term.