Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread via Digitalmars-d-learn
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

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread thebluepandabear via Digitalmars-d-learn
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 --

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread via Digitalmars-d-learn
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

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread via Digitalmars-d-learn
On Saturday, 19 November 2022 at 19:54:59 UTC, Ali Çehreli wrote: On 11/19/22 01:05, [] () {} () wrote: > All this because some programmer wanted to save a few key strokes, or > did not anticipate change, or did not anticipate the need to ensure data > is valid before assigning it, or returning

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread via Digitalmars-d-learn
On Saturday, 19 November 2022 at 19:59:20 UTC, Ali Çehreli wrote: .. ... Ali The 10 years was mentioned, because it was what I learnt over that period (well, long before that actually). It wasn't mentioned to demonstrate that I have some superior knowledge. Object data needs to be

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread via Digitalmars-d-learn
On Saturday, 19 November 2022 at 19:59:20 UTC, Ali Çehreli wrote: On 11/19/22 01:43, [] () {} () wrote: > do it your way for the next 10 years, and > I bet you will eventually come to a different point of view ;-) Hm... I am responding without reading the rest of the thread so I don't know

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread Sergey via Digitalmars-d-learn
On Saturday, 19 November 2022 at 04:27:14 UTC, []() {}() wrote: By making your class member variables public, it is not clear whether you forgot that you needed to validate incoming and outgoing values, or whether you don't need to do this (not ever). If you did it because of the former,

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread Ali Çehreli via Digitalmars-d-learn
On 11/19/22 01:43, [] () {} () wrote: > do it your way for the next 10 years, and > I bet you will eventually come to a different point of view ;-) Hm... I am responding without reading the rest of the thread so I don't know whether you've mentioned the 10 years more but here it goes: I hope

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread Ali Çehreli via Digitalmars-d-learn
On 11/19/22 01:05, [] () {} () wrote: > All this because some programmer wanted to save a few key strokes, or > did not anticipate change, or did not anticipate the need to ensure data > is valid before assigning it, or returning it. > > So no. It's not overkill. It's called software

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread Ali Çehreli via Digitalmars-d-learn
On 11/18/22 20:13, [] () {} () wrote: > after 10 years of doing all that, you may well come to the conclusion > that public member variables are not such a great idea afterall ;-) It depends. Majority of my structs are pure data. When there is no invariant to protect, then there is no reason

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread Ali Çehreli via Digitalmars-d-learn
On 11/18/22 19:35, [] () {} () wrote: > I like to see an example, of a 'class type' with 'public' member > variables, somehow magically converted into both getter and setter using > UFCS, without breaking client code. UFCS was mentioned before in the same context but I think what is meant was

Re: "Little Scheme" and PL Design (Code Critique?)

