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

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
On Saturday, 19 November 2022 at 05:42:03 UTC, []() {}() wrote: those public Get/Set members functions are exactly what you get in C#, except the compiler does it for you, behind the scenes, saving you the keystokes.. but the end code is just as if you had typed them out yourself. I know...

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

2022-11-18 Thread via Digitalmars-d-learn
On Saturday, 19 November 2022 at 04:47:57 UTC, thebluepandabear wrote: https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/ms229042(v=vs.100) Thanks, I'll think about it more -- I am a noob so I may be wrong in what I am saying. Of course in C# this argument wouldn't

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

2022-11-18 Thread via Digitalmars-d-learn
On Saturday, 19 November 2022 at 03:52:41 UTC, thebluepandabear wrote: ... . Honestly, it may not be a magic bullet, but still useful. This refactoring may be source compatible, but would it be binary compatible? i.e. you refactor your class, compile it as an updated version of your lib

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

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/ms229042(v=vs.100) Thanks, I'll think about it more -- I am a noob so I may be wrong in what I am saying. Of course in C# this argument wouldn't exist because you could just do `{ get; set; }`, and I really wish D ha

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

2022-11-18 Thread via Digitalmars-d-learn
On Saturday, 19 November 2022 at 04:37:51 UTC, thebluepandabear wrote: Thankfully I only code in D as a hobby, so I don't need to use getters/setters! Thanks. well, in that case, you can throw out everything that programmers have learnt over many decades, and just to whatever you want in yo

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

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
On Saturday, 19 November 2022 at 04:27:14 UTC, []() {}() wrote: On Saturday, 19 November 2022 at 04:19:01 UTC, thebluepandabear 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

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

2022-11-18 Thread via Digitalmars-d-learn
On Saturday, 19 November 2022 at 04:19:01 UTC, thebluepandabear 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

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

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
classes, and as such you will have a good chunk of code that is practically useless and doing nothing. Meant *fields not variables, excuse my terminology.

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

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
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 you're initial design never factored in the possibility of chan

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

2022-11-18 Thread via Digitalmars-d-learn
On Saturday, 19 November 2022 at 03:52:41 UTC, thebluepandabear wrote: On Saturday, 19 November 2022 at 03:39:18 UTC, []() {}() wrote: On Saturday, 19 November 2022 at 03:22:12 UTC, thebluepandabear wrote: On Saturday, 19 November 2022 at 03:19:53 UTC, []() {}() wrote: On Thursday, 17 November

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

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
If you only want to add setters: ``` class Rect2D { int _width; int _height; void width(int width) { writeln("SET"); this._width = width; } void height(int height) { writeln("SET"); this._height = height; } } ```

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

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
A better example of a code refactor after adding getters/setters is changing the names of the fields like so: ``` class Rect2D { int _width; int _height; ``` or ``` class Rect2D { int width_; int height_; ```

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

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
On Saturday, 19 November 2022 at 03:52:41 UTC, thebluepandabear wrote: On Saturday, 19 November 2022 at 03:39:18 UTC, []() {}() wrote: On Saturday, 19 November 2022 at 03:22:12 UTC, thebluepandabear wrote: On Saturday, 19 November 2022 at 03:19:53 UTC, []() {}() wrote: On Thursday, 17 November

Re: Need Advice: Union or Variant?

