10/22/08 1
Scripting Languages
Kathleen Fisher
What are scripting languages?
- Unix shells: sh, ksh, bash
– job control
- Perl
– Slashdot, bioinformatics, financial data processing, cgi
- Python
– System administration at Google – BitTorrent file sharing system
- Ruby
– Various blogs, data processing applications
- PHP
– Yahoo web site
- JavaScript
– Google maps
“The glue that holds the web together”
Characteristics
- Interpreted (no compilation step)
- Dynamically typed
- High-level model of underlying machine
- Garbage collected
- Don’t have to declare variables
Designed to support “quick programming”
Design philosophy
Often people, especially computer engineers, focus on the machines. They think, "By doing this, the machine will run faster. By doing this, the machine will run more effectively. By doing this, the machine will something something something." They are focusing on the machines. But in fact we need to focus on humans, on how humans care about doing programming or operating the application of the
- machines. We are the masters. They are the slaves.
Yukihiro “Matz” Matsumoto Creator of Ruby
Demo: Getting the homework
- What if I don’t want to go to the web site
to see if I have cs242 homework?
- Write a script to check for me!
> hwk http://www.stanford.edu/class/cs242/handouts/index.html Hwk 1 was due on Wednesday, October 05. Hwk 2 was due on Wednesday, October 12. Hwk 3 is due on Wednesday, October 19. #!/sw/bin/ruby require 'uri'; require 'net/http' uri= URI.parse(ARGV[0]) h=Net::HTTP.new(uri.host,80) resp,data = h.get(uri.path) hwk = {} if resp.message == "OK" data.scan(/Homework (\d*) \(due (\d*)\/(\d*)\)/)\ {|x,y,z| hwk[x] = Time.local(2005,y,z)} end hwk.each{| assignment, duedate| if duedate < (Time.now - 60 * 60 * 24) puts "Hwk #{assignment} was due on #{duedate.strftime("%A, %B %d")}." else puts "Hwk #{assignment} is due on #{duedate.strftime("%A, %B %d")}." end }