Ruby isan acceptable Lisp            Vitaly Kushner             astrails.com
Ruby is better   then Lisp
Ruby is better   then Lisp    sometimes*        ;-)
Language
http://www.flickr.com/photos/jantik/254695220/
Power
http://www.flickr.com/photos/lrargerich/4187318085/
Blub Language   Paradox             Paul Graham        http://paulgraham.com/avg.html
Is Lisp the most    powerful?
NO
It depends
• syntax
• syntax• linguistic power
• syntax• linguistic power• domain
• syntax• linguistic power• domain• libraries
• syntax• linguistic power• domain• libraries• community
Ruby
History
History• Yukihiro Matsumoto (aka "Matz")
History• Yukihiro Matsumoto (aka "Matz")• Released in 1994
History• Yukihiro Matsumoto (aka "Matz")• Released in 1994• Got known in US about 2000
History• Yukihiro Matsumoto (aka "Matz")• Released in 1994• Got known in US about 2000• Gained momentum around 2003-2005
more powerful     than Perlmore object-oriented   than Python.
PerlSmalltalk Eiffel  Ada  Lisp
• Simple consistent syntax• Dynamically typed• Late binding• Single Inheritance with Mixin support
• Everything is an object• Closures• Garbage Collection• Multi platform
Ruby is Awesome
Clean Syntax
var # variable$var # global variable@var # instance variable@@var # class variableCONST # constantClass # class
attrs = {  :src => "foo.img",  :width => 100,  :height => 200,  :class => Avatar}
User.find params[:id], :limit => 10, :order => “name”
if @project.owned_by?(@user)  return false unless @user.admin?end@project.complete!
Higher-order functions
Anonymous functions
def x_times(x, fun)  for i in 1..x    fun.call(i)  endendx_times(10, lambda {|x| puts x})
def x_times(x)  for i in 1..x    yield i  endendx_times(10) {|x| puts x}
def x_times(x)  for i in 1..x    yield i  endendx_times(10) do |x|  puts xend
Everything is an Objectthat you can extend
class Fixnum  def x_times    for i in 1..self      yield i    end  endend5.x_times { |x| puts x }
5.times { |x| puts x }
map       {|x|   ...}collect   {|x|   ...}select    {|x|   ...}reject    {|x|   ...}find      {|x|   ...}any?      {|x|   ...
3.megabytes=> 3145728
10.months.from_now=> Thu Aug 12 03:25:40 0300 2010
5.minutes.ago=> Mon Oct 12 03:21:02 0200 2009
Closures
def incrementor(increment)  proc {|x| x + increment}end>>   i5 = incrementor(5)=>   #<Proc:0x01874a78@(irb):46>>>   i5.cal...
Compact
# rubydef paidMore(amount)  proc {|e| e.salary > amount}end// C#public Predicate<Employee> PaidMore(int amount) {  return ...
// rubydef foo(n) lambda {|i| n+=i} end; lisp(defun foo (n) (lambda (i) (incf n i)))
# ruby[1,2,3].map {|n| n*n }.reject {|n| n%3==1 }; lisp(remove-if (lambda (n) (= (mod n 3) 1))           (mapcar (lambda (...
Macros
Ruby fakes macros   pretty well
OO      +Monkey Patching
class Person  def self.defsay(sound)    define_method("say_#{sound}") do      puts sound    end  end  defsay :hello  defsa...
>> bob = Person.new=> #<Person:0x185cba8>>> bob.say_hellohello=> nil>> bob.say_hihi=> nil
class Plugin < ActiveRecord::Base  validates_presence_of :name  validates_presence_of :description  validates_presence_of ...
Magic
NoMethodError
method_missing
User.find_by_name_and_company(   "Vitaly Kushner", "Astrails")
Ruby rewrite
require pprequire parse_treerequire parse_tree_extensionsdef print_ast(&block) pp block.to_sexpend
print_ast do puts "hello"ends(:iter,   s(:call, nil, :proc, s(:arglist)),    nil,     s(:call, nil, :puts, s(:arglist, s(:...
Multiple inheritance      is EVIL         :-)
Modules a.k.a. Mixins
module FlyHome  def set_home    @home = position  end  def fly_home    fly(@home)  endend
class Bird < Living  include FlyHome  def fly(direction) ...  def position ...endclass Airplane < Machine  include FlyHome...
Libraries
Rubygems
➜

~

✗
sudo
gem
install
astrails‐safeSuccessfully
installed
astrails‐safe‐0.2.71
gem
installedInstalling
ri
documentation...
Rubygems.org 12,798 gems
Github.com
Community  attitude
Testing
TDD
TDDTest Driven Development
BDD
BDDBehavior Driven Development
Pressure
TATFT
TATFTTest All The Fucking Time
• Test::Unit• RSpec• Shoulda• Cucumber• Webrat
it "should be able to show media" do  @media = stub_media  Media.stub!(:find).and_return(@media)  get :show, :id => @media...
Ruby is Better            then Lisp            Q &A                        Vitaly Kushner                         astrails...
Ruby is an Acceptable Lisp
Upcoming SlideShare
Loading in...5
×

Ruby is an Acceptable Lisp

1,603

Published on

Why ruby is a practical implementation of Lisp and why is a good replacement that actually can be used in production

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,603
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
8
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Ruby is an Acceptable Lisp

  1. 1. Ruby isan acceptable Lisp Vitaly Kushner astrails.com
  2. 2. Ruby is better then Lisp
  3. 3. Ruby is better then Lisp sometimes* ;-)
  4. 4. Language
  5. 5. http://www.flickr.com/photos/jantik/254695220/
  6. 6. Power
  7. 7. http://www.flickr.com/photos/lrargerich/4187318085/
  8. 8. Blub Language Paradox Paul Graham http://paulgraham.com/avg.html
  9. 9. Is Lisp the most powerful?
  10. 10. NO
  11. 11. It depends
  12. 12. • syntax
  13. 13. • syntax• linguistic power
  14. 14. • syntax• linguistic power• domain
  15. 15. • syntax• linguistic power• domain• libraries
  16. 16. • syntax• linguistic power• domain• libraries• community
  17. 17. Ruby
  18. 18. History
  19. 19. History• Yukihiro Matsumoto (aka "Matz")
  20. 20. History• Yukihiro Matsumoto (aka "Matz")• Released in 1994
  21. 21. History• Yukihiro Matsumoto (aka "Matz")• Released in 1994• Got known in US about 2000
  22. 22. History• Yukihiro Matsumoto (aka "Matz")• Released in 1994• Got known in US about 2000• Gained momentum around 2003-2005
  23. 23. more powerful than Perlmore object-oriented than Python.
  24. 24. PerlSmalltalk Eiffel Ada Lisp
  25. 25. • Simple consistent syntax• Dynamically typed• Late binding• Single Inheritance with Mixin support
  26. 26. • Everything is an object• Closures• Garbage Collection• Multi platform
  27. 27. Ruby is Awesome
  28. 28. Clean Syntax
  29. 29. var # variable$var # global variable@var # instance variable@@var # class variableCONST # constantClass # class
  30. 30. attrs = { :src => "foo.img", :width => 100, :height => 200, :class => Avatar}
  31. 31. User.find params[:id], :limit => 10, :order => “name”
  32. 32. if @project.owned_by?(@user) return false unless @user.admin?end@project.complete!
  33. 33. Higher-order functions
  34. 34. Anonymous functions
  35. 35. def x_times(x, fun) for i in 1..x fun.call(i) endendx_times(10, lambda {|x| puts x})
  36. 36. def x_times(x) for i in 1..x yield i endendx_times(10) {|x| puts x}
  37. 37. def x_times(x) for i in 1..x yield i endendx_times(10) do |x| puts xend
  38. 38. Everything is an Objectthat you can extend
  39. 39. class Fixnum def x_times for i in 1..self yield i end endend5.x_times { |x| puts x }
  40. 40. 5.times { |x| puts x }
  41. 41. map {|x| ...}collect {|x| ...}select {|x| ...}reject {|x| ...}find {|x| ...}any? {|x| ...}all? {|x| ...}sort {|a, b| ...}
  42. 42. 3.megabytes=> 3145728
  43. 43. 10.months.from_now=> Thu Aug 12 03:25:40 0300 2010
  44. 44. 5.minutes.ago=> Mon Oct 12 03:21:02 0200 2009
  45. 45. Closures
  46. 46. def incrementor(increment) proc {|x| x + increment}end>> i5 = incrementor(5)=> #<Proc:0x01874a78@(irb):46>>> i5.call(3)=> 8
  47. 47. Compact
  48. 48. # rubydef paidMore(amount) proc {|e| e.salary > amount}end// C#public Predicate<Employee> PaidMore(int amount) { return delegate(Employee e) { return e.Salary > amount; }}
  49. 49. // rubydef foo(n) lambda {|i| n+=i} end; lisp(defun foo (n) (lambda (i) (incf n i)))
  50. 50. # ruby[1,2,3].map {|n| n*n }.reject {|n| n%3==1 }; lisp(remove-if (lambda (n) (= (mod n 3) 1)) (mapcar (lambda (n) (* n n)) (1 2 3)))
  51. 51. Macros
  52. 52. Ruby fakes macros pretty well
  53. 53. OO +Monkey Patching
  54. 54. class Person def self.defsay(sound) define_method("say_#{sound}") do puts sound end end defsay :hello defsay :hiend
  55. 55. >> bob = Person.new=> #<Person:0x185cba8>>> bob.say_hellohello=> nil>> bob.say_hihi=> nil
  56. 56. class Plugin < ActiveRecord::Base validates_presence_of :name validates_presence_of :description validates_presence_of :author_id belongs_to :author, :class_name => "User" has_many :plugin_versions, :dependent => :destroy belongs_to :default_version, :class_name => "PluginVersion" acts_as_commentable acts_as_taggable ...end
  57. 57. Magic
  58. 58. NoMethodError
  59. 59. method_missing
  60. 60. User.find_by_name_and_company( "Vitaly Kushner", "Astrails")
  61. 61. Ruby rewrite
  62. 62. require pprequire parse_treerequire parse_tree_extensionsdef print_ast(&block) pp block.to_sexpend
  63. 63. print_ast do puts "hello"ends(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:call, nil, :puts, s(:arglist, s(:str, "hello"))))
  64. 64. Multiple inheritance is EVIL :-)
  65. 65. Modules a.k.a. Mixins
  66. 66. module FlyHome def set_home @home = position end def fly_home fly(@home) endend
  67. 67. class Bird < Living include FlyHome def fly(direction) ... def position ...endclass Airplane < Machine include FlyHome def fly(direction) ... def position ...end
  68. 68. Libraries
  69. 69. Rubygems
  70. 70. ➜

~

✗
sudo
gem
install
astrails‐safeSuccessfully
installed
astrails‐safe‐0.2.71
gem
installedInstalling
ri
documentation
for
astrails‐safe‐0.2.7...Building
YARD
(yri)
index
for
astrails‐safe‐0.2.7...Installing
RDoc
documentation
for
astrails‐safe‐0.2.7...➜

~

✗

  71. 71. Rubygems.org 12,798 gems
  72. 72. Github.com
  73. 73. Community attitude
  74. 74. Testing
  75. 75. TDD
  76. 76. TDDTest Driven Development
  77. 77. BDD
  78. 78. BDDBehavior Driven Development
  79. 79. Pressure
  80. 80. TATFT
  81. 81. TATFTTest All The Fucking Time
  82. 82. • Test::Unit• RSpec• Shoulda• Cucumber• Webrat
  83. 83. it "should be able to show media" do @media = stub_media Media.stub!(:find).and_return(@media) get :show, :id => @media.id response.should be_successend
  84. 84. Ruby is Better then Lisp Q &A Vitaly Kushner astrails.com@astrails @vkushner
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×