Last active
August 29, 2015 14:15
-
-
Save paulghaddad/0546fa8e4f5413aa0476 to your computer and use it in GitHub Desktop.
Level Up 7: Understands DSLs, how to create them, and their limitations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Explain why DSLs are an advantage to a language like ruby. | |
DSLs are by their nature a very expressive and highly readable language that extends Ruby's own expressiveness to a higher level. DSLs not only make a specific task easier, but also make the code clearer. Ruby also lends itself to DSL development because its extensive use of syntactic sugar, including the following language features: | |
- optional parentheses | |
- symbols (they are less noisy than strings) | |
- blocks (enable delayed execution of code) | |
- literal arrays and hashes | |
- variable-length arguments | |
- modules (provide a clean separation of code) | |
- splats (handle parameter arrays) | |
- eval, instance_eval, and class_eval methods | |
- define_method and alias_method | |
In summary, DSLs provide a clear, readable and flexible interface for performing a specific job. | |
2. Give two examples of DSLs that we use on an everyday basis in rails development | |
RSpec, Rake, ActiveRecord Models, Capistrano and routes.rb are some of the most prominent examples of DSLs in Rails development. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment