SlideShare una empresa de Scribd logo
1 de 85
Descargar para leer sin conexión
Ruby is
an 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 Perl
more object-oriented
   than Python.
Perl
Smalltalk
 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 variable
CONST # constant
Class # 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)
  end
end

x_times(10, lambda {|x| puts x})
def x_times(x)
  for i in 1..x
    yield i
  end
end

x_times(10) {|x| puts x}
def x_times(x)
  for i in 1..x
    yield i
  end
end

x_times(10) do |x|
  puts x
end
Everything is
 an Object
that you can extend
class Fixnum
  def x_times
    for i in 1..self
      yield i
    end
  end
end

5.x_times { |x| puts x }
5.times { |x| puts x }
map       {|x|   ...}
collect   {|x|   ...}
select    {|x|   ...}
reject    {|x|   ...}
find      {|x|   ...}
any?      {|x|   ...}
all?      {|x|   ...}
sort      {|a,   b| ...}
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.call(3)
=>   8
Compact
# ruby
def paidMore(amount)
  proc {|e| e.salary > amount}
end

// C#
public Predicate<Employee> PaidMore(int amount) {
  return delegate(Employee e) {
    return e.Salary > amount;
  }
}
// ruby
def 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 (n) (* n n))
                   '(1 2 3)))
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
  defsay :hi
end
>> bob = Person.new
=> #<Person:0x185cba8>
>> bob.say_hello
hello
=> nil
>> bob.say_hi
hi
=> nil
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
Magic
NoMethodError
method_missing
User.find_by_name_and_company(
   "Vitaly Kushner", "Astrails")
Ruby rewrite
require 'pp'
require 'parse_tree'
require 'parse_tree_extensions'

def print_ast(&block)
 pp block.to_sexp
end
print_ast do
 puts "hello"
end

s(:iter,
   s(:call, nil, :proc, s(:arglist)),
    nil,
     s(:call, nil, :puts, s(:arglist, s(:str, "hello"))))
Multiple inheritance
      is EVIL
         :-)
Modules
 a.k.a. Mixins
module FlyHome
  def set_home
    @home = position
  end

  def fly_home
    fly(@home)
  end
end
class Bird < Living
  include FlyHome
  def fly(direction) ...
  def position ...
end

class Airplane < Machine
  include FlyHome
  def fly(direction) ...
  def position ...
end
Libraries
Rubygems
➜

~

✗
sudo
gem
install
astrails‐safe
Successfully
installed
astrails‐safe‐0.2.7
1
gem
installed
Installing
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...
➜

~

✗

Rubygems.org
 12,798 gems
Github.com
Community
  attitude
Testing
TDD
TDD
Test Driven Development
BDD
BDD
Behavior Driven Development
Pressure
TATFT
TATFT
Test 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.id
  response.should be_success
end
Ruby is Better
            then Lisp

            Q &A
                        Vitaly Kushner
                         astrails.com

@astrails               @vkushner

Más contenido relacionado

La actualidad más candente

Hacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 AutumnHacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 Autumn
Moriyoshi Koizumi
 

La actualidad más candente (20)

Redis and Ohm
Redis and OhmRedis and Ohm
Redis and Ohm
 
Serializing Ruby Objects in Redis
Serializing Ruby Objects in RedisSerializing Ruby Objects in Redis
Serializing Ruby Objects in Redis
 
Kotlin
KotlinKotlin
Kotlin
 
Linux basics by Raj Miraje
Linux basics by Raj MirajeLinux basics by Raj Miraje
Linux basics by Raj Miraje
 
It's the end of design patterns as we know it (and i feel fine)
It's the end of design patterns as we know it (and i feel fine)It's the end of design patterns as we know it (and i feel fine)
It's the end of design patterns as we know it (and i feel fine)
 
Advanced Radiant
Advanced RadiantAdvanced Radiant
Advanced Radiant
 
Smalltalk on rubinius
Smalltalk on rubiniusSmalltalk on rubinius
Smalltalk on rubinius
 
Raspberry pi a la cfml
Raspberry pi a la cfmlRaspberry pi a la cfml
Raspberry pi a la cfml
 
Perl 5.10
Perl 5.10Perl 5.10
Perl 5.10
 
TRICK2015 results
TRICK2015 resultsTRICK2015 results
TRICK2015 results
 
Fun with Ruby and Redis
Fun with Ruby and RedisFun with Ruby and Redis
Fun with Ruby and Redis
 
iSoligorsk #3 2013
iSoligorsk #3 2013iSoligorsk #3 2013
iSoligorsk #3 2013
 
Kotlin For Android - Functions (part 3 of 7)
Kotlin For Android - Functions (part 3 of 7)Kotlin For Android - Functions (part 3 of 7)
Kotlin For Android - Functions (part 3 of 7)
 
