friend grants a function or class direct ACCESS to another class's private/protected members, bypassing the encapsulation boundary the class's public interface would otherwise enforce.
Performance benefit. It lets tightly-coupled, performance-critical code (e.g., operator<<, a matrix-multiplication kernel, a custom iterator's implementation) access the internal representation DIRECTLY rather than through possibly-virtual public accessor calls, avoiding call overhead and unnecessary defensive copying in a hot path.
Why it is detrimental to modularity. It breaks encapsulation and information hiding — the central modular-programming principle (also central to Question 19 and Question 23): a friend can read AND WRITE the class's internal representation directly, so the class's actual invariant-preserving interface silently expands to include every friend function/class scattered anywhere in the codebase, not just its declared public methods. Consequences:
The class's internal representation can no longer be changed safely without also auditing and possibly rewriting every friend — defeating the whole point of information hiding, which is the ability to change an implementation without affecting clients. Friends ARE clients that see the implementation, they just aren't marked as such by the public interface.
friend declarations are typically scattered far from the class's own definition, so determining "who can affect this class's invariants" requires a whole-codebase search rather than reading one class's public interface — exactly the traceability cost Question 19 flags for merged responsibilities.
Maintenance risk grows: a maintainer editing the class's private representation must also understand and update every friend, an easy step to miss, unlike a change kept behind a stable public interface, which by definition cannot break well-behaved clients.
Conclusion.friend is a deliberate, narrow escape hatch traded against modularity for a genuine, measured performance need (canonical legitimate uses: operator-overload pairs, tightly-coupled iterator/container pairs) — it should be used sparingly, only where the performance case is real, never as a routine substitute for a proper public interface.