Variables of struct and class types are called objects - discuss
Paul Backus
snarwin at gmail.com
Sun Aug 3 15:31:34 UTC 2025
On Sunday, 3 August 2025 at 11:11:43 UTC, Brother Bill wrote:
> In Programming in D book, page 247, it is written: Variables
> of struct and class types are called objects.
>
> This struck me as odd and confusing. I have always been taught
> that objects are instances of classes. That is, new MyClass
> creates an instance or object of MyClass.
[...]
> Am curious whether experienced D developers actually refer to
> both struct and class variables as "objects" without confusion.
As far as I'm aware, there are two common definitions of the word
"object" that are used in D.
The first is the one you're familiar with: an object is an
instance of a class. D inherits this definition from Java, along
with the base class [`Object`][1].
The second one comes from C, where "object" refers to any value
stored in memory. This kind of "object" is defined in the
["Object Model" section][2] of the language specification, and is
mostly of interest to those writing low-level code that deals
directly with memory allocation.
I have never seen any D programmer use "object" to mean "struct
or class instance." The standard term for grouping together
structs and classes is ["aggregate,"][4] as in "aggregate type"
or "aggregate instance."
[1]: https://dlang.org/library/object/object.html
[2]: https://dlang.org/spec/intro.html#object-model
[3]: https://ddili.org/ders/d.en/index.html
[4]: https://dlang.org/spec/declaration.html#aggregates
More information about the Digitalmars-d-learn
mailing list