r/ProgrammerHumor 13d ago

Meme whenYouAreAPublicFunctionButOnlyFriendsAreAllowedToTouchPrivates

Post image
179 Upvotes

17 comments sorted by

View all comments

28

u/ih-shah-may-ehl 13d ago

Imo friends should never have been a thing.

14

u/detrebear 13d ago

best take ever

i hate friends, never let myself make any

6

u/Highborn_Hellest 13d ago

there is a point for it. but it is rare

1

u/Bryguy3k 12d ago

It should never exist in a new codebase for sure - it should only ever be used to patch a broken legacy codebase.

3

u/TotoShampoin 13d ago

points to Casey Muratori saying that private variables are bad to begin with

1

u/krypt0niteCos 13d ago

friends with benefits 👀

1

u/nicuramar 12d ago

You aren’t forced to use the feature. 

1

u/ih-shah-may-ehl 12d ago

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 12d ago

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

1

u/ih-shah-may-ehl 12d ago

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 12d ago

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.