#!/usr/local/bin/ruby presdate = '2005-09-09' author = 'Sam Ruby' company = 'IBM' title = 'Dynamic Languages' subtitle = 'FOSSSL' presentation = <<'EOF' The Case for Dynamic Languages h3. Sam Ruby * "IBM":http://www.ibm.com * "ASF":http://www.apache.org === Case for Dynamic Languages a.k.a. h2(incremental). Reinventing Smalltalk, %(incremental) one decade at a time% === Preface What do these have in common? * BitTorrent * Slashdot * Yahoo! === Hints *(incremental) Michael Tiemann "G++ 40% faster than..." * Bud Siddhisena "less than 8% degredation..." * Anuradha Ratnaweera "shaving seconds off of boot times" === Preface So... what do these have in common? * BitTorrent * Slashdot * -Yahoo-!
Answer: *(incremental) Each are synonymous with scalability * Each are implemented in scripting languages * Macro-performance vs Micro-performance ** Modest hardware running Perl can easily saturate your bandwidth === Comparison Printing out all arguments in uppercase in a few languages:
Perl
print join(' ',map {uc} @ARGV) . "\n";
Python
print ' '.join(map(string.upper,sys.argv[1:]))
Ruby
puts ARGV.map{|arg| arg.upcase}.join(' ')
%(incremental) To minimize distraction: I'm going to focus primarily on one (Ruby)% === Part I h2. Personal retrospective === BASIC
10 print "Enter your name:"
20 input a$
30 print "Hello, "; a$; "!"
=== 1970's * *BASIC* * FORTRAN * COBOL === 1980's * Programming ** JOVIAL ** *370 Assembler* ** Ada ** Pascal * Scripting ** JCL ** CLIST ** REXX === 1990's * Programming ** C ** *C++* ** Java * Scripting ** Shell Scripts ** Batch files ** *REXX* === 2000's * Programming ** *Java* * Scripting ** Perl ** PHP ** *Python* ** Ruby === Other activities * Bean Scripting Framework * ECMAScript (JavaScript) Editor * ECMA CLI working group Conveener * C# working group member * PHP 4.0 + Java * Python on Parrot === 2010's? *(incremental show-first) Anybody's guess **(incremental) here's mine * Languages come and go **(incremental) even COBOL * It is getting harder to differentiate "real" and "scripting" languages ** Re-discovering Smalltalk === Part II h2. Meanwhile... === C derived languages * 1970's: (C) Ken Thompson and Dennis Ritchie * 1980's: (C++) Bjarne Stroustrup * 1990's: (Java) James Gosling * 2000's: (C#) Anders Hejlsberg === SmallTalk * 1970's * Alan Kay, Dan Ingalls, Ted Kaehler, Adele Goldberg * Smalltalk-80 * Extreme Programming === Smalltalk *(incremental show-first) Everything is an object * type-checking is dynamic * message-sending * garbage collection * everything is modifyable * bytecodes * MVC(Model View Controller) * JITs (80's) %(incremental) Source: "wikipedia":http://en.wikipedia.org/wiki/Smalltalk% === Everything is an object
Integer.parseInt("5")
"5".to_i
Math.abs(-5)
-5.abs
=== type-checking is dynamic
def dump(results) results << "abc" results << "xyz" end
Examples of classes that implement "<<" : * File * String * Array === message-sending Facilities enabled by being able to capture messages: * Remote Proxies * Auto Loaders * Decorators * Mock Objects * Builders === everything is modifyable Facilities enabled by being able to modify existing classes: *(incremental) Bug fixes * Features * Application Specific logic on generic (e.g. DOM) classes === MVC(Model View Controller) !mvc.png(Ruby on Rails)! Ruby on Rails === Part V h2. Blocks and Continuations === Block Example
sorted_employees = employees.sort_by %{font-weight:bold}{|e| e.lastname}%
=== Block Usages * Iteration * Sort and comparison * Ensuring post process * Conditionals * Callbacks * Enumerable * Enumerator === Ensuring post process
Scanner sc = new Scanner(new File(args[0])); try { while (sc.hasNextLine()) { System.out.println(sc.nextLine()); } } finally { sc.close(); }
open(ARGV[0]) do |f| f.readlines.each {|line| puts line} end
=== Closure Example
def high_paid_employees(employees, %{font-weight:bold}limit%) employees.collect{|e| e.salary > %{font-weight:bold}limit%} end
=== Part III h2. Incredible shrinking code === Hello World!
class Greeting { public static void main(String args[]) { System.out.println("Hello World!"); } }
Kernel::puts("Hello World!");
=== Hello World!
class Greeting { public static void main(String args[]) { System.out.println("Hello World!"); } }
puts("Hello World!");
=== Hello World!
class Greeting { public static void main(String args[]) { System.out.println("Hello World!"); } }
puts("Hello World!")
=== Hello World!
class Greeting { public static void main(String args[]) { System.out.println("Hello World!"); } }
puts "Hello World!"
=== Beans
class Point { private int x; public int getX() { return this.x; } public void setX(int x) { this.x = x; } }
=== Beans
class Point def x() return @x end def x=(x) @x=x end end
=== Beans
class Point { private float x; public float getX() { return this.x; } public void setX(float x) { this.x = x; } }
class Point def x() @x end def x=(x) @x=x end end
=== Beans
class Point { private float x; public float getX() { return this.x; } public void setX(float x) { this.x = x; } }
class Point attr_accessor :x end
=== Beans
class Point { private float x,y; public float getX() { return this.x; } public void setX(float x) { this.x = x; } public float getY() { return this.y; } public void setY(float y) { this.y = y; } }
class Point attr_accessor :x, :y end
=== Rails
class Entry < ActiveRecord::Base acts_as_tree :order => "updated" validates_presence_of :updated end
=== Exceptions
Scanner sc = new Scanner(new File(args[0])); while (sc.hasNextLine()) { System.out.println(sc.nextLine()); } sc.close();
=== Exceptions
Scanner sc = new Scanner(new File(args[0])); try { while (sc.hasNextLine()) { System.out.println(sc.nextLine()); } } finally { sc.close(); }
=== Exceptions
f = open(ARGV[0]) begin for line in f.readlines puts line end ensure f.close end f.close();
=== Exceptions
open(ARGV[0]) do |f| f.readlines.each {|line| puts line} end
=== Summary Dynamic languages *(incremental) Focus on the task at hand * Executable pseudocode * Enable domain specific grammars * IDEs *available*, not required ** Eclipse plug-ins ** ActiveState ** FreeRide === References * "10 Things Every Java Programmer Should Know About Ruby":http://onestepback.org/articles/10things * "Yield to the Block: The Power of Blocks in Ruby":http://www.rubyist.net/~matz/slides/oscon2005/mgp00001.html * "Programming Ruby":http://www.rubycentral.com/book/ EOF require 'erb' puts "Content-type: text/html\r\n\r" if ENV['QUERY_STRING'] pages=presentation.split /^==+/ pages=pages[ARGV[0].to_i,1] if ARGV[0] pages=pages[$1.to_i,1] if ENV['QUERY_STRING'] =~ /(\d+)/ puts ERB.new(open('s5.erb').read).run