Is defining get/set methods for every field overkill?
thebluepandabear
therealbluepandabear at protonmail.com
Sat Nov 19 03:04:41 UTC 2022
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 a `struct` or `class` can start out as a
>> normal field and be later converted to getter/setter if
>> needed, without breaking calling code.
>
> This is a great point that I actually had never considered. If
> you need to swap out the implementation details later, you
> haven't actually locked yourself in to exposing the raw member
> because you swap it with a getter function/property of the same
> name. Huh. I love D.
Interesting point. If that's the case, I'd say getters/setters
are mostly just code bloat.
More information about the Digitalmars-d-learn
mailing list