Is defining get/set methods for every field overkill?


Sat Nov 19 09:05:42 UTC 2022


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 C# ;-)

If you used such, you would still need to completely refactor 
your class when you decided to implement you business rules 
(within the getter/setter), since you cannot do anything more 
than get and set with auto property.

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 customer, there code will 
stop working - cause they'll have to recompile it against the new 
library.

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 engineering.


More information about the Digitalmars-d-learn mailing list