Redis, Resque & Friends
Redis, Resque & FriendsRedis, Resque & Friends
Redis, Resque & Friends
 
Dias do futuro presente da programação
Dias do futuro presente da programaçãoDias do futuro presente da programação
Dias do futuro presente da programação
 
Hacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 AutumnHacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 Autumn
 
Csp scala wixmeetup2016
Csp scala wixmeetup2016Csp scala wixmeetup2016
Csp scala wixmeetup2016
 
Swift Study #7
Swift Study #7Swift Study #7
Swift Study #7
 
YAPC::Tiny Introduction
YAPC::Tiny IntroductionYAPC::Tiny Introduction
YAPC::Tiny Introduction
 
My Adventures In Objective-C (A Rubyists Perspective)
My Adventures In Objective-C (A Rubyists Perspective)My Adventures In Objective-C (A Rubyists Perspective)
My Adventures In Objective-C (A Rubyists Perspective)
 

Similar a Ruby is an Acceptable Lisp

Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Ruby 程式語言入門導覽
Ruby 程式語言入門導覽
Wen-Tien Chang
 
Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手
Wen-Tien Chang
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
Dmitry Buzdin
 

Similar a Ruby is an Acceptable Lisp (20)

Ruby is Awesome
Ruby is AwesomeRuby is Awesome
Ruby is Awesome
 
The Joy Of Ruby
The Joy Of RubyThe Joy Of Ruby
The Joy Of Ruby
 
Introductionto fp with groovy
Introductionto fp with groovyIntroductionto fp with groovy
Introductionto fp with groovy
 
Ruby 程式語言入門導覽
Ruby 程式語言入門導覽Ruby 程式語言入門導覽
Ruby 程式語言入門導覽
 
Groovy presentation
Groovy presentationGroovy presentation
Groovy presentation
 
Groovy unleashed
Groovy unleashed Groovy unleashed
Groovy unleashed
 
Rakudo
RakudoRakudo
Rakudo
 
Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2
 
Ruby - Uma Introdução
Ruby - Uma IntroduçãoRuby - Uma Introdução
Ruby - Uma Introdução
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2ruby
 
Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
 
React Native Evening
React Native EveningReact Native Evening
React Native Evening
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 
JRuby 9000 - Optimizing Above the JVM
JRuby 9000 - Optimizing Above the JVMJRuby 9000 - Optimizing Above the JVM
JRuby 9000 - Optimizing Above the JVM
 
Ruby 入門 第一次就上手
Ruby 入門 第一次就上手Ruby 入門 第一次就上手
Ruby 入門 第一次就上手
 
An introduction to Ruby
An introduction to RubyAn introduction to Ruby
An introduction to Ruby
 
PuppetConf 2017: What's in a Name? Scaling ENC with DNS- Cameron Nicholson, A...
PuppetConf 2017: What's in a Name? Scaling ENC with DNS- Cameron Nicholson, A...PuppetConf 2017: What's in a Name? Scaling ENC with DNS- Cameron Nicholson, A...
PuppetConf 2017: What's in a Name? Scaling ENC with DNS- Cameron Nicholson, A...
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Explaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to ComeExplaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to Come
 
Elixir introd
Elixir introdElixir introd
Elixir introd
 

Más de Astrails

Más de Astrails (11)

Building and deploying React applications
Building and deploying React applicationsBuilding and deploying React applications
Building and deploying React applications
 
Accounting For Hackers
Accounting For HackersAccounting For Hackers
Accounting For Hackers
 
Machine Learning: Make Your Ruby Code Smarter
Machine Learning: Make Your Ruby Code SmarterMachine Learning: Make Your Ruby Code Smarter
Machine Learning: Make Your Ruby Code Smarter
 
Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.Migrating from Flux to Redux. Why and how.
Migrating from Flux to Redux. Why and how.
 
Engineering esthetics
Engineering estheticsEngineering esthetics
Engineering esthetics
 
Lean Software Development
Lean Software DevelopmentLean Software Development
Lean Software Development
 
RubyMotion: Put your Dreams in Motion with Ruby
RubyMotion: Put your Dreams in Motion with RubyRubyMotion: Put your Dreams in Motion with Ruby
RubyMotion: Put your Dreams in Motion with Ruby
 
WTF is NoSQL
WTF is NoSQLWTF is NoSQL
WTF is NoSQL
 
Cassandra intro
Cassandra introCassandra intro
Cassandra intro
 
Rails missing features
Rails missing featuresRails missing features
Rails missing features
 
Performance - When, What and How
Performance - When, What and HowPerformance - When, What and How
Performance - When, What and How
 

Último

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 

Ruby is an Acceptable Lisp