2. Internal DSLs are particular ways of
using a host language to give the host
language the feel of a particular
language.
Martin Fowler
Tuesday, May 18, 2010
3. Internal DSLs are particular ways of
abusing a host language to give the host
language the feel of a particular
language.
Martin Fowler
Tuesday, May 18, 2010
7. Order o = new Order();
Product p1 = new Product(1,Product.find(“Billy”));
o.addProduct(p1);
Product p2 = new Product(2,Product.find(”Janso"));
o.addProduct(p2);
Product p3 = new Product(4,Product.find(“Traby"));
o.addProduct(p3);
o.setPriorityRush(true);
customer.addOrder(o);
http://www.st.ewi.tudelft.nl/~bouwers/main/slides/2008jspring.pdf
Tuesday, May 18, 2010
42. class Person
def self.find(key, value)
puts "You want results from #{key} with a value of #{value}"
end
end
Person.find('name', 'Zef')
Tuesday, May 18, 2010
43. class Person
def self.find(key, value)
puts "You want results from #{key} with a value of #{value}"
end
def self.method_missing(id, *args)
if id.id2name =~ /find_by_(.+)/
return self.find(Regexp.last_match(1), args[0])
else
raise NoMethodError
end
end
end
Person.find_by_name('Zef')
Tuesday, May 18, 2010
65. (if (= n 10)
(print "It was ten!”)
nil)
Tuesday, May 18, 2010
66. (when (= n 10)
(print "It was ten!”))
Tuesday, May 18, 2010
67. (defn when [c ifTrue]
(if c
ifTrue
nil))
Tuesday, May 18, 2010
68. (when (= n 10)
(print "It was ten!”))
Tuesday, May 18, 2010
69. (defmacro when [c ifTrue]
(list 'if c ifTrue 'nil))
Tuesday, May 18, 2010
70. (defmacro when [c ifTrue]
`(if ~c
~ifTrue
nil))
Tuesday, May 18, 2010
71. (when (= n 10)
(print "It was ten!”))
(if (= n 10)
(print "It was ten!”)
nil)
Tuesday, May 18, 2010
72. (when (= n 10)
(print "It was ten!”))
(if (= n 10)
(print "It was ten!”)
nil)
Tuesday, May 18, 2010
73. (loop for i in *random*
counting (evenp i) into evens
counting (oddp i) into odds
summing i into total
maximizing i into max
minimizing i into min
finally (return (list min max total evens odds)))
Tuesday, May 18, 2010
74. (defent User
[:username :string {:unique true}]
[:openid :string]
[:email :email]
[:points :int])
http://github.com/zefhemel/adia
Tuesday, May 18, 2010
79. <h1>Hello, Rails!</h1>
<%= link_to "My Blog", post_path %>
http://zef.me/2308/when-rails-fails
Tuesday, May 18, 2010
80. <h1>Hello, Rails!</h1>
<%= link_to "My Blog", post_path %>
post_url failed to generate from
{:controller=>"posts", :action=>"show"} – you may have ambiguous
routes, or you may need to supply additional parameters for this
route. content_url has the following required parameters:
["posts", :id] – are they all satisfied?
http://zef.me/2308/when-rails-fails
Tuesday, May 18, 2010
81. <%= link_to 'Destroy', post, :confrm => 'Are you sure?', :method => :delete %>
Tuesday, May 18, 2010
82. <%= link_to 'Destroy', post, :confrm => 'Are you sure?', :method => :delete %>
Tuesday, May 18, 2010
83. class Post < ActiveRecord::Base
validates_presence_of :nam
end
Tuesday, May 18, 2010
84. class Post < ActiveRecord::Base
validates_presence_of :nam
end
Tuesday, May 18, 2010
94. + -
quick development lack of static checking
built on existing errors hard to trace
platform back to origin
existing community bad error messages
limited freedom in
syntax
Tuesday, May 18, 2010