News for hackers. Stuff that matters.
Re:There’s No Such Thing as Clean Code by karatinversion on Friday January 28, 2022 @04:40AM (#30112581)
> Hide internal structure (that "private" is the default in C++, Java and Rust just adds to boilerplate; the default case is that you want everything public (unless you like writing trivial getters and setters just for the fun of it); legitimate uses of "private" exist, but are rare)

This is such a strange POV to me. There are cases where your classes are just data records, but any object with logic surely wants to restrict access to its state so it can maintain invariants? E.g. the simplest classes I can think of, like a vector that consists of a pointer to a buffer, a length and a capacity, wouldn't want to provide a setter for the buffer, or allow callers to set it to a random value?

Re:There’s No Such Thing as Clean Code by lifeisstillgood on Friday January 28, 2022 @05:39AM (#30112970)
This is where Python's "consenting adults" idea comes in. Why the hell should someone change a vector "mid-flight" - that is a huge code smell and should be dealt with in the review / design / discussion / pub.

But there are reasons and rationales to "lockdown" the code (beyond not trusting fellow devs!) and at that point I suggest that any mutable state language cannot be properly locked down - so use a functional language where its easier to reason about.

Usually (IMO) private classes etc are just trying to make it easier to reason about state changes - when its probably best to dump the whole mess.

Re:There’s No Such Thing as Clean Code by hogrider on Saturday January 29, 2022 @06:43AM (#30125584)
In most situations, no you can not trust fellow devs to do the right thing and if you push for those reviews then you're the asshole and lose the office politics game. So yeah, I'd rather guardrail people into good behavior.
Re:There’s No Such Thing as Clean Code by lifeisstillgood on Sunday January 30, 2022 @05:14AM (#30135566)
Can I clarify? You get a review that just looks wrong and you become the asshole? What kind of reviews are these ?
Re:There’s No Such Thing as Clean Code by lifeisstillgood on Sunday January 30, 2022 @12:30PM (#30139094)
please ignore the above. I am sure reviews can become political arenas
Re:There’s No Such Thing as Clean Code by yakubin on Friday January 28, 2022 @05:06AM (#30112738)
IME I write about 10-20 as many data records as "classes". I do use "private" from time to time to protect invariants. But if the default was switched to public, my code on balance would be a lot shorter and readable. I'm not saying that "private" shouldn't exist. I'm saying it's a poor default.
Re:There’s No Such Thing as Clean Code by tubs on Friday January 28, 2022 @05:16AM (#30112808)
In c++ you choose the default so I'm not sure it should be lumped in with the others.
Re:There’s No Such Thing as Clean Code by rightbyte on Friday January 28, 2022 @05:31AM (#30112907)
In the literal sense private is default though. I wonder why. Lexical sorting of private, protected and public?

It makes almost no sense to have all private class fields and methods. The only thing I can think of is fat handles with friend classes or functions.

Re:There’s No Such Thing as Clean Code by andi999 on Friday January 28, 2022 @05:56AM (#30113084)
In c++ a class declared with the keyword 'class' is private by default, and a class declared with the keyword 'struct' is public by default. So if you want public by default just write 'struct' (somehow this is not commonly known).

https://en.wikipedia.org/wiki/C%2B%2B_classes

Re:There’s No Such Thing as Clean Code by klodolph on Friday January 28, 2022 @06:35AM (#30113391)
I think the “somehow” is not too hard to guess… it is easy to think that “class” is the only way to declare a class, especially since “struct” is taken from C. I’m sure very few intro C++ explanations ever mention “struct” as a way to declare a class.
Re:There’s No Such Thing as Clean Code by TillE on Friday January 28, 2022 @04:12PM (#30120424)
There's quite a lot about C++ which wouldn't be covered in a simple tutorial, but the meaning of class/struct is a pretty basic part of the language, hardly obscure.

Maybe it's something you could miss if you're coming from a strong C background and still thinking of C++ as C-with-classes, but otherwise it's something any serious user of the language would pick up.

Re:There’s No Such Thing as Clean Code by klodolph on Saturday January 29, 2022 @01:06AM (#30124161)
This comment represents some of the worst elitism I see in the programming community.
Re:There’s No Such Thing as Clean Code by andi999 on Friday January 28, 2022 @07:35AM (#30113801)
Yes, I meant common introductory material should mention (and use) it (I think Bjarne does mention it, but I wouldnt call it introductory material)
Re:There’s No Such Thing as Clean Code by tubs on Friday January 28, 2022 @05:57AM (#30113094)
struct over class then.
Re:There’s No Such Thing as Clean Code by tjajab on Friday January 28, 2022 @04:53AM (#30112648)
I guess that for a lot of people it is the case where you have a class with mutable state that is the anomaly.
Re:There’s No Such Thing as Clean Code by barrkel on Friday January 28, 2022 @06:56AM (#30113550)
It's nuts. It's deeply naive and utterly unworkable.