SlideShare a Scribd company logo
A Humanist's Introduction to Programming (with Ruby)     Wayne Graham & Joe Gilbert MITH, Oct. 19, 2010
What does that mean? (We're still figuring it out.)
Why teach programming to humanities scholars?
Jean Bauer Early American Foreign Service Database
Mapping Taqwacore: the Kominas
Why program? Express complex logic or relationships Perform computations Do things that take a long time or are difficult for humans to do (counting, comparing, repeating, graphing)
Why program?     "when you don't create things,     you become defined by your      tastes rather than ability. your     tastes only narrow & exclude     people. so create."       why the lucky stiff (@_why)
What is a programming language? An artificial language with a limited purpose A means of expressing computations (math) and algorithms (logic)
What is a programming language? ..like human languages in some ways!   Syntax (form) Semantics (meaning) signs /words (variables, symbols, numbers, strings) expressions narrative  ("flow,"  decisions, conditions, loops) complex entities  (methods, structures, & objects)
Why Ruby? General purpose Object-oriented Usable locally or over the web English-like syntax and useful built-in features "Fun" to write Other commonly used languages:  C, C++, Java, PHP, Python, JavaScript, ActionScript
  "...trying to make Ruby natural, not simple."   Yukihiro Matsumoto  aka "Matz"
Why not Ruby? Not as easy to run on the web as PHP (or JavaScript) Used less often than PHP, and major platforms (WordPress, Drupal, Omeka) use PHP Ruby isn't Rails Object-oriented languages are conceptually difficult to grasp
What we will cover What kinds of information do we use in programs? How can we store and reuse information? How can we describe collections of information? What operations can we perform with information? How can we repeat steps? What if we only want to do things under certain conditions?
What we won't cover Building a database driven website Design patterns Testing code Inheritance Software design Modules Mixins Procs Lambdas Coercion (Monkey Patching)
Try it out! irb   http://www.ruby-lang.org/ http://tryruby.org/   http://rubyinstaller.org/
We work with a few basic types of information Numbers  like 1, 4000, -33.3 Text , including  characters ,  words ,  sentences , and  paragraphs
Types of information numbers, letters, boolean values integers: 4 ,  1040 ,  -55 ,  9999 floating-point numbers: 1.1 ,  0.444 ,  9999.0001 ,  -3.33 text (strings): "a" ,  'cat' ,  "The quick brown fox jumped over the lazy dogs." ,  '8 keys', '7’ boolean (yes or no?): true ,  false
Variables "words" that hold information   >   the_lonliest_number = 1 => 1   >  truth = "beauty" => "beauty"
Collections
Collections text, numbers...collections?   Array: >  presidents = ["Jefferson", "Madison", "Monroe"] => ["Jefferson", "Madison", "Monroe"]   presidents[0] = "Jefferson",  presidents[1] = "Madison", etc.    Associative array ("hash"):  >  states = {"VA" => "Virginia", "MD" => "Maryland"} => {"VA" => "Virginia", "MD" => "Maryland"} states["VA"] = "Virginia", states["MD"] = "Maryland"
Operators arithmetic and more my_variable = 5 my_other_variable = "hi"   >  my_variable + 2   => 7   >  my_variable * 3 => 15   >  my_other_variable + " there!" => "hi there!"   >  presidents = presidents + ["Washington"] => ["Jefferson", "Madison", "Monroe", "Washington"]   >  presidents = presidents - ["Washington"] => ["Jefferson", "Madison", "Washington"] What happens with  presidents * 2 ?
Type casting duck typing and type casting Quotes are meaningful   >  my_favorite_number = '2' => "2"   >  my_favorite_number + 2 TypeError: can't convert Fixnum into String   >  my_favorite_number.to_i + 2 => 4
Special Symbols   math operators +        addition (and concatenation) -         subtraction /         division *         multiplication assignment operators   =         assign a value   +=        add, then assign a value   other operators equivalence, non-equivalence, boolean (and, or, etc.)
Printing things to the screen puts "Doctor Who"   puts tardis   puts doctors[0] puts doctors["David Tennant"]   puts "My favorite episode is " + best_episode
Do something! Store your street address, city, state, and zip code in variables (or even better, a hash!), then print them in the usual format: Joseph Gilbert 160 McCormick Road Charlottesville, VA 22902 address = {'name' => 'Joseph Gilbert', 'street' => '160 McCormick Road', 'city' => 'Charlottesville', 'state' => 'VA', 'zip' => '22902'} puts address['name'] puts address['street'] puts address['city'] + ', ' + address['state'] + ' ' + address['zip']
Repeating yourself  >  puts presidents[0] Jefferson =>nil >  puts presidents[1] Madison => nil >  puts presidents[2] Monroe => nil this isn't fun or efficient!
Repetition: "iterating" with each >  presidents.each do |president|   >      puts president >  end Jefferson Madison Monroe => ["Jefferson", "Madison", "Monroe"]
.each for hashes states = {"VA" => "Virginia", "MD" => "Maryland"} states.each do |code, state|      puts code.to_s + " is the postal code for " + state.to_s end
Do Something, pt. 2 Create a collection of these authors and the year they passed away; print the collection in the following format: Charles Dickens passed away in 1870. Charles Dickens, 1870 William Thackeray, 1863 Anthony Trollope, 1882 Gerard Manley Hopkins, 1889 authors = {"Charles Dickens" => "1870", "William Thackeray" => "1863", "Anthony Trollope" => "1882", "Gerard Manley Hopkins" => "1889"} authors.each do |author, year|   puts author.to_s + " passed away in " + year.to_s end
Resources Learn to Program http://pine.fm/LearnToProgram/ Why's Poignant Guide to Ruby http://mislav.uniqpath.com/poignant-guide/ Ruby Documentation http://ruby-doc.org/core/ “ Pick-axe Book ”  http://ruby-doc.org/docs/ProgrammingRuby/  Teach Me to Code http://www.teachmetocode.com RubyTu.be Rubylearning.com

More Related Content

ODP
Modern Web Development with Perl
PPTX
API Design Antipatterns - APICon SF
PPT
Inroduction to XSLT with PHP4
PPT
XML and Web Services with PHP5 and PEAR
ODP
How Xslate Works
ODP
Lucene And Solr Intro
PPT
Web Scraper Shibuya.pm tech talk #8
PPT
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
Modern Web Development with Perl
API Design Antipatterns - APICon SF
Inroduction to XSLT with PHP4
XML and Web Services with PHP5 and PEAR
How Xslate Works
Lucene And Solr Intro
Web Scraper Shibuya.pm tech talk #8
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...

What's hot (20)

ODP
Djabot – Python Jabber Bot
ODP
Advanced Perl Techniques
PPT
PEAR For The Masses
PPT
Session Server - Maintaing State between several Servers
PPT
Perl Tidy Perl Critic
PPT
The Big Documentation Extravaganza
PPTX
The Django Web Application Framework 2
PDF
Web develop in flask
PPT
course slides -- powerpoint
PDF
Writing and using php streams and sockets tek11
PPT
Go OO! - Real-life Design Patterns in PHP 5
KEY
Battle of NoSQL stars: Amazon's SDB vs MongoDB vs CouchDB vs RavenDB
PPT
Introduction to Google API - Focusky
PPT
Presentation log4 j
PPT
Create a web-app with Cgi Appplication
PPTX
Streams, sockets and filters oh my!
PPT
XML Transformations With PHP
PDF
Boost Maintainability
PDF
Using Jenkins for Continuous Integration of Perl components OSD2011
PDF
Text indexing and search libraries for PHP - Zoë Slattery - Barcelona PHP Con...
Djabot – Python Jabber Bot
Advanced Perl Techniques
PEAR For The Masses
Session Server - Maintaing State between several Servers
Perl Tidy Perl Critic
The Big Documentation Extravaganza
The Django Web Application Framework 2
Web develop in flask
course slides -- powerpoint
Writing and using php streams and sockets tek11
Go OO! - Real-life Design Patterns in PHP 5
Battle of NoSQL stars: Amazon's SDB vs MongoDB vs CouchDB vs RavenDB
Introduction to Google API - Focusky
Presentation log4 j
Create a web-app with Cgi Appplication
Streams, sockets and filters oh my!
XML Transformations With PHP
Boost Maintainability
Using Jenkins for Continuous Integration of Perl components OSD2011
Text indexing and search libraries for PHP - Zoë Slattery - Barcelona PHP Con...
Ad

Viewers also liked (7)

PPTX
Computer Programming Overview
PPTX
The next 2500 days
PPS
Paradigm 1218656614474137 8
PPTX
Programming Paradigm
PPTX
Standard Algorithms
PPTX
Prgramming paradigms
PPT
Programming Paradigms
Computer Programming Overview
The next 2500 days
Paradigm 1218656614474137 8
Programming Paradigm
Standard Algorithms
Prgramming paradigms
Programming Paradigms
Ad

Similar to MITH Digital Dialogues: Intro to Programming for Humanists (with Ruby) (20)

PPT
Domain Specific Languages
PPT
03 Php Array String Functions
PPT
Lecture 3 - Comm Lab: Web @ ITP
ODP
Why Python by Marilyn Davis, Marakana
PPT
Php Training
PDF
Anvita Dynamic Fontson Web Feb2001
PPTX
Php Form
PPT
Learning Ruby
PPTX
Business Intelligence Portfolio
ODP
Haml & Sass presentation
PPT
Forum Presentation
PPT
ODP
PHP 102: Out with the Bad, In with the Good
ODP
Intro to #memtech PHP 2011-12-05
PPT
REST, HTTP, and the PATCH verb (with kittens)
PPT
A brief history of the web
PPT
How to be a better Google-r
PPT
Getting the Most Out of OpenSocial Gadgets
PPT
Open Source Package Php Mysql 1228203701094763 9
Domain Specific Languages
03 Php Array String Functions
Lecture 3 - Comm Lab: Web @ ITP
Why Python by Marilyn Davis, Marakana
Php Training
Anvita Dynamic Fontson Web Feb2001
Php Form
Learning Ruby
Business Intelligence Portfolio
Haml & Sass presentation
Forum Presentation
PHP 102: Out with the Bad, In with the Good
Intro to #memtech PHP 2011-12-05
REST, HTTP, and the PATCH verb (with kittens)
A brief history of the web
How to be a better Google-r
Getting the Most Out of OpenSocial Gadgets
Open Source Package Php Mysql 1228203701094763 9

MITH Digital Dialogues: Intro to Programming for Humanists (with Ruby)

  • 1. A Humanist's Introduction to Programming (with Ruby)     Wayne Graham & Joe Gilbert MITH, Oct. 19, 2010
  • 2. What does that mean? (We're still figuring it out.)
  • 3. Why teach programming to humanities scholars?
  • 4. Jean Bauer Early American Foreign Service Database
  • 6. Why program? Express complex logic or relationships Perform computations Do things that take a long time or are difficult for humans to do (counting, comparing, repeating, graphing)
  • 7. Why program?     "when you don't create things,    you become defined by your     tastes rather than ability. your    tastes only narrow & exclude    people. so create."      why the lucky stiff (@_why)
  • 8. What is a programming language? An artificial language with a limited purpose A means of expressing computations (math) and algorithms (logic)
  • 9. What is a programming language? ..like human languages in some ways! Syntax (form) Semantics (meaning) signs /words (variables, symbols, numbers, strings) expressions narrative ("flow," decisions, conditions, loops) complex entities (methods, structures, & objects)
  • 10. Why Ruby? General purpose Object-oriented Usable locally or over the web English-like syntax and useful built-in features "Fun" to write Other commonly used languages:  C, C++, Java, PHP, Python, JavaScript, ActionScript
  • 11.   "...trying to make Ruby natural, not simple."   Yukihiro Matsumoto aka "Matz"
  • 12. Why not Ruby? Not as easy to run on the web as PHP (or JavaScript) Used less often than PHP, and major platforms (WordPress, Drupal, Omeka) use PHP Ruby isn't Rails Object-oriented languages are conceptually difficult to grasp
  • 13. What we will cover What kinds of information do we use in programs? How can we store and reuse information? How can we describe collections of information? What operations can we perform with information? How can we repeat steps? What if we only want to do things under certain conditions?
  • 14. What we won't cover Building a database driven website Design patterns Testing code Inheritance Software design Modules Mixins Procs Lambdas Coercion (Monkey Patching)
  • 15. Try it out! irb   http://www.ruby-lang.org/ http://tryruby.org/ http://rubyinstaller.org/
  • 16. We work with a few basic types of information Numbers like 1, 4000, -33.3 Text , including characters , words , sentences , and paragraphs
  • 17. Types of information numbers, letters, boolean values integers: 4 , 1040 , -55 , 9999 floating-point numbers: 1.1 , 0.444 , 9999.0001 , -3.33 text (strings): "a" , 'cat' , "The quick brown fox jumped over the lazy dogs." , '8 keys', '7’ boolean (yes or no?): true , false
  • 18. Variables "words" that hold information   >  the_lonliest_number = 1 => 1   > truth = "beauty" => "beauty"
  • 20. Collections text, numbers...collections?   Array: > presidents = ["Jefferson", "Madison", "Monroe"] => ["Jefferson", "Madison", "Monroe"]   presidents[0] = "Jefferson",  presidents[1] = "Madison", etc.   Associative array ("hash"): > states = {"VA" => "Virginia", "MD" => "Maryland"} => {"VA" => "Virginia", "MD" => "Maryland"} states["VA"] = "Virginia", states["MD"] = "Maryland"
  • 21. Operators arithmetic and more my_variable = 5 my_other_variable = "hi"   > my_variable + 2 => 7   > my_variable * 3 => 15   > my_other_variable + " there!" => "hi there!"   > presidents = presidents + ["Washington"] => ["Jefferson", "Madison", "Monroe", "Washington"]   > presidents = presidents - ["Washington"] => ["Jefferson", "Madison", "Washington"] What happens with presidents * 2 ?
  • 22. Type casting duck typing and type casting Quotes are meaningful   > my_favorite_number = '2' => "2"   >  my_favorite_number + 2 TypeError: can't convert Fixnum into String   >  my_favorite_number.to_i + 2 => 4
  • 23. Special Symbols   math operators +       addition (and concatenation) -         subtraction /         division *         multiplication assignment operators   =         assign a value   +=        add, then assign a value   other operators equivalence, non-equivalence, boolean (and, or, etc.)
  • 24. Printing things to the screen puts "Doctor Who"   puts tardis   puts doctors[0] puts doctors["David Tennant"]   puts "My favorite episode is " + best_episode
  • 25. Do something! Store your street address, city, state, and zip code in variables (or even better, a hash!), then print them in the usual format: Joseph Gilbert 160 McCormick Road Charlottesville, VA 22902 address = {'name' => 'Joseph Gilbert', 'street' => '160 McCormick Road', 'city' => 'Charlottesville', 'state' => 'VA', 'zip' => '22902'} puts address['name'] puts address['street'] puts address['city'] + ', ' + address['state'] + ' ' + address['zip']
  • 26. Repeating yourself  > puts presidents[0] Jefferson =>nil > puts presidents[1] Madison => nil > puts presidents[2] Monroe => nil this isn't fun or efficient!
  • 27. Repetition: "iterating" with each > presidents.each do |president|   >      puts president > end Jefferson Madison Monroe => ["Jefferson", "Madison", "Monroe"]
  • 28. .each for hashes states = {"VA" => "Virginia", "MD" => "Maryland"} states.each do |code, state|     puts code.to_s + " is the postal code for " + state.to_s end
  • 29. Do Something, pt. 2 Create a collection of these authors and the year they passed away; print the collection in the following format: Charles Dickens passed away in 1870. Charles Dickens, 1870 William Thackeray, 1863 Anthony Trollope, 1882 Gerard Manley Hopkins, 1889 authors = {"Charles Dickens" => "1870", "William Thackeray" => "1863", "Anthony Trollope" => "1882", "Gerard Manley Hopkins" => "1889"} authors.each do |author, year|   puts author.to_s + " passed away in " + year.to_s end
  • 30. Resources Learn to Program http://pine.fm/LearnToProgram/ Why's Poignant Guide to Ruby http://mislav.uniqpath.com/poignant-guide/ Ruby Documentation http://ruby-doc.org/core/ “ Pick-axe Book ” http://ruby-doc.org/docs/ProgrammingRuby/ Teach Me to Code http://www.teachmetocode.com RubyTu.be Rubylearning.com

Editor's Notes

  • #18: characters and words (strings) sometimes two different things, depending on language
  • #22: "Doing stuff" usually doesn't change the variables used.  You'd need to use write things like  new_variable = my_variable + 2 or my_variable = my_variable + 2  to use this value later.
  • #26: address = {'name' => 'Joseph Gilbert', 'street' => '160 McCormick Road', 'city' => 'Charlottesville', 'state' => 'VA', 'zip' => '22902'} puts address['name'] puts address['street'] puts address['city'] + ', ' + address['state'] + ' ' + address['zip']
  • #30: authors = {"Charles Dickens" => "1870", "William Thackeray" => "1863", "Anthony Trollope" => "1882", "Gerard Manley Hopkins" => "1889"} authors.each do |author, year|   puts author.to_s + " passed away in " + year.to_s end authors.each do |author, year|   puts author.to_s + " passed away in " + year.to_s endauthors = {"Charles Dickens" => "1870", "William Thackeray" => "1863", "Anthony Trollope" => "1882", "Gerard Manley Hopkins" => "1889"} authors.each do |author, year|   puts author.to_s + " passed away in " + year.to_s endauthors = {"Charles Dickens" => "1870", "William Thackeray" => "1863", "Anthony Trollope" => "1882", "Gerard Manley Hopkins" => "1889"} authors.each do |author, year|   puts author.to_s + " passed away in " + year.to_s endauthors = {"Charles Dickens" => "1870", "William Thackeray" => "1863", "Anthony Trollope" => "1882", "Gerard Manley Hopkins" => "1889"} authors.each do |author, year|   puts author.to_s + " passed away in " + year.to_s end