4 ms·
This is idiomatic Ruby syntax, and anyone familiar with the language knows what that code does
by dymk 3y ago
This is idiomatic Ruby syntax, and anyone familiar with the language knows what that code does
- heleninboodler 3y agoThis 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.
- dymk 3y agoIt'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.
- heleninboodler 3y agoIndeed 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.