Re:Gem adds support for creating state machines for attribut...
by dymk on Sunday January 21, 2024 @07:44PM
(#39084697)
This is idiomatic Ruby syntax, and anyone familiar with the language knows what that code does
[ Parent
| on HN ]
Re:Gem adds support for creating state machines for attribut...
by heleninboodler on Monday January 22, 2024 @02:37AM
(#39087262)
This is kind of an absurd statement, given how prevalent custom DSLs are in Ruby (and in this example). No amount of familiarity with the Ruby language can tell me what this means:
event :ignite do
transition stalled: same, parked: :idling
end
You have to be familiar with the DSL, not Ruby.
Re:Gem adds support for creating state machines for attribut...
by dymk on Monday January 22, 2024 @07:03PM
(#39097394)
It's generally good practice to read a library's documentation to understand how to use it - there's not really a short cut to that, regardless of the language.
As for the syntax, you know that `event` is a method, passed the param `:ignite` and a block, and in that block, you call the method `transition` with kwargs `{stalled: same, parked: :idling}`, and `same` is another method call.
Re:Gem adds support for creating state machines for attribut...
by heleninboodler on Tuesday January 23, 2024 @02:09PM
(#39108080)
Indeed I know all of this. But in terms of "what this code does," the information that a method is passed a block that calls another method is not particularly interesting. The major problem I have with this sort of DSL is it encourages people to infer what it does based on what the ad hoc method names make it sound like this is intended to do. So many of these custom DSLs are documented by example rather than by any decent specification. The attitude that these clever little grammars make it so you can "just read it and it's obvious" is, in my opinion, sloppiness in code comprehension taken to an extreme.