News for hackers. Stuff that matters.
Re:Public/protected/private is an unnecessary feature by ctxc on Thursday June 19, 2025 @02:09PM (#44321055)
Do you really want to create an interface for every possible place where you'd use `private` though?
Re:Public/protected/private is an unnecessary feature by WorldMaker on Thursday June 19, 2025 @02:20PM (#44321156)
Right, even if it is just syntactic sugar for a "pure" dual of `interface` as the article posits, syntactic sugar still has advantages/merit in many scenarios.
Re:Public/protected/private is an unnecessary feature by ctxc on Thursday June 19, 2025 @02:31PM (#44321246)
Exactly. Ime most classes are not designed to be inherited but want to expose a clean public API.

While true that all classes can be inherited, treating _all_ classes with the assumption that they will be would just lead to a labyrinth of code.

Re:Public/protected/private is an unnecessary feature by coderjames on Thursday June 19, 2025 @04:10PM (#44322112)
> most classes are not designed to be inherited but want to expose a clean public API.

> While true that all classes can be inherited

That's what the 'final' keyword in C++ is for: https://en.cppreference.com/w/cpp/language/final.html

"Specifies that a virtual function cannot be overridden in a derived class, or that a class cannot be derived from."

Re:Public/protected/private is an unnecessary feature by WorldMaker on Thursday June 19, 2025 @04:18PM (#44322182)
C# and Java both have `sealed` for that, too.
Re:Public/protected/private is an unnecessary feature by throwaway2037 on Friday June 20, 2025 @01:03AM (#44324882)
Nitpick: It is called "final" in Java, but your point stands. As I understand, C++ borrowed their "final" keyword from Java/C#. I'm not trolling when I write that last sentence. That is something that has really changed about C+ since the C++-11 committee was started -- and continues. When people write language / library proposals, they now regularly survey the landscape and talk about their experiences with other languages / libraries.
Re:Public/protected/private is an unnecessary feature by WorldMaker on Friday June 20, 2025 @10:27PM (#44334006)
Technically Java has both `final` and `sealed`, and the distinction between the two is complicated, but `sealed` is the more powerful/capable/adjustable of the two. But the rest of your point stands and it does seem useful that C++ is paying more attention to the large ecosystems of its descendant languages and other relatives.
Re:Public/protected/private is an unnecessary feature by throwaway2037 on Sunday June 22, 2025 @04:34AM (#44345117)
Holy shit: I stand corrected about sealed keyword in Java! It was added in Java 17. <Hat tip>
Re:Public/protected/private is an unnecessary feature by orwin on Friday June 20, 2025 @03:46AM (#44325548)
Ideally, yes in my opinion. In the real world, I don't have time to design my code that well.