4 ms·
Like properly model a domain in domain terms?
by bvrmn 2y ago
Like properly model a domain in domain terms?
- nottorp 2y agoAnd that won't be a state machine with the states having more fancy names?
- InDubioProRubio 2y agoIt will be, but the idea of having an overview over the states is gone then. There is just modules-> objects with the transitions being method calls. Nobody will have to know all the things about all the state transitions, resulting in another problem (dys)solved by architecture obscurity. If needs be the state-machine can be reconstructed on a whiteboard by a team of five.
- grumpyprole 2y agoA state machine makes the actual program state first class and easy to reason about. One does not even need mutable state to model one. Whereas you appear to be advocating mutable objects. The state space then becomes a combinatorial explosion of all the hidden mutable state "encapsulated" inside the objects. Object oriented programming is not the only way and often leads to a poor domain model. Some OOP evangelists even model a bank account with a mutable balance field and methods for making deposits. This is a absolutely not a faithful model of the domain (ledgers have been used for hundreds/thousands of years). In summary, yes a state machine can absolutely be a good domain model.
- bvrmn 2y agoIt's interesting to know about what state machines you talk. From my experience most of the time it's an entity with state property with finger countable cardinality. And state is assumed to be changed directly. And it's not easy to reason because author only heard about state machines and state transitions are spread over all code base.
- grumpyprole 2y agoI was talking in the most general sense. I am sure there are state machine implementations that are terrible to reason about, especially any that emerge from a codegen tool. But hopefully they are the exception and not the rule.
- throwaway2037 2y agoWoah, this caught my eye: > especially any that emerge from a codegen tool Can you give an example?
- majormajor 2y agoI don't follow the connection you're making. State machines often are implemented with mutable objects. And one does not need mutable objects to make "modules-> objects with the transitions being method calls". Every method call could return a fresh, immutable object, nothing requires mutation there. I'd see a method like: `TransitionTo(newState)` as a major smell compared to an explicit `TransistionToNewState` and I think OOO can be helpful (hardly required, of course) in that one neat way of streamlining usage of your code is that if you're implementing objects then the object for something in "State A" might not even have "TransitionToStateC" if that's not a valid operation. (No, you don't HAVE to write state machine code that allows you to ask for invalid operations, but it's a common pattern I've seen in real code and in online discussion/blogs/stack overflow.)
- grumpyprole 2y agoObjects and "method calls" generally implies mutable state to me, but yes the parent was not explicit about this. I assumed mutable (implicit) state was being argued in favour of an explicit state representation. Perhaps I misunderstood. For a state machine, I would expect a function such as: transition : (old_state, event) -> new_state Or if we use immutable objects, and one method per simple event, then something like: transition_event1 : () -> new_state Which I think is similar to what you hace. So I think we are in agreement here.
- saurik 2y ago> I assumed mutable (implicit) state was being argued in favour of an explicit state representation. I definitely was not: I would argue for structured logic rather than implicit state. The idea you are discussing seems to be more about imperative vs. functional design, and that would also be a lot better... but these are Google engineers managing a million interacting state machines via a giant pile of global (mutable) state, resulting in tons of bugs such as this one that isn't even fixed yet: https://issues.webrtc.org/issues/339131894 https://issues.webrtc.org/issues/339131894 A reply I just left elsewhere on this thread, noting that "state machine" doesn't imply the clean perfectly-factored concept you'd learn in a computer science class: these are ad hoc state machines that result from having a number of developers who don't really care and who think they can "dead reckon" the state of the system if they just add enough transition functions. https://news.ycombinator.com/item?id=42250142 https://news.ycombinator.com/item?id=42250142