November 19, 2022

On Saturday, 19 November 2022 at 22:57:36 UTC, [] () {} () wrote:

>

On Thursday, 17 November 2022 at 04:39:35 UTC, thebluepandabear wrote:

>

...
I am debating whether or not I should add getter methods to these properties. On one hand, it will inflate the codebase by a lot, on the other hand -- in other languages like Java it is a good practice:

You really should, instead, be debating why your class has public member variables.

If you come to the conclusion that those member variables are completely ok being public, then making them private and thus needing to provide a simple getter/setter for getting/setting the raw value, well, that is just equivalent to making them public anyway, really.

So have you achieved nothing with that refactoring?

Well, only time (and 100's of users) will tell ;-)

Do I really need a fence around my house... well.. only time will tell.

I'm inclined to build the fence anyway.

Though it would be great if didn't need fences.

Ok... thank you.

November 20, 2022

On Saturday, 19 November 2022 at 23:05:30 UTC, thebluepandabear wrote:

>

..

btw. Although this thread has well and truly exhausted it usefulness, the question you posed primarly relates to encapsulation, and as such, I think Scott Myers provided a reasonable answer to your question - more than 2 decades ago:

"Encapsulation is a means, not an end. There's nothing inherently desirable about encapsulation. Encapsulation is useful only because it yields other things in our software that we care about. In particular, it yields flexibility and robustness."

https://www.drdobbs.com/cpp/how-non-member-functions-improve-encapsuhttps://www.drdobbs.com/cpp/how-non-member-functions-improve-encapsu/184401197

November 20, 2022
On Saturday, 19 November 2022 at 19:40:43 UTC, Ali Çehreli wrote:
> ..
> (I fully agree with the posted video.)
> ...


Quoted from that video (the one that you agree with):

"I don't ever think that private .. private is like just .. shouldn't even be used."

"so I don't even use classes I just use struct so that everything is always public .. and that in my opinion is the correct method."

Now, after thoroughly examining that rant, I better understand his agenda.

It's hard for me to conceive how a someone who thinks of themself as a 'software engineer' could agree with this.

anyho.. If anyone wants to learn more about why encapsulated types (classes) have shown to be so useful in my many years of programming, they can first pay me my fee.
November 20, 2022
On 11/20/22 00:31, [] () {} () wrote:

> Quoted from that video (the one that you agree with):
>
> "I don't ever think that private .. private is like just .. shouldn't
> even be used."
>
> "so I don't even use classes I just use struct so that everything is
> always public .. and that in my opinion is the correct method."

Yes, still agreeing with it.

> If anyone wants to learn more about why encapsulated types
> (classes) have shown to be so useful in my many years of programming,

Hm. 'private' is about access control. Encapsulation is something else.

> they can first pay me my fee.

If I could, I would like to pay to have less of that please. :)

Ali

November 20, 2022
On Sunday, 20 November 2022 at 12:23:39 UTC, Ali Çehreli wrote:
> On 11/20/22 00:31, [] () {} () wrote:
>
> > Quoted from that video (the one that you agree with):
> >
> > "I don't ever think that private .. private is like just ..
> shouldn't
> > even be used."
> >
> > "so I don't even use classes I just use struct so that
> everything is
> > always public .. and that in my opinion is the correct
> method."
>
> Yes, still agreeing with it.
>
> > If anyone wants to learn more about why encapsulated types
> > (classes) have shown to be so useful in my many years of
> programming,
>
> Hm. 'private' is about access control. Encapsulation is something else.
>
> > they can first pay me my fee.
>
> If I could, I would like to pay to have less of that please. :)
>
> Ali

so, as I understand it, your're against the use of private, against the use of class, and against the use of encapsulation.

we have nothing more to discuss..

.. good luck with your career as a software engineer (but please, for all our sakes, don't work on any safety-related systems, and especially not the ones running in my car).




November 20, 2022
On Sunday, 20 November 2022 at 12:23:39 UTC, Ali Çehreli wrote:
> On 11/20/22 00:31, [] () {} () wrote:
> > If anyone wants to learn more about why encapsulated types
> > (classes) have shown to be so useful in my many years of
> programming,
>
> Hm. 'private' is about access control. Encapsulation is something else.

BTW, many software developers and also wikipedia actually agree with [] () {} (): https://en.wikipedia.org/wiki/Encapsulation_(computer_programming)

And this all is getting really silly. The proof is in the pudding. I mean the existence of really large successful software is the best evidence of the programming language or coding technique superiority. C++ has plenty of large successful object oriented software written using it (Mozilla, Chromium, LibreOffice, Qt, LLVM, ...). People had a lot of time to try various C++ features and everyone has their own opinion. Multiple inheritance isn't very popular, but having private class members and the ability to easily hide class implementation details is generally seen as a good and useful feature.

D makes a rather arbitrary change to encapsulation and claims that this is an improvement. But you can't easily convince everyone by just making such claims. How it really works in practice is the only thing that matters.
November 20, 2022
On Sunday, 20 November 2022 at 23:04:18 UTC, Siarhei Siamashka wrote:
>
> ..
> BTW, many software developers and also wikipedia actually agree with [] () {} (): https://en.wikipedia.org/wiki/Encapsulation_(computer_programming)
>

and.. Autostar C++, Misra C++, Cert C++ ... I could go on and on.

but as you rightly point out, the proof is in the pudding.

some of us actually enjoy going to work each day and creating great software for our customers...and having to type a getter/setter doesn't bother us one little bit ;-)

the alternative is just make everything public, and watch our customer systems fail terribly, with all kinds of awful consequences...

.. not to mention, I'd be out of job if I stopped writing getters/setters ;-)

November 20, 2022
On Sunday, 20 November 2022 at 12:23:39 UTC, Ali Çehreli wrote:
>
> Hm. 'private' is about access control. Encapsulation is something else.
>
> Ali

"Clearly, encapsulation is not enough."

https://www.infoworld.com/article/2075271/encapsulation-is-not-information-hiding.html

November 21, 2022
> .. not to mention, I'd be out of job if I stopped writing getters/setters ;-)

I value your input in this discussion, you have brought some good points.

Out of interest, what type of industry-level software are you creating with D? I don't know much companies using D commercially.
November 21, 2022
On Monday, 21 November 2022 at 00:29:12 UTC, thebluepandabear wrote:
>> .. not to mention, I'd be out of job if I stopped writing getters/setters ;-)
>
> I value your input in this discussion, you have brought some good points.
>
> Out of interest, what type of industry-level software are you creating with D? I don't know much companies using D commercially.

I think I may actually have been convinced that writing getters/setters is good practice, I think it's better be safe than sorry because I am writing a library it may be important not to break ABI compatibility in the future if needed, plus I will not need to change the field name if I ever want to add getters/setters.