• Save
Simple Ruby DSL Techniques: Big Project Impact!
Upcoming SlideShare
Loading in...5
×
 

Simple Ruby DSL Techniques: Big Project Impact!

on

  • 745 views

Talk that introduces simple DSL techniques in Ruby. Developers are encouraged to apply such techniques for their project's business domain to gain benefits usually received from DSL-ish APIs of ...

Talk that introduces simple DSL techniques in Ruby. Developers are encouraged to apply such techniques for their project's business domain to gain benefits usually received from DSL-ish APIs of frameworks.

Presented at Garden City RubyConf 2014 in Bangalore, India.

Statistics

Views

Total Views
745
Views on SlideShare
625
Embed Views
120

Actions

Likes
2
Downloads
0
Comments
1

5 Embeds 120

http://www.amanking.com 70
http://localhost 45
http://feeds.feedburner.com 3
http://www.linkedin.com 1
http://www.slideee.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

CC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • http://ruby-doc.org/core-2.1.0/Module.html#method-i-privatehttp://ruby-doc.org/stdlib-2.1.0/libdoc/forwardable/rdoc/Forwardable.html#method-i-delegate
  • http://guides.rubyonrails.org/active_record_querying.htmlhttp://guides.rubyonrails.org/association_basics.html
  • http://guides.rubyonrails.org/action_controller_overview.html
  • https://github.com/sunspot/sunspot#readme

Simple Ruby DSL Techniques: Big Project Impact! Simple Ruby DSL Techniques: Big Project Impact! Presentation Transcript

  • Simple Ruby DSL Techniques: Big Project Impact! Aman King king@thoughtworks.com
  • Obligatory Humour… No offence intended toward any community; hint of satire
  • What is common between Beggars & Developers?
  • When two Beggars meet at a railway station…
  • Or when two Developers meet at a tech conference…
  • Both introduce themselves… with the question…
  • “What platform do you work on?” 2 1 Java Ruby
  • “What domain do you work on?” Finance Retail
  • What about…
  • Implementation Concerns
  • Technical Domain
  • Technical Domain? Business Domain? What is a Domain?
  • Characteristics of a Domain • Specialized field • Common context shared by specialists • Common vocabulary among specialists
  • Characteristics of a Domain • Specialized field • Common context shared by specialists • Common vocabulary among specialists
  • “Is this method private?” “Let’s simply delegate these methods!”
  • “Is this method private?” “Let’s simply delegate these methods!”
  • “Is this method private?” DSL! “Let’s simply delegate these methods!”
  • “Is this method private?” DSL in core Ruby! “Let’s simply delegate these methods!”
  • More commonly cited DSL examples…
  • ActiveRecord
  • ActionController
  • Sunspot
  • All Ruby DSLs for Technical Domains
  • Where are the DSLs for Business Domains?
  • Well, framework writers don’t write them! framework writers can only guess generic technical domains
  • You need to write the DSLs for your Business Domain! only you know the business problem your project solves
  • Why write them?
  • Well, why not!
  • Enough fluff, now stuff…
  • Recognize your DSLs!
  • Recognize your DSLs!
  • Fluent Interface
  • Recognize your DSLs!
  • Single-line Declaration
  • Recognize your DSLs!
  • Block Declaration
  • Recognize your Secret Sauce!
  • Recognize your Secret Sauce! Fluent Interface
  • Fluent Interface Method Chaining & Builder Pattern
  • Recognize your Secret Sauce! Single-line Declaration
  • Single-line Declaration Class Methods & Metaprogramming
  • Recognize your Secret Sauce! Block Declaration
  • Block Declaration Class/Instance Methods & Metaprogramming
  • Some real-world inspirations…
  • Fluent Interface
  • Domain: Production Support https://github.com/amanking/ruby_dsl_talk_companion
  • More sneak peeks…
  • Single-line Declaration
  • Domain: Community Forum https://github.com/amanking/ruby_dsl_talk_companion
  • More sneak peeks…
  • Block Declaration
  • Domain: Social Networking https://github.com/amanking/ruby_dsl_talk_companion
  • More sneak peeks…
  • Secret Sauce Recap
  • Secret Sauce Recap Fluent Interface • simple object-oriented code • builder pattern • method chaining
  • Secret Sauce Recap Single-line Declaration • modules as mixins • class-level methods • basic metaprogramming – define_method – alias_method
  • Secret Sauce Recap Block Declaration • modules as mixins • class-level methods • builder pattern • advanced metaprogramming – – – – instance_eval class_eval define_method def
  • But mind it! you win some, you lose some
  • Guidelines & Gotchas
  • Guidelines & Gotchas Builder Pattern • not everything needs a builder • keep builder class separate from built class • always setup reasonable default values
  • Guidelines & Gotchas Metaprogramming • • • • • do not shy away but be vigilant split metaprogramming responsibilities extra focus on readability control options explosion drive using tests or duplication removal
  • Guidelines & Gotchas Possible Pains • debugging (unit tests help but not always) • understanding a metaprogramming-based DSL implementation • dealing with variations • not everyone may “get” the beautiful DSL you write
  • Let’s talk benefits! observed in real-world projects
  • Benefits Productivity • full cycle of user stories completed in half day or less • reusable code Maintenance • improved readability & consistency • less defects • quick fixes Knowledge • deeper Ruby know-how for team members • deeper business domain exploration by team members • quick ramp-up for new team members
  • Final words
  • Final words Custom DSLs for Business Domains
  • Final words Custom DSLs for Business Domains Just try it!
  • Thanks! amanking.com github.com/amanking bitbucket.org/amanking slideshare.net/amanking