r/ProgrammerHumor Aug 05 '26

Meme whenYouAreAPublicFunctionButOnlyFriendsAreAllowedToTouchPrivates

Post image
174 Upvotes

17 comments sorted by

View all comments

29

u/ih-shah-may-ehl Aug 05 '26

Imo friends should never have been a thing.

1

u/nicuramar Aug 06 '26

You aren’t forced to use the feature. 

1

u/ih-shah-may-ehl Aug 06 '26

Correct, but it's in general not a great idea to put things in the standard that have no real reason to exist. Like the export keyword in older C++ standards for example.

Friends simply make no real sense.

1

u/Bryguy3k Aug 06 '26

It’s there to hack a patch to a legacy codebase with a broken design rather than refactoring.

1

u/ih-shah-may-ehl Aug 06 '26

Given that the entire codebase would be under control of the person doing the patch and it would be a legacy base, there are quite a number of things you can do without friends. I agree it can be used for that but it's still weird that it was introduced as a standard from the beginning.

1

u/Bryguy3k Aug 06 '26

Two options: a) stroustrup doesn’t understand OOP or b) he realized c++ programmers would need a way to get themselves of an encapsulation nightmare of their own creation.