SlideShare a Scribd company logo
Version 0.1



                      A Little Ruby, A Lot of Objects
Preface
Welcome to my little book. In it, my goal is to teach you a way to think about
computation, to show you how far you can take a simple idea: that all computation
consists of sending messages to objects. Object-oriented programming is no longer
unusual, but taking it to the extreme – making everything an object – is still supported by
only a few programming languages.

Can I justify this book in practical terms? Will reading it make you a better programmer,
even if you never use "call with current continuation" or indulge in "metaclass hackery"?
I think it might, but perhaps only if you're the sort of person who would read this sort of
book even if it had no practical value.

The real reason for reading this book is that the ideas in it are neat. There's an intellectual
heritage here, a history of people building idea upon idea. It's an academic heritage, but
not in the fussy sense. It's more a joyous heritage of tinkerers, of people buttonholing
their friends and saying, "You know, if I take that and think about it like this, look what I
can do!"

Prerequisites

With effort, someone who didn't know programming could read this book. I expect that
most readers will know at least one programming language, not necessarily an object-
oriented one.

I use a few simple mathematical ideas in some of the examples. The factorial function is
the most complex, and I explain a simplified form of it, rather than assume you know
what it is. I don't think the book requires any particular mathematical inclination, so don't
be scared off at the first sight of factorial.

Using the book
This book is written as a dialogue between two people, one who knows objects well, and
one who doesn't. The text builds cumulatively. If you don't understand something about
one chapter, you'll likely understand the next chapter even less. So I recommend you read
slowly. The characters in the book take frequent breaks. I think that's a good idea.

This book uses Ruby, a freely available language developed by Yukihiro Matsumoto, but
it is not a book about Ruby. Ruby constructs are introduced gradually, as they're needed,
rather than in any systematic order. They're described only enough to allow you to
understand code that contains them.

If you want to try variants of the examples, you may need a little more Ruby knowledge.
The example files (see below) define new constructs a little more completely. However,

                 Copyright © 2001 by Brian Marick. All Rights Reserved.
DRAFT                       (marick@visibleworkings.com)                               DRAFT
even with the examples, this book is not a Ruby tutorial. If you want to use Ruby for
general-purpose programming – and you should, since it's a wonderful rapid-
development language for many types of applications - the book to read is Programming
Ruby, by David Thomas and Andrew Hunt (available online at
www.rubycentral.com/book/index.html). You'll find that Ruby has many more features
than this book describes.

Notation

Ruby text and values printed by the Ruby interpreter are in italic font. Everything else is
in normal font. Important terms are in bold when they're defined.

Sometimes, one participant will show a partially completed snippet of Ruby code. The
unfinished part is indicated with ???:

      def finish_this
        ???
      end

Bold italic font is used to draw your attention to a part of some Ruby code

      class Something
        def some_function
          "look here"
        end
      end

Running the examples

I recommend you play with the examples as you read.

As of this writing, Ruby works on Unix and Windows. It is available from www.ruby-
lang.org. The Windows download comes from www.rubycentral.com, at
www.rubycentral.com/downloads/ruby-install.html.

I recommend you use the Ruby interpreter irb. Here's an example:

       > irb
       irb(main):001:0> 1 + 1
       2
       irb(main):002:0>

All of the examples in the book are available from www.visibleworkings.com/little-
ruby/source. At the points in the text where an example is complete, a marginal note
names the example's file:




DRAFT                                         2                                     DRAFT
Exactly. What do you suppose this Ruby             The name tells me it computes factorial,
function does?                                     but I’ not sure how.
                                                         m

        def factorial(n)
          if n == 1
             n
          else
             n * factorial(n-1)
          end
        end

ch1-factorial.rb


You can either cut and paste the example into irb, or load the example into Ruby like
this:

          > irb
          irb(main):001:0> load 'ch1-factorial.rb'
          true
          irb(main):002:0>

