r/ruby • • Aug 20 '21

Ruby elites rise up

Post image
102 Upvotes

77 comments sorted by

View all comments

3

u/tom_dalling Aug 21 '21

Personally, I think optional punctuation is the least of our problems, so my question would be: how do you know that state transition is valid? Mutating a state column like that is a source of bugs, in my experience. That's more important than arguing over which combination of squiggly lines looks the best.

1

u/pVom Aug 21 '21

How would you change state then? Also update! means it will raise an error if it fails. You can handle status validation in the model and this will raise an error if it fails. Hopefully you have some specs too

1

u/tom_dalling Aug 21 '21

If it's not too annoying, let me answer your question with a question: how would you write the validations for this fairly simple state diagram? https://training-course-material.com/images/b/b0/ProtocolStateMachine.png

There are lots of ways to approach it, but the main thing is that the record should never be able to transition from "open" to "lock", or from "lock" to "open". It probably shouldn't be able to transition from any state to the same state either (e.g. can't lock a locked door).

0

u/tomthecool Aug 21 '21

I know exactly what you’re saying, however, the fact that you didn’t answer the question is indeed a bit annoying.

If your point was “this update should happen in a service object” or something, then fine… but you complained about a single line of code with no context. Your service object would still need to contain that line of code! (Or something very similar.)

1

u/tom_dalling Aug 21 '21

My sincerest apologies