2022-11-19 Thread Jack Pope via Digitalmars-d-learn
On Thursday, 17 November 2022 at 22:05:45 UTC, jwatson-CO-edu wrote: [`Atom`](https://github.com/jwatson-CO-edu/SPARROW/blob/main/lil_schemer.d#L66) (unit of data), I throw it on the heap and never bother to delete it. I understand that D does GC for me. I am interested in using either [timed

Re: pointer escaping return scope bug?

2022-11-19 Thread Dukc via Digitalmars-d-learn
On Saturday, 19 November 2022 at 15:02:54 UTC, Nick Treleaven wrote: On Saturday, 19 November 2022 at 14:52:23 UTC, ag0aep6g wrote: That's essentially just a function that returns its pointer parameter. So the program boils down to this: ```D @safe: int* fp(return scope int* p) { return p; }

Re: pointer escaping return scope bug?

2022-11-19 Thread ag0aep6g via Digitalmars-d-learn
On Saturday, 19 November 2022 at 15:02:54 UTC, Nick Treleaven wrote: OK, so how do I make `lf` implicitly scope? By explicit/implicit I just meant this: scope explicit = new int; int x; auto implicit = That's probably not helping with whatever you want to accomplish.

Re: pointer escaping return scope bug?

2022-11-19 Thread Nick Treleaven via Digitalmars-d-learn
On Saturday, 19 November 2022 at 14:52:23 UTC, ag0aep6g wrote: That's essentially just a function that returns its pointer parameter. So the program boils down to this: @safe: int* fp(return scope int* p) { return p; } void main() { int* p; { auto lf = new int; p =

Re: pointer escaping return scope bug?

2022-11-19 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 19 November 2022 at 14:07:59 UTC, Nick Treleaven wrote: Hi, The following seems like a bug to me (reduced code, FILE* changed to int*): ```d @safe: struct LockedFile { private int* fps; auto fp() return scope => fps; } void main() { int* p; { auto lf =

Re: pointer escaping return scope bug?

2022-11-19 Thread ag0aep6g via Digitalmars-d-learn
On 19.11.22 15:07, Nick Treleaven wrote: Hi, The following seems like a bug to me (reduced code, FILE* changed to int*): ```d @safe: struct LockedFile {     private int* fps;     auto fp() return scope => fps; } void main() {     int* p;     {     auto lf = LockedFile(new int);  

pointer escaping return scope bug?

2022-11-19 Thread Nick Treleaven via Digitalmars-d-learn
Hi, The following seems like a bug to me (reduced code, FILE* changed to int*): ```d @safe: struct LockedFile { private int* fps; auto fp() return scope => fps; } void main() { int* p; { auto lf = LockedFile(new int); p = lf.fp; } assert(p != null); //

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread Andrey Zherikov via Digitalmars-d-learn
On Saturday, 19 November 2022 at 10:17:19 UTC, []() {}() wrote: On Saturday, 19 November 2022 at 09:51:09 UTC, []() {}() wrote: ... no. in C# it breaks ABI. that is why its not acceptable in my team. of course that's not the reason we don't use public member variables in classes. the

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread Andrey Zherikov via Digitalmars-d-learn
On Saturday, 19 November 2022 at 09:49:18 UTC, thebluepandabear wrote: I am too dumb to know what ABI is https://en.wikipedia.org/wiki/Application_binary_interface

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread Dukc via Digitalmars-d-learn
On Saturday, 19 November 2022 at 09:49:18 UTC, thebluepandabear wrote: On Saturday, 19 November 2022 at 09:26:49 UTC, Andrey Zherikov wrote: On Saturday, 19 November 2022 at 09:12:26 UTC, thebluepandabear wrote: That's the point many people have given here which is not convincing him, even

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread Dukc via Digitalmars-d-learn
On Saturday, 19 November 2022 at 09:26:49 UTC, Andrey Zherikov wrote: On Saturday, 19 November 2022 at 09:12:26 UTC, thebluepandabear wrote: That's the point many people have given here which is not convincing him, even though it is quite great. I think we all know the answer here  IMHO

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread Dukc via Digitalmars-d-learn
On Saturday, 19 November 2022 at 03:52:41 UTC, thebluepandabear wrote: Say you want to write 'SET' now whenever someone sets a width/height value for the rect (as an example), and 'GET' when someone gets the width/height value for the rect, what you could do is do this: ``` class Rect2D {

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread via Digitalmars-d-learn
On Saturday, 19 November 2022 at 09:51:09 UTC, []() {}() wrote: ... no. in C# it breaks ABI. that is why its not acceptable in my team. of course that's not the reason we don't use public member variables in classes. the reason we don't use them, is because (1) we always anticpiate

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread Andrey Zherikov via Digitalmars-d-learn
On Saturday, 19 November 2022 at 09:51:09 UTC, []() {}() wrote: no. in C# it breaks ABI. that is why its not acceptable in my team. Every company works differently. Yours are using .net and (I guess) ships dlls so you must care about ABI with existing software. In my company we use static

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread via Digitalmars-d-learn
On Saturday, 19 November 2022 at 09:26:49 UTC, Andrey Zherikov wrote: On Saturday, 19 November 2022 at 09:12:26 UTC, thebluepandabear wrote: That's the point many people have given here which is not convincing him, even though it is quite great. I think we all know the answer here  IMHO

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread thebluepandabear via Digitalmars-d-learn
On Saturday, 19 November 2022 at 09:26:49 UTC, Andrey Zherikov wrote: On Saturday, 19 November 2022 at 09:12:26 UTC, thebluepandabear wrote: That's the point many people have given here which is not convincing him, even though it is quite great. I think we all know the answer here  IMHO

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread Andrey Zherikov via Digitalmars-d-learn
On Saturday, 19 November 2022 at 09:12:26 UTC, thebluepandabear wrote: That's the point many people have given here which is not convincing him, even though it is quite great. I think we all know the answer here  IMHO you are both right :) You are speaking about API compatibility, `[]()

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread Andrey Zherikov via Digitalmars-d-learn
On Saturday, 19 November 2022 at 09:12:26 UTC, thebluepandabear wrote: That's the point many people have given here which is not convincing him, even though it is quite great. I think we all know the answer here  IMHO you are both right :) You are speaking about API compatibility, `[]()

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread Andrey Zherikov via Digitalmars-d-learn
On Saturday, 19 November 2022 at 09:05:42 UTC, []() {}() wrote: Once you refactor your class (creating actual private member variables and creating getter/setter methods, you are almost certainly going to break binary compatability, and when you send your update compiler library to your

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread thebluepandabear via Digitalmars-d-learn
That's the point many people have given here which is not convincing him, even though it is quite great. I think we all know the answer here 

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread via Digitalmars-d-learn
On Saturday, 19 November 2022 at 04:47:57 UTC, thebluepandabear wrote: .. Of course in C# this argument wouldn't exist because you could just do `{ get; set; }`, and I really wish D had something similar  If D had C#'s 'automatic' property syntax, it would as meaningless in D as it is in

Re: Is defining get/set methods for every field overkill?

2022-11-19 Thread Andrey Zherikov via Digitalmars-d-learn
On Saturday, 19 November 2022 at 04:13:33 UTC, []() {}() wrote: oh. so i get it now. you have to refactor your class (change member variable names and also do it in all places where they are used througout the class. then add new methods, overloading them in this way and that way, all because