5 ms·
A definition of objects that rules out immutable objects doesn't seem viable to me. Furthermore, your definition merely requires mutability, which is a feature
by naasking 10y ago
A definition of objects that rules out immutable objects doesn't seem viable to me.
Furthermore, your definition merely requires mutability, which is a feature of Java and C++ objects, so I'm not sure what you think is lacking. Your definition reduces to "objects undergo state transitions".
- seanmcdirmid 10y agoObjects require at least an identity. Immutable data structures necessarily don't have identity (well, to say identity isn't meaningful because aliases can simply be seen as copies). There is more to it than identity, and you can always use a mutable variable or rebound parameter to recreate an identity for an immutable object (I.e. the world as an input and output).
- lacampbell 10y agoI don't follow why objects need an identity, as you define it. How does not having an identity make something un-objectlike?
- seanmcdirmid 10y agoI would say identity is core to objectness. Without identity, something is purely structural, only its value is relevant because it will not transition to another state later. Objects must be things you can manipulate. They have a presence beyond their values.
- lacampbell 10y agoI use objects that can't transition from one state to another practically every working day. It's a strange view point to me that because something is immutable, it's not really an object. But a view worth thinking about. To me the important thing is hiding internal state and sending high level messages instead of something like "change internal field x to y". Whether that internal state you're hiding is immutable or not seems irrelevant to me.
- seanmcdirmid 10y agoIf you have a variable X that is pointing at different immutable maps over time, then X is the identity of your object that is implemented with multiple immutable maps.
- spdionis 10y agoBecause objects are supposed to hide their internal state and the actions you do with them are heavily dependent on that state. This means that an object must have an identity to be sure you're working with the right object. If you don't have identity it means that you must know yourself what state you're working with. This defeats the definition of objects that says that their state is hidden.
- naasking 10y agoEncapsulation is not identity. Immutable objects are still perfectly encapsulated, but they don't have identity, which is what the OP was asking about.
- lacampbell 10y agoI do come across the view a lot that immutable objects aren't really OO. It's something I really don't understand - state that changes over time doesn't seem like a key ingredient to me at all.
- naasking 10y agoI disagree. Encapsulation is the only universal property of object oriented abstraction (see Will Cook's papers on OO vs ADTs). Identity is merely a property of some objects, not all objects.
- ratmice 10y agoI don't really agree as well, Modula-3 (although i'm not terribly familiar with the language) has partial revelation (a rather nuanced form of encapsulation), and branding where structural transparency does not preclude nominal identity... I tend to view the whole thing as a false dichotomy.
- naasking 10y agoI'm not sure what you're disagreeing with specifically. "Partial revelation" sounds like a feature of ADTs they mixed into objects, which all modern OO languages have done, so I'm not sure what you think is the relevance to objects specifically.
- ratmice 10y agoI was kind of disagreeing with 2 things: that encapsulation must be all encompassing, and that identity is not meaningful or useful for transparent immutable data...
- naasking 10y ago> that encapsulation must be all encompassing If we're trying to characterize "objects" in its purest sense, it must have some all-encompassing property. Mixing in other properties for pragmatic reasons doesn't seem relevant here. > that identity is not meaningful or useful for transparent immutable data No one claimed it wasn't useful, simply that it's not necessary to have objects.
- ratmice 10y ago>No one claimed it wasn't useful, simply that it's not necessary to have objects. "Immutable data structures necessarily don't have identity (well, to say identity isn't meaningful because aliases can simply be seen as copies)." I read saying that it is necessariy for them not to have identity, and that giving them identity isn't useful or meaningful. If it said "don't necessarily" instead of necessarily don't, I would agree