Friends Will Be Friends

Friends Will Be Friends
cpp-memes, friend-classes-memes, encapsulation-memes, oop-memes, code-smell-memes | ProgrammerHumor.io

Someone's asking if using friend classes is frowned upon, and the top comment drops the golden rule: "Don't let friends touch your privates."

For context, the friend keyword in C++ lets another class access your private members, which is basically punching a hole through encapsulation. It's like giving someone the keys to your house and saying "please don't go through my underwear drawer." Most devs consider it a code smell because it creates tight coupling and defeats the purpose of access modifiers. If you need a friend class, your design probably needs a refactor.

The double entendre here is *chef's kiss* — both a programming best practice AND life advice wrapped in one sentence.

More Like This