(This assumes you're running irb in the directories where the examples live.) Thereafter,
you can type things like this:

          irb(main):002:0> factorial 5
          120
          irb(main):003:0>

Acknowledgements
This book was inspired by The Little Lisper, by Daniel P. Friedman and Mattthias
Felleisen. I fell in love with their book around 1984. The fourth edition, titled The Little
Schemer, is still available. If you like this book, you'll like that one too, especially
because it treats computation from a different perspective.

The Little Lisper is famous for using food in its examples. As the authors say, "[it] is not
a good book to read while dieting." As an ironic homage to my inspiration, one of the
characters here is an exercise freak. In that way, this is a very different book.

I received help and encouragement from people who read drafts: Al Chou, Mikkel
Damsgaard, Joani DiSilvestro, Pat Eyler, Darrell Ferguson, Tammo Freese, Hal E.
Fulton, Ned Konz, Dragos A. Manolescu, Dawn Marick, Pete McBreen, Nat Pryce,
Christopher Sawtell, Kevin Smith, Dave Thomas, David Tillman, and Eugene
Wallingford.




DRAFT                                          3                                      DRAFT

More Related Content

Similar to FrontMatter

ruby_vs_perl_and_python
ruby_vs_perl_and_pythonruby_vs_perl_and_python
ruby_vs_perl_and_python
tutorialsruby
 
Ruby tutorial
Ruby tutorialRuby tutorial
Ruby tutorial
knoppix
 
Culture And Aesthetic Revisited
Culture And Aesthetic RevisitedCulture And Aesthetic Revisited
Culture And Aesthetic Revisited
Adam Keys
 
Book of ruby
Book of rubyBook of ruby
Book of ruby
phongbk1609
 
Naming Things (with notes)
Naming Things (with notes)Naming Things (with notes)
Naming Things (with notes)
Pete Nicholls
 
Spoiling The Youth With Ruby (Euruko 2010)
Spoiling The Youth With Ruby (Euruko 2010)Spoiling The Youth With Ruby (Euruko 2010)
Spoiling The Youth With Ruby (Euruko 2010)
Karel Minarik
 
Documentation for developers
Documentation for developersDocumentation for developers
Documentation for developers
Michael Marotta
 
On lisp
On lispOn lisp
On lisp
Peter Wang
 
Intro To Ror
Intro To RorIntro To Ror
Intro To Ror
myuser
 
Computers for-smart-people
Computers for-smart-peopleComputers for-smart-people
Computers for-smart-people
King Mj
 
On the path to become a jr. developer short version
On the path to become a jr. developer short versionOn the path to become a jr. developer short version
On the path to become a jr. developer short version
Antonelo Schoepf
 
Naming Things
Naming ThingsNaming Things
Naming Things
Pete Nicholls
 
Mongodb
MongodbMongodb
Mongodb
ichangbai
 
Ruby
RubyRuby
Ruby
RubyRuby
The Bund language
The Bund languageThe Bund language
The Bund language
Vladimir Ulogov
 
Invasion of the dynamic language weenies
Invasion of the dynamic language weeniesInvasion of the dynamic language weenies
Invasion of the dynamic language weenies
Srijit Kumar Bhadra
 
Avoid adding a new library to the project
Avoid adding a new library to the projectAvoid adding a new library to the project
Avoid adding a new library to the project
PVS-Studio
 
Thinkapjava
ThinkapjavaThinkapjava
Thinkapjava
sanjeetey
 
The Little MongoDB Book - Karl Seguin
The Little MongoDB Book - Karl SeguinThe Little MongoDB Book - Karl Seguin
The Little MongoDB Book - Karl Seguin
Paulo Fagundes
 

Similar to FrontMatter (20)

ruby_vs_perl_and_python
ruby_vs_perl_and_pythonruby_vs_perl_and_python
ruby_vs_perl_and_python
 
Ruby tutorial
Ruby tutorialRuby tutorial
Ruby tutorial
 
Culture And Aesthetic Revisited
Culture And Aesthetic RevisitedCulture And Aesthetic Revisited
Culture And Aesthetic Revisited
 
Book of ruby
Book of rubyBook of ruby
Book of ruby
 
Naming Things (with notes)
Naming Things (with notes)Naming Things (with notes)
Naming Things (with notes)
 
Spoiling The Youth With Ruby (Euruko 2010)
Spoiling The Youth With Ruby (Euruko 2010)Spoiling The Youth With Ruby (Euruko 2010)
Spoiling The Youth With Ruby (Euruko 2010)
 
Documentation for developers
Documentation for developersDocumentation for developers
Documentation for developers
 
On lisp
On lispOn lisp
On lisp
 
Intro To Ror
Intro To RorIntro To Ror
Intro To Ror
 
Computers for-smart-people
Computers for-smart-peopleComputers for-smart-people
Computers for-smart-people
 
On the path to become a jr. developer short version
On the path to become a jr. developer short versionOn the path to become a jr. developer short version
On the path to become a jr. developer short version
 
Naming Things
Naming ThingsNaming Things
Naming Things
 
Mongodb
MongodbMongodb
Mongodb
 
Ruby
RubyRuby
Ruby
 
Ruby
RubyRuby
Ruby
 
The Bund language
The Bund languageThe Bund language
The Bund language
 
Invasion of the dynamic language weenies
Invasion of the dynamic language weeniesInvasion of the dynamic language weenies
Invasion of the dynamic language weenies
 
Avoid adding a new library to the project
Avoid adding a new library to the projectAvoid adding a new library to the project
Avoid adding a new library to the project
 
Thinkapjava
ThinkapjavaThinkapjava
Thinkapjava
 
The Little MongoDB Book - Karl Seguin
The Little MongoDB Book - Karl SeguinThe Little MongoDB Book - Karl Seguin
The Little MongoDB Book - Karl Seguin
 

More from tutorialsruby

<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
tutorialsruby
 
TopStyle Help & <b>Tutorial</b>
TopStyle Help & <b>Tutorial</b>TopStyle Help & <b>Tutorial</b>
TopStyle Help & <b>Tutorial</b>
tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>
tutorialsruby
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
tutorialsruby
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
tutorialsruby
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
tutorialsruby
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
tutorialsruby
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
tutorialsruby
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
tutorialsruby
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
tutorialsruby
 
CSS
CSSCSS
CSS
CSSCSS
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
tutorialsruby
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
tutorialsruby
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
tutorialsruby
 

More from tutorialsruby (20)

<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
 
TopStyle Help & <b>Tutorial</b>
TopStyle Help & <b>Tutorial</b>TopStyle Help & <b>Tutorial</b>
TopStyle Help & <b>Tutorial</b>
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting <b>...</b>
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
 
<img src="../i/r_14.png" />
<img src="../i/r_14.png" /><img src="../i/r_14.png" />
<img src="../i/r_14.png" />
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 

Recently uploaded

zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
Ajin Abraham
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid ResearchHarnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Neo4j
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
Safe Software
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
Edge AI and Vision Alliance
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Pitangent Analytics & Technology Solutions Pvt. Ltd
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
BibashShahi
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 

Recently uploaded (20)

zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid ResearchHarnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
 
Artificial Intelligence and Electronic Warfare
Artificial Intelligence and Electronic WarfareArtificial Intelligence and Electronic Warfare
Artificial Intelligence and Electronic Warfare
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 

FrontMatter

  • 1. Version 0.1 A Little Ruby, A Lot of Objects Preface Welcome to my little book. In it, my goal is to teach you a way to think about computation, to show you how far you can take a simple idea: that all computation consists of sending messages to objects. Object-oriented programming is no longer unusual, but taking it to the extreme – making everything an object – is still supported by only a few programming languages. Can I justify this book in practical terms? Will reading it make you a better programmer, even if you never use "call with current continuation" or indulge in "metaclass hackery"? I think it might, but perhaps only if you're the sort of person who would read this sort of book even if it had no practical value. The real reason for reading this book is that the ideas in it are neat. There's an intellectual heritage here, a history of people building idea upon idea. It's an academic heritage, but not in the fussy sense. It's more a joyous heritage of tinkerers, of people buttonholing their friends and saying, "You know, if I take that and think about it like this, look what I can do!" Prerequisites With effort, someone who didn't know programming could read this book. I expect that most readers will know at least one programming language, not necessarily an object- oriented one. I use a few simple mathematical ideas in some of the examples. The factorial function is the most complex, and I explain a simplified form of it, rather than assume you know what it is. I don't think the book requires any particular mathematical inclination, so don't be scared off at the first sight of factorial. Using the book This book is written as a dialogue between two people, one who knows objects well, and one who doesn't. The text builds cumulatively. If you don't understand something about one chapter, you'll likely understand the next chapter even less. So I recommend you read slowly. The characters in the book take frequent breaks. I think that's a good idea. This book uses Ruby, a freely available language developed by Yukihiro Matsumoto, but it is not a book about Ruby. Ruby constructs are introduced gradually, as they're needed, rather than in any systematic order. They're described only enough to allow you to understand code that contains them. If you want to try variants of the examples, you may need a little more Ruby knowledge. The example files (see below) define new constructs a little more completely. However, Copyright © 2001 by Brian Marick. All Rights Reserved. DRAFT (marick@visibleworkings.com) DRAFT
  • 2. even with the examples, this book is not a Ruby tutorial. If you want to use Ruby for general-purpose programming – and you should, since it's a wonderful rapid- development language for many types of applications - the book to read is Programming Ruby, by David Thomas and Andrew Hunt (available online at www.rubycentral.com/book/index.html). You'll find that Ruby has many more features than this book describes. Notation Ruby text and values printed by the Ruby interpreter are in italic font. Everything else is in normal font. Important terms are in bold when they're defined. Sometimes, one participant will show a partially completed snippet of Ruby code. The unfinished part is indicated with ???: def finish_this ??? end Bold italic font is used to draw your attention to a part of some Ruby code class Something def some_function "look here" end end Running the examples I recommend you play with the examples as you read. As of this writing, Ruby works on Unix and Windows. It is available from www.ruby- lang.org. The Windows download comes from www.rubycentral.com, at www.rubycentral.com/downloads/ruby-install.html. I recommend you use the Ruby interpreter irb. Here's an example: > irb irb(main):001:0> 1 + 1 2 irb(main):002:0> All of the examples in the book are available from www.visibleworkings.com/little- ruby/source. At the points in the text where an example is complete, a marginal note names the example's file: DRAFT 2 DRAFT
  • 3. Exactly. What do you suppose this Ruby The name tells me it computes factorial, function does? but I’ not sure how. m def factorial(n) if n == 1 n else n * factorial(n-1) end end ch1-factorial.rb You can either cut and paste the example into irb, or load the example into Ruby like this: > irb irb(main):001:0> load 'ch1-factorial.rb' true irb(main):002:0> (This assumes you're running irb in the directories where the examples live.) Thereafter, you can type things like this: irb(main):002:0> factorial 5 120 irb(main):003:0> Acknowledgements This book was inspired by The Little Lisper, by Daniel P. Friedman and Mattthias Felleisen. I fell in love with their book around 1984. The fourth edition, titled The Little Schemer, is still available. If you like this book, you'll like that one too, especially because it treats computation from a different perspective. The Little Lisper is famous for using food in its examples. As the authors say, "[it] is not a good book to read while dieting." As an ironic homage to my inspiration, one of the characters here is an exercise freak. In that way, this is a very different book. I received help and encouragement from people who read drafts: Al Chou, Mikkel Damsgaard, Joani DiSilvestro, Pat Eyler, Darrell Ferguson, Tammo Freese, Hal E. Fulton, Ned Konz, Dragos A. Manolescu, Dawn Marick, Pete McBreen, Nat Pryce, Christopher Sawtell, Kevin Smith, Dave Thomas, David Tillman, and Eugene Wallingford. DRAFT 3 DRAFT