3 ms·
The problem with classes is that an object's available methods can change over time. E.g. a file object should not have a write method after having been closed.
by Zalastax 8y ago
The problem with classes is that an object's available methods can change over time. E.g. a file object should not have a write method after having been closed. Ongoing research is trying to fix this problem (see Scribble, mailbox types for unordered interaction), but until then I'd say it's probably best to stick with dynamic messaging.
- nine_k 8y agoAnother approach is that object's available methods cannot change over time, but this requires move semantics: `close(file)` consumes `file`, so you can't invoke anything else on it. Rust has this built-in (lifetimes and move / borrow semantics); I suppose C++ can model this, too.
- Zalastax 8y agoYes! Changing available methods/consuming data terms are virtually the same - the former can be modelled as having methods consume their object and returning a copy of it that has another type. My background is in distributed systems and there linearity has a big cost, which is why the research I mentioned needs to be done.