gracelang / language

Design of the Grace language and its libraries
GNU General Public License v2.0
6 stars 1 forks source link

Value Objects #90

Open kjx opened 8 years ago

kjx commented 8 years ago

Do we want to introduce value objects, and if so, how?

We have thought about this, but now need to do it.

kjx commented 8 years ago

So: the first question is: what are value objects? in particular: mutable or immutable?

I think immutable obejct with default comparison by public field is what it should be. I think.

as distinct from record or struct (mutable object with default comparison of public fields, fields default public)

KimBruce commented 8 years ago

Does it make sense to talk about a public field?

What is the motivation for value objects? Is this just to define a default eval operator?

Perhaps immutable with default(?) comparison by some collection of public methods (always including asString?).

kjx commented 8 years ago

Does it make sense to talk about a public field?

Well yes and no. Yes in that there can be fields declared public or readable; No it that auto-generating based on fields is bad. No because as Michael pointed out (and I only now understand what he meant) you don't have fields any more. As we're using the terms, aliasing rather than renaming means you can't think of fields within objects, you have to think of them as lambda-captured mutable state, because you can have more than one name for the same "field". (this is why I still prefer renaming!)

What is the motivation for value objects? Is this just to define a default eval operator?

Partly. Also to, umm, support immutable values.

Perhaps immutable with default(?) comparison by some collection of public methods

how do you choose the collection? - how do you choose what the default comparison should be?

(always including asString?)

that strikes me as just terrible engineering.

apblack commented 8 years ago

I certainly agree that we should have immutable objects as part of the language.

I'm less convinced about generating the magic equality operations, but I guess that would be handy. I would need to read that essay first.

I would want it to be possible to define whatever behaviour on value objects the application wants. So value objects would not be structs. If that's what you meant, then I'm in agreement.