2022-11-18 Thread jwatson-CO-edu via Digitalmars-d-learn
On Saturday, 19 November 2022 at 03:38:26 UTC, jwatson-CO-edu wrote: Thank you, something similar to what you suggested reduced the atom size from 72 bytes to 40. Oh, based on another forum post I added constructors in addition to reducing the atom size 44%. ```d struct Atom{ F_Type kin

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

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
On Saturday, 19 November 2022 at 03:39:18 UTC, []() {}() wrote: On Saturday, 19 November 2022 at 03:22:12 UTC, thebluepandabear wrote: On Saturday, 19 November 2022 at 03:19:53 UTC, []() {}() wrote: On Thursday, 17 November 2022 at 09:52:11 UTC, Dukc wrote: .. D has far less need for getters/s

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

2022-11-18 Thread via Digitalmars-d-learn
On Saturday, 19 November 2022 at 03:24:41 UTC, thebluepandabear wrote: I think because of uniform function call syntax, getters/setters are not needed even for production level code, in D of course. In Java, you do need them so your point holds true in that scenario, but in D I don't really s

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

2022-11-18 Thread via Digitalmars-d-learn
On Saturday, 19 November 2022 at 03:22:12 UTC, thebluepandabear wrote: On Saturday, 19 November 2022 at 03:19:53 UTC, []() {}() wrote: On Thursday, 17 November 2022 at 09:52:11 UTC, Dukc wrote: .. D has far less need for getters/setters than Java or C++. The reason is [Uniform Function Call S

Re: Need Advice: Union or Variant?

2022-11-18 Thread jwatson-CO-edu via Digitalmars-d-learn
On Thursday, 17 November 2022 at 22:49:37 UTC, H. S. Teoh wrote: Just create a nested anonymous struct, like this: struct Atom { F_Type kind; union { // anonymous union struct { Atom* car; /

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

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
On Saturday, 19 November 2022 at 03:19:53 UTC, []() {}() wrote: On Thursday, 17 November 2022 at 09:52:11 UTC, Dukc wrote: .. D has far less need for getters/setters than Java or C++. The reason is [Uniform Function Call Syntax](https://ddili.org/ders/d.en/ufcs.html). This means that a member

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

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
On Saturday, 19 November 2022 at 03:14:18 UTC, []() {}() wrote: On Saturday, 19 November 2022 at 03:08:05 UTC, thebluepandabear wrote: It likely already does something, in that- >'it allows for change to occur without having to break the clients interface'. That too is the 'point' missing f

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

2022-11-18 Thread via Digitalmars-d-learn
On Thursday, 17 November 2022 at 09:52:11 UTC, Dukc wrote: .. D has far less need for getters/setters than Java or C++. The reason is [Uniform Function Call Syntax](https://ddili.org/ders/d.en/ufcs.html). This means that a member of a `struct` or `class` can start out as a normal field and be

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

2022-11-18 Thread via Digitalmars-d-learn
On Saturday, 19 November 2022 at 03:08:05 UTC, thebluepandabear wrote: It likely already does something, in that- >'it allows for change to occur without having to break the clients interface'. That too is the 'point' missing from that rant. With all due respect, I think your point is mostl

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

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
It likely already does something, in that- >'it allows for change to occur without having to break the clients interface'. That too is the 'point' missing from that rant. With all due respect, I think your point is mostly invalid due to the point that Dukc made.

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

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
On Saturday, 19 November 2022 at 03:04:41 UTC, thebluepandabear wrote: On Saturday, 19 November 2022 at 00:25:57 UTC, Gavin Ray wrote: On Thursday, 17 November 2022 at 09:52:11 UTC, Dukc wrote: D has far less need for getters/setters than Java or C++. The reason is [Uniform Function Call Synt

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

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
On Saturday, 19 November 2022 at 00:25:57 UTC, Gavin Ray wrote: On Thursday, 17 November 2022 at 09:52:11 UTC, Dukc wrote: D has far less need for getters/setters than Java or C++. The reason is [Uniform Function Call Syntax](https://ddili.org/ders/d.en/ufcs.html). This means that a member of

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

2022-11-18 Thread Gavin Ray via Digitalmars-d-learn
On Thursday, 17 November 2022 at 09:52:11 UTC, Dukc wrote: D has far less need for getters/setters than Java or C++. The reason is [Uniform Function Call Syntax](https://ddili.org/ders/d.en/ufcs.html). This means that a member of a `struct` or `class` can start out as a normal field and be la

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

2022-11-18 Thread via Digitalmars-d-learn
On Friday, 18 November 2022 at 20:18:41 UTC, matheus wrote: On Friday, 18 November 2022 at 09:42:21 UTC, []() {}() wrote: ... I think you missed the point of that video very badly. By the way just a few points from that video: Around: 2:32 -> "Never ever put in an 'accessor' until it actual

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

2022-11-18 Thread matheus via Digitalmars-d-learn
On Friday, 18 November 2022 at 09:42:21 UTC, []() {}() wrote: ... I think you missed the point of that video very badly. By the way just a few points from that video: Around: 2:32 -> "Never ever put in an 'accessor' until it actually does something...". Around: 3:10 -> "If there is an 'acc

Re: How often I should be using const? Is it useless/overrated?

2022-11-18 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 18, 2022 at 11:51:42AM +, thebluepandabear via Digitalmars-d-learn wrote: A question I have been thinking about whilst using D is how often I should be using const. You should use it as often as you need to use it, and no more. If you don't need to use it, don't use it. Ma

Re: How often I should be using const? Is it useless/overrated?

2022-11-18 Thread Dennis via Digitalmars-d-learn
On Friday, 18 November 2022 at 11:51:42 UTC, thebluepandabear wrote: A question I have been thinking about whilst using D is how often I should be using const. This should be a good read for you: [Is there any real reason to use "const"?](https://forum.dlang.org/post/dkkxcibwdsndbckon...@foru

How often I should be using const? Is it useless/overrated?

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
A question I have been thinking about whilst using D is how often I should be using const. Many people claim that all variables should be const by default, but whether or not it is really needed is debatable and oftentimes making everything const could cause readability issues and make the co

Re: How often I should be using const? Is it useless/overrated?

2022-11-18 Thread thebluepandabear via Digitalmars-d-learn
On Friday, 18 November 2022 at 11:51:42 UTC, thebluepandabear wrote: A question I have been thinking about whilst using D is how often I should be using const. Many people claim that all variables should be const by default, but whether or not it is really needed is debatable and oftentimes m

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

2022-11-18 Thread via Digitalmars-d-learn
On Thursday, 17 November 2022 at 09:46:57 UTC, matheus wrote: Food for thought: https://yewtu.be/watch?v=_xLgr6Ng4qQ or https://www.youtube.com/embed/_xLgr6Ng4qQ Matheus. 'Food for thought'? Sure, if you're feeding that to your dog. Public fields in 'class' definitions rarely have place i