Your SlideShare is downloading. ×
  • Like
DSL or NoDSL - Euruko - 29may2010
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

DSL or NoDSL - Euruko - 29may2010

  • 1,546 views
Published

José Valim (@josevalim) from Plataforma talks about DSL or NoDSL at Euruko 2010 in Kraków/Poland.

José Valim (@josevalim) from Plataforma talks about DSL or NoDSL at Euruko 2010 in Kraków/Poland.

Published in Technology , News & Politics
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,546
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
19
Comments
0
Likes
5

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide






















































Transcript

  • 1. DSL or NoDSL? José Valim blog.plataformatec.com @josevalim
  • 2. DSL or NoDSL? ID blog twitter José Valim blog.plataformatec.com @josevalim
  • 3. A brief introduction... José Valim blog.plataformatec.com @josevalim
  • 4. A short story... José Valim blog.plataformatec.com @josevalim
  • 5. José Valim blog.plataformatec.com @josevalim
  • 6. mail_form José Valim blog.plataformatec.com @josevalim
  • 7. Contact form recipe José Valim blog.plataformatec.com @josevalim
  • 8. Contact form recipe ✦ Controller (20 LOC) José Valim blog.plataformatec.com @josevalim
  • 9. Contact form recipe ✦ Controller (20 LOC) ✦ Model (30 LOC) José Valim blog.plataformatec.com @josevalim
  • 10. Contact form recipe ✦ Controller (20 LOC) ✦ Model (30 LOC) ✦ View (30 LOC) José Valim blog.plataformatec.com @josevalim
  • 11. Contact form recipe ✦ Controller (20 LOC) ✦ Model (30 LOC) ✦ View (30 LOC) ✦ Mailer (15 LOC) José Valim blog.plataformatec.com @josevalim
  • 12. Contact form recipe ✦ Controller (20 LOC) ✦ Model (30 LOC) ✦ View (30 LOC) ✦ Mailer (15 LOC) ✦ View (20 LOC) José Valim blog.plataformatec.com @josevalim
  • 13. Contact form recipe ✦ Controller (20 LOC) ✦ Model (30 LOC) ✦ View (30 LOC) ✦ Mailer (15 LOC) ✦ View (20 LOC) José Valim blog.plataformatec.com @josevalim
  • 14. Let’s create a DSL! José Valim blog.plataformatec.com @josevalim
  • 15. Domain Speci c Language José Valim blog.plataformatec.com @josevalim
  • 16. class ContactForm < MailForm::Base to "jose.valim@plataformatec.com.br" from "contact_form@app_name.com" subject "Contact form" attributes :name, :email, :message end ContactForm.new(params[:contact_form]).deliver José Valim blog.plataformatec.com @josevalim
  • 17. from { |c| "#{c.name} <#{c.email}>" } José Valim blog.plataformatec.com @josevalim
  • 18. to :author_email def author_email Author.find(self.author_id).email end José Valim blog.plataformatec.com @josevalim
  • 19. headers { |c| { "X-Spam" => "True" } if c.honey_pot } José Valim blog.plataformatec.com @josevalim
  • 20. class ContactForm < MailForm::Base to :author_email from { |c| "#{c.name} <#{c.email}>" } subject "Contact form" headers { |c| { "X-Spam" => "True" } if c.honey_pot } attributes :name, :email, :message def author_email Author.find(self.author_id).email end end José Valim blog.plataformatec.com @josevalim
  • 21. Issues José Valim blog.plataformatec.com @josevalim
  • 22. Issues ✦ Lacks simplicity José Valim blog.plataformatec.com @josevalim
  • 23. Issues ✦ Lacks simplicity ✦ Reduces programmer happiness José Valim blog.plataformatec.com @josevalim
  • 24. NoDSL! José Valim blog.plataformatec.com @josevalim
  • 25. From: GitHub <noreply@github.com> To: jose.valim@plataformatec.com.br Message-Id: <4bfe3e812c22fc17d@github.com> Subject: [GitHub] someone commented on a commit Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 MESSAGE BODY José Valim blog.plataformatec.com @josevalim
  • 26. class ContactForm < MailForm::Base attributes :name, :email, :message def headers { :to => author_email, :from => "#{name} <#{email}>", :subject => "Contact form" } end def author_email Author.find(self.author_id).email end end José Valim blog.plataformatec.com @josevalim
  • 27. It provides a nice DSL José Valim blog.plataformatec.com @josevalim
  • 28. It relies on a simple contract José Valim blog.plataformatec.com @josevalim
  • 29. José Valim blog.plataformatec.com @josevalim
  • 30. Rack José Valim blog.plataformatec.com @josevalim
  • 31. class RackApp def self.call(env) [200, { "Content-Type" => "text/html"}, ["Hello"]] end end José Valim blog.plataformatec.com @josevalim
  • 32. RackApp = Rack::AppBuilder.new do |env| status 200 headers "Content-Type" => "text/html" body ["Hello"] after_return { # do something } end José Valim blog.plataformatec.com @josevalim
  • 33. Rake and Thor José Valim blog.plataformatec.com @josevalim
  • 34. task :process do # do some processing end namespace :app do task :setup do # do some setup # end end rake app:setup José Valim blog.plataformatec.com @josevalim
  • 35. task :process do # do some processing end namespace :app do task :setup do # do some setup Rake::Task[:process].invoke end end rake app:setup José Valim blog.plataformatec.com @josevalim
  • 36. class Default < Thor def process # do some processing end end class App < Thor def setup # do some setup # end end thor app:setup José Valim blog.plataformatec.com @josevalim
  • 37. class Default < Thor def process # do some processing end end class App < Thor def setup # do some setup Default.new.process end end thor app:setup José Valim blog.plataformatec.com @josevalim
  • 38. Rspec and Test::Unit José Valim blog.plataformatec.com @josevalim
  • 39. # Rspec describe User do it "should be valid" do User.new(@attributes).should be_valid end end # Test::Unit class UserTest < Test::Unit::Case def test_user_validity assert User.new(@attributes).valid? end end José Valim blog.plataformatec.com @josevalim
  • 40. A nal story... José Valim blog.plataformatec.com @josevalim
  • 41. class UsersController < ApplicationController def index @users = User.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @users } end end def show @user = User.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @user } end end def new @user = User.new respond_to do |format| format.html # new.html.erb format.xml { render :xml => @user } end end def edit @user = User.find(params[:id]) end Scaffold Controller def create @user = User.new(params[:user]) respond_to do |format| if @user.save format.html { redirect_to(@user, :notice => 'User was successfully created.') } format.xml { render :xml => @user, :status => :created, :location => @user } else format.html { render :action => "new" } format.xml { render :xml => @user.errors, :status => :unprocessable_entity } end end end def update @user = User.find(params[:id]) respond_to do |format| if @user.update_attributes(params[:user]) format.html { redirect_to(@user, :notice => 'User was successfully updated.') } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @user.errors, :status => :unprocessable_entity } end end end def destroy @user = User.find(params[:id]) @user.destroy respond_to do |format| format.html { redirect_to(users_url) } format.xml { head :ok } end end end José Valim blog.plataformatec.com @josevalim
  • 42. class UsersController < ApplicationController restful! end José Valim blog.plataformatec.com @josevalim
  • 43. class UsersController < ApplicationController restful! create do before { # do something before } success.flash "This is the message" end create.after do # do something after end end José Valim blog.plataformatec.com @josevalim
  • 44. InheritedResources José Valim blog.plataformatec.com @josevalim
  • 45. class UsersController < InheritedResources::Base def create # do something before flash[:success] = "This is the message" super # do something after end end José Valim blog.plataformatec.com @josevalim
  • 46. Bene ts José Valim blog.plataformatec.com @josevalim
  • 47. Bene ts ✦ Simple José Valim blog.plataformatec.com @josevalim
  • 48. Bene ts ✦ Simple ✦ Less code to maintain José Valim blog.plataformatec.com @josevalim
  • 49. Bene ts ✦ Simple ✦ Less code to maintain ✦ More time to focus on important features José Valim blog.plataformatec.com @josevalim
  • 50. Bene ts ✦ Simple ✦ Less code to maintain ✦ More time to focus on important features ✦ Just Ruby™ José Valim blog.plataformatec.com @josevalim
  • 51. José Valim blog.plataformatec.com @josevalim
  • 52. ORM Callbacks José Valim blog.plataformatec.com @josevalim
  • 53. # DSL class User < ActiveRecord::Base after_save :deliver_notification, :unless => :admin? end # NoDSL class User < ActiveRecord::Base def save(*) if super deliver_notification unless admin? end end end José Valim blog.plataformatec.com @josevalim
  • 54. DSL or NoDSL? José Valim blog.plataformatec.com @josevalim
  • 55. Thank you! José Valim blog.plataformatec.com @josevalim
  • 56. Questions? Feedback? Opinions? José Valim blog.plataformatec.com @josevalim
  • 57. Questions? Feedback? Opinions? ID blog twitter José Valim blog.plataformatec.com @josevalim