4 ms·
I'd like to chip in about Ruby's API/DSL designs. Most DSLs (at least the ones I've worked with, or made), are simply a convenience, and eventually to make the
by spoiler 12y ago
I'd like to chip in about Ruby's API/DSL designs.
Most DSLs (at least the ones I've worked with, or made), are simply a convenience, and eventually to make the code more expressive.
Behind this fancy DSL, there is an API, the DSL itself isn't really an API, it's just a "frontend" for that API.
I'll pull a simple and shitty example out of my ass[1]:
game = Game::CardsAgainstHumanity.new do
fun 9000
rounds 10
must_involve_drinking!
end
which could be a DSL for doing something like:
game = Game::CardsAgainstHumanity.new()
game.configuration(:fun_level, 9000)
game.configuration(:round_count, 10)
game.set_game_flag(:drinking, true)
game.set_game_flag(:drinking_optional, false)
Like I said, this is a shit example. The API behind this could be way more complex and allow for much greater fine-tuning of stuff than the DSL would, but the DSL exist for stuff that's common.
Also, one would have to go out of their way to hide the actual API behind the DSL, which is very unlikely and due to Ruby's nature, one could always expose the API anyway (through the C API, as a last resort).
Also, I'd like to add little bit of something about the Haskell part, even though I've never written one line of Haskell, but this isn't really about Haskell:
> "Look, I used a monad! And defined my own type class for custom folding of data! Isn’t that amazing?“. “What does it do?” “It’s a CRUD app”
I bet everyone did the same or something of that sort in <pick your language> when they were starting out with it, or exploring some part of it that they were previously unfamiliar with. This is excellent, actually. Why? Because they'll learn the benefits and pitfalls of that approach. They'll be wiser and better programmers tomorrow because of that.
---
[1]: No pun intended. Also, not looking for a real example out of principle, because I feel like the author was too lazy to do some research; this is just my opinion. Frankly, this feels like click-baiting.