The problem with C++ is that all of your friends can see your private parts.

That's not a problem, it's a feature!

  • 9
    But at least it has class.
  • 3
    Ahhhhhh! I get the reference ...
  • 2
    No no no no no no no, stop it! friends are essentially a bad idea in programming!
    I'm not saying that whole idea is 100% bad but missuses are too much common. Breaking encapsulation is not always well motivated (most often by lazyness).
    In my opinion if you use friends you are bad designer.
  • 0
    @MaLiN2223 I think I've used friends once only, in 26 years. It was something to do with overloaded operators, IIRC. It's just a weird feature.

    C#'s extension methods is a parallel case. It was introduced to make LINQ possible, but some people misuse it like crack, and create obfuscation for no good reason.
  • 1
    @Grumpy exactly.
    Extensions methos are also good for extending string class however they forbid to use private parts of classes (if i remember correctly) hence no encapsulations are broken unlike when using friends.
  • 0
    @MaLiN2223 friends are there to *avoid* breaking encapsulatiin by adding more public api
  • 0
    @elazar it is called 'work around' and if you see that you need something you should change the project. Code smells more and more with behavior you described.
  • 0
    Privacy is just an illusion !

    #define private public
  • 0
    @MaLiN2223 Sometimes, but not necessarily. It is fine-grained permissions, like "protected". It should be questioned wherever it appears, but there are good answers.
Add Comment