advertisement

Simple Ruby DSL Techniques: Big Project Impact!

50 %
50 %
advertisement
Information about Simple Ruby DSL Techniques: Big Project Impact!
Technology

Published on January 3, 2014

Author: amanking

Source: slideshare.net

Description

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.
advertisement

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

Add a comment

Related presentations

Presentación que realice en el Evento Nacional de Gobierno Abierto, realizado los ...

In this presentation we will describe our experience developing with a highly dyna...

Presentation to the LITA Forum 7th November 2014 Albuquerque, NM

Un recorrido por los cambios que nos generará el wearabletech en el futuro

Um paralelo entre as novidades & mercado em Wearable Computing e Tecnologias Assis...

Microsoft finally joins the smartwatch and fitness tracker game by introducing the...

Related pages

Garden City Ruby 2014 - Simple Ruby DSL Techniques: Big ...

Garden City Ruby 2014 - Simple Ruby DSL Techniques: Big Project Impact! ... creating DSLs within a Ruby project, including simple OO code ...
Read more

GitHub - amanking/ruby_dsl_talk_companion: Code companion ...

Code companion to Aman King's talk "Simple Ruby DSL Techniques: Big Project Impact"
Read more

The Design of a DSL - YouTube

Given at the Portland Ruby Brigade meeting on Octob ... The Design of a DSL ... Simple Ruby DSL Techniques: Big Project Impact! ...
Read more

Ruby Videos | Lanyrd

Video Garden City Ruby 2014 - Simple Ruby DSL Techniques: Big Project Impact! (youtube.com) from Simple Ruby DSL Techniques: Big Project Impact at Garden ...
Read more

Aman King :: Garden City RubyConf 2014

My talk this time was about implementing simple Ruby DSL techniques to improve productivity ... Simple Ruby DSL Techniques: Big Project Impact! from Aman ...
Read more

amanking (Aman King) · GitHub

Follow their code on GitHub. ... ruby_dsl_talk_companion 1 Code companion to Aman King's talk "Simple Ruby DSL Techniques: Big Project Impact"
Read more

Ruby at ThoughtWorks - Martin Fowler

Ruby at ThoughtWorks. ... , reports that once a ruby project has got going, ... Choosing a development platform is never a simple choice, ...
Read more

Google

Advertising Programmes Business Solutions +Google About Google Google.com © 2016 - Privacy - Terms. Search; Images; Maps; Play; YouTube; News; Gmail ...
Read more