jonathan lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • zen and the art of...

68
OSCON 2009 Jonathan Lloyd (majrmovies)

Upload: others

Post on 10-Oct-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

OSCON 2009Jonathan Lloyd (majrmovies)

Page 2: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Who am I?

• I have been programming Perl for ~ 4 years

• I work for a small business (~ 30 employees) in Irvine, CA that does e-commerce and distribution.

• I do primarily web programming with Perl, mod_perl2, CGI and JavaScript. Including lots of web service communications like SOAP, XML, and JSON.

Page 3: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

The Presentations• Perl 6 Update & Perl 6: What? Why? How? - Larry Wall & Damian Conway

• Distributed Applications with CouchDB - J Chris Anderson

• Open Source Language Roundtable

• Transparent Sharing of Complex Data with YAML - Ingy döt Net

• Zen and the Art of Abstraction Maintenance - Alex Martelli

• Gearman: Building a Distributed Platform - Eric Day and Brian Aker

• 7 Principles of Better API Design - Damian Conway

• Situation Normal, Everything Must Change - Simon Wardley

Page 4: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

The Presentations• Perl 6 Update & Perl 6: What? Why? How? - Larry Wall & Damian Conway

• Distributed Applications with CouchDB - J Chris Anderson

• Open Source Language Roundtable

• Transparent Sharing of Complex Data with YAML - Ingy döt Net

• Zen and the Art of Abstraction Maintenance - Alex Martelli

• Gearman: Building a Distributed Platform - Eric Day and Brian Aker

• 7 Principles of Better API Design - Damian Conway

• Situation Normal, Everything Must Change - Simon Wardley

Page 5: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

The Presentations• Perl 6 Update & Perl 6: What? Why? How? - Larry Wall & Damian Conway

• Distributed Applications with CouchDB - J Chris Anderson

• Open Source Language Roundtable

• Transparent Sharing of Complex Data with YAML - Ingy döt Net

• Zen and the Art of Abstraction Maintenance - Alex Martelli

• Gearman: Building a Distributed Platform - Eric Day and Brian Aker

• 7 Principles of Better API Design - Damian Conway

• Situation Normal, Everything Must Change - Simon Wardley

Disclaimer: I am not these people. I just listened to these people.

Page 6: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

The Presentations• Perl 6 Update & Perl 6: What? Why? How? - Larry Wall & Damian Conway

• Distributed Applications with CouchDB - J Chris Anderson

• Open Source Language Roundtable

• Transparent Sharing of Complex Data with YAML - Ingy döt Net

• Zen and the Art of Abstraction Maintenance - Alex Martelli

• Gearman: Building a Distributed Platform - Eric Day and Brian Aker

• 7 Principles of Better API Design - Damian Conway

• Situation Normal, Everything Must Change - Simon Wardley

Disclaimer: I am not these people. I just listened to these people. And stole some of their materials for this presentation.

Page 7: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

The Presentations• Perl 6 Update & Perl 6: What? Why? How? - Larry Wall & Damian Conway

• Distributed Applications with CouchDB - J Chris Anderson

• Open Source Language Roundtable

• Transparent Sharing of Complex Data with YAML - Ingy döt Net

• Zen and the Art of Abstraction Maintenance - Alex Martelli

• Prism, Bringing Web Applications to the Desktop - Matthew Gertner

• Gearman: Building a Distributed Platform - Eric Day and Brian Aker

• 7 Principles of Better API Design - Damian Conway

• Situation Normal, Everything Must Change - Simon Wardley

Page 8: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Perl: The Metrics

• Perl is 21 year’s old.

8

Page 9: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Perl: The Metrics

• Perl is 21 year’s old.

• Perl 5 is 14 years old.

Page 10: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Perl: The Metrics

• Perl is 21 year’s old.

• Perl 5 is 14 years old.

• Larry Wall is 55 years old.

Page 11: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Perl: The Metrics

• Perl is 21 year’s old.

• Perl 5 is 14 years old.

• Larry Wall is 55 years old.

• The idea of Perl 6 was introduced to the community on October 24th, 2000.

Page 12: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Perl 6: Why?

• We have 20 years of experience with the language.

Page 13: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Perl 6: Why?

• We have 20 years of experience with the language.

• We have a much better Larry.

Page 14: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Perl 6: Why?

• We have 20 years of experience with the language.

• We have a much better Larry.

• We have Damian Conway

Page 15: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Perl 6: Why?

• We have 20 years of experience with the language.

• We have a much better Larry.

• We have Damian Conway

• “It’s time to steal all the good ideas from other languages.”

Page 16: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Perl 6: Why?

• We have 20 years of experience with the language.

• We have a much better Larry.

• We have Damian Conway

• “It’s time to steal all the good ideas from other languages.”

Page 17: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Perl 6: Why?

• We have 20 years of experience with the language.

• We have a much better Larry.

• We have Damian Conway

• “It’s time to steal all the good ideas from other languages.”

Page 18: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Perl 6: Seriously?Comments are inline-able

my $x# This is a comment to the end of the line

= 1;

use v5;

use v6;my $y #{ Need a better var name!} = 2;

Page 19: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Perl 6: Seriously?String lists

# throw some strings in to an arraymy @names = qw(Jonathan David Lloyd);

# throw variables and strings -- no more qw!my @meals = ($breakfast, ‘Lunch’, ‘Dinner’);

use v5;

use v6;# The qw list constructor gets prettiermy @names = < Jonathan David Lloyd >;

# Interpolates variables or stringsmy @meals = << $breakfast Lunch Dinner >>;

my @names = <<

Jonathan # This is my first name>>

Page 20: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Perl 6: Seriously?Everything is an object

say keys %hash;say values %hash;

join(‘-’, $year, $month, $day);for (sort keys %hash) { say; }

use v5;

use v6;%hash.keys.say;

%hash.keys.sort.join(‘ | ‘);%hash.keys.reverse.join(‘-’).say;

.say for %hash.keys.sort;

Page 21: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Perl 6: Seriously?Variable declarations

my $variable = “String”;my $variable = 10;my $variable = new CGI;

my @array = (‘String’, 10, $object);

use v5;

use v6;my Str $variable = ‘a scalar’;my Int $variable = 10;

my Str @array = < Jonathan David Lloyd >;my Int @array = 1..10;

Page 22: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Perl 6: Seriously?Junctions

my @odds = qw(1 3 5 7 9);my @nums = qw(0 1 2 3 4 5 6 7 8 9);

for my $num (@nums) {if (grep $_ eq $num, @odds) {say “$num is odd”; ...

use v5;

use v6;for (@nums) {say “$_ is odd” if $_ == any (@odds);say “$_ in even” if $_ == none (@odds);

}

# The comparisons are performed in parallel!

Page 23: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Perl 6: Seriously?1. Strictures and

warnings on by default2. Comments are inline-

able3. Big revamp of POD4. Identifiers5. String lists6. Sigils sanitized7. Everything is an object8. Variable declarations9. State variables10.Constants11.Lists12.Generators13.Pairs14.Smarter string

interpolations15.Heredocs fixed16.Junctions17.Array indexing

18.Multidimensional arrays

19.Hash features20.Data-preserving hash

transformations21.Operator revamp22.DWIMier comparisons23.DWIMier matching24.Switch statements and

switch loops25.Defaulting operators26.IO27.Sort has been fixed28.Revamped loops29.Nested postfix control

statements30.Error variables31.Subroutines32.Named parameters

33.Parameter types and return types

34.Captures35.“Slurpy” parameters36.The MAIN subroutine37.Classes38.Inheritance39.Constructors and

destructors40.Multiple dispatch41.Roles42.Regular Expressions43.Named regexes44.Match-time variable

interpolation45.Named regexes and

grammars

Page 24: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Perl 6: How?

• Download “Rakudo”

• It won’t hurt your current distribution/system

• Use modules built for Perl5 that are similar to Perl6::*

Page 25: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

The Presentations• Perl 6 Update & Perl 6: What? Why? How? - Larry Wall & Damian Conway

• Distributed Applications with CouchDB - J Chris Anderson

• Open Source Language Roundtable

• Transparent Sharing of Complex Data with YAML - Ingy döt Net

• Zen and the Art of Abstraction Maintenance - Alex Martelli

• Prism, Bringing Web Applications to the Desktop - Matthew Gertner

• Gearman: Building a Distributed Platform - Eric Day and Brian Aker

• 7 Principles of Better API Design - Damian Conway

• Situation Normal, Everything Must Change - Simon Wardley

Page 26: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Distributed Applications with CouchDB

• Document-oriented, not relational database.

• Schema-Free (JSON)

• RESTful HTTP API

• JavaScript Powered Map/Reduce Views

• N-Master Replication, Highly Concurrent, Robust Storage, Buzz word, Buzz word, Buzz word.

Page 27: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Distributed Applications with CouchDB

• Documents in the Real World

• Bills, letters, tax forms ..

• Same type != same structure

• Can be out of date

• No references

• Natural Data Behavior

• Document-oriented, not relational database.

Page 28: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Distributed Applications with CouchDB

{

"_id": "BCCD12CBB","_rev": "3-AB764C",

"type": "person","name": "Darth Vader","age": 63,"headware":["Helmet", "Sombrero"],"dark_side": true

}

• Schema-Free (JSON)

• Unique ID for each document

• Data structure can change on a per-document basis

• Limited only by the data structures available in JSON

Page 29: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Distributed Applications with CouchDB

Create HTTP PUT /db/mydocidRead HTTP GET /db/mydocidUpdate HTTP PUT /db/mydocidDelete HTTP DELETE /db/mydocid

• RESTful HTTP API

JSON

Page 30: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Distributed Applications with CouchDB

• RESTful HTTP API

Page 31: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Distributed Applications with CouchDB

• Javascript-Powered Map/Reduce Functions

MapDocuments

Reduce

Page 32: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Distributed Applications with CouchDB

• N-Master Replication, Highly Concurrent, Robust Storage ..

-d '{"source":"http://server/db","target":"db-replica"

}’

Pull

-d '{"source":"db-replica","target":"http://server/db"

}'

Push

-d '{"source":"http://server-one/db","target":"http://server-two/db"

}'

Remotescp

JSONJSON

Server

Page 33: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

• Terrific Idea

• Leverage Apache for its strength -- distributing documents

• Use client-side JavaScript to manage and display documents

• Replication across multiple servers, or being downloadable to offline applications is very simple

Pros

Cons

Distributed Applications with CouchDB

• Security (HTTP DELETE /db -- Oops!)

• Using Perl would require a DBD::CouchDB plugin for sanity

• Writing queries/views is not practical in a small shop

• No direct interface -- runs as a daemon that is simply killed

• Very JavaScript oriented

Page 34: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

The Presentations• Perl 6 Update & Perl 6: What? Why? How? - Larry Wall & Damian Conway

• Distributed Applications with CouchDB - J Chris Anderson

• Open Source Language Roundtable

• Transparent Sharing of Complex Data with YAML - Ingy döt Net

• Zen and the Art of Abstraction Maintenance - Alex Martelli

• Prism, Bringing Web Applications to the Desktop - Matthew Gertner

• Gearman: Building a Distributed Platform - Eric Day and Brian Aker

• 7 Principles of Better API Design - Damian Conway

• Situation Normal, Everything Must Change - Simon Wardley

Page 35: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Open Source Language RoundtableJava: Rod Johnson (SpringSource)Perl: Jim Brandt (Perl Foundation)PHP: Laura Thomason (Mozilla)Python: Alex Martelli (Google)Ruby: Brian Ford (Engine Yard)

• Most dynamic programming languages are inherently the same. Don’t hate.

• Perl is the best for shell scripting

• JavaScript is a dynamic language completely undervalued, but hugely important in web development (i.e. Google)

• Runs on the client-side

• AJAX has enabled more dynamic communication with the server

• Frameworks like Prototype, Dojo, Moo Tools, and jQuery make it easy

Page 36: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

The Presentations• Perl 6 Update & Perl 6: What? Why? How? - Larry Wall & Damian Conway

• Distributed Applications with CouchDB - J Chris Anderson

• Open Source Language Roundtable

• Transparent Sharing of Complex Data with YAML - Ingy döt Net

• Zen and the Art of Abstraction Maintenance - Alex Martelli

• Prism, Bringing Web Applications to the Desktop - Matthew Gertner

• Gearman: Building a Distributed Platform - Eric Day and Brian Aker

• 7 Principles of Better API Design - Damian Conway

• Situation Normal, Everything Must Change - Simon Wardley

Page 37: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Transparent Sharing of Complex Data with YAMLby Ingy döt Net (Hackers, Inc)

• YAML (YAML Ain't Markup Language)

• JSON == YAML

• YAML =!~ JSON

• YAML can store objects

• YAML can be streamed

• YAML has implementations in 8 different languages -- more to come ...

---name: ingyage: oldweight: heavy# I should comment that I also# like pink, but don't tell anybody.favorite colors:

- red- green- blue

---- Clark Evans- Oren Ben-Kiki- Ingy döt Net...

Page 38: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

The Presentations• Perl 6 Update & Perl 6: What? Why? How? - Larry Wall & Damian Conway

• Distributed Applications with CouchDB - J Chris Anderson

• Open Source Language Roundtable

• Transparent Sharing of Complex Data with YAML - Ingy döt Net

• Zen and the Art of Abstraction Maintenance - Alex Martelli

• Prism, Bringing Web Applications to the Desktop - Matthew Gertner

• Gearman: Building a Distributed Platform - Eric Day and Brian Aker

• 7 Principles of Better API Design - Damian Conway

• Situation Normal, Everything Must Change - Simon Wardley

Page 39: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Zen and the Art of Abstraction Maintenanceby Alex Martelli (Google)

• Everything is built on something.

• You build layers of abstraction (Perl modules)

• All layers of abstraction leak.

• Understand the layers surrounding your code.

Page 40: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

The Presentations• Perl 6 Update & Perl 6: What? Why? How? - Larry Wall & Damian Conway

• Distributed Applications with CouchDB - J Chris Anderson

• Open Source Language Roundtable

• Transparent Sharing of Complex Data with YAML - Ingy döt Net

• Zen and the Art of Abstraction Maintenance - Alex Martelli

• Prism, Bringing Web Applications to the Desktop - Matthew Gertner

• Gearman: Building a Distributed Platform - Eric Day and Brian Aker

• 7 Principles of Better API Design - Damian Conway

• Situation Normal, Everything Must Change - Simon Wardley

Page 41: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Bringing Web Applications to the Desktopby Matthew Gertner

• The browser wasn’t designed for running applications -- but it is being used that way

• HTML5 is furthering this effort

• Offline Operation

• Local Data

• Worker Threads

• Prism allows you to spin a process (separate from the browser) and interact with the OS using JavaScript calls to the API

Page 42: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

The Presentations• Perl 6 Update & Perl 6: What? Why? How? - Larry Wall & Damian Conway

• Distributed Applications with CouchDB - J Chris Anderson

• Open Source Language Roundtable

• Transparent Sharing of Complex Data with YAML - Ingy döt Net

• Zen and the Art of Abstraction Maintenance - Alex Martelli

• Prism, Bringing Web Applications to the Desktop - Matthew Gertner

• Gearman: Building a Distributed Platform - Eric Day and Brian Aker

• 7 Principles of Better API Design - Damian Conway

• Situation Normal, Everything Must Change - Simon Wardley

Page 43: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Build Your Own Distributed Platform in 3 Hours

• Gearman provides a distributed application framework

• Clients - Create jobs to be run and sends them to a job server.

• Workers - Register with a job server and grab jobs to run.

• Job Server - Coordinate the assignment from the client to the works, handle restarts.

• “Gearman, like managers, assign the tasks but do none of the work.”

Page 44: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Build Your Own Distributed Platform in 3 Hours

• Not everything needs immediate attention

• E-mail notifications

• Certain DB updates

• RSS indexing

• Search indexing Image Processing

Page 45: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Build Your Own Distributed Platform in 3 Hours

• Background tasks

• Foreground tasks

• Asynchronous tasks

• No single point of failure (multiple job servers, multiple workers)

• Workers can be specific to certain jobs

Page 46: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Build Your Own Distributed Platform in 3 Hours

• Written in C

• Perl API on CPAN (Gearman::XS)

• Command line tool

• Multi-language - mix client and workers

• Synchronous and Asynchronous queues

• Runs as a daemon (gearmand)

• Developing improved monitoring (statistics, configuration management, etc.)

• Only accepts a single string / file handle from Client to Worker

• Failure by worker -- not enough configuration (would rather it be function specific)

Pros Cons

Page 47: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

The Presentations• Perl 6 Update & Perl 6: What? Why? How? - Larry Wall & Damian Conway

• Distributed Applications with CouchDB - J Chris Anderson

• Open Source Language Roundtable

• Transparent Sharing of Complex Data with YAML - Ingy döt Net

• Zen and the Art of Abstraction Maintenance - Alex Martelli

• Prism, Bringing Web Applications to the Desktop - Matthew Gertner

• Gearman: Building a Distributed Platform - Eric Day and Brian Aker

• 7 Principles of Better API Design - Damian Conway

• Situation Normal, Everything Must Change - Simon Wardley

Page 48: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

7 Principles of Better API Designby Damian Conway

1.Do one thing really well

# read a file in to a variablemy $text = do { local (@ARGV, $/) = filename; <> };

use Perl6::Slurp;

my $text = slurp $fh;my $text2 = slurp ‘filename’;

Page 49: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

7 Principles of Better API Designby Damian Conway

2.Design by coding (work backwards)

# regex for floating point integermy $input =~ /([+-]?(?:\d+[.]?\d*|[.]\d+(?:[eE][+-]?\d+)?)/;

use Regexp::Common;my $input =~ /($RE{num}{real})/;my $input2 =~ /($RE{num}{int})/;my $input3 =~ /($RE{num})/;

Page 50: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

7 Principles of Better API Designby Damian Conway

3.Evolve by Subtraction

use IO::Prompt;while (prompt “next: “, -bool, -chomped) { print “You said ‘$_’\n”;}

while (prompt “next: “) { # autodetect, autochomp print “You said ‘$_’\n”;}

Page 51: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

7 Principles of Better API Designby Damian Conway

4.Declarative beats imperative

use Getopt::Euclid;

for my $x (0 .. $ARGV{-size}{h} - 1) { for my $y (0 .. $ARGV{-size}{w} - 1) { do_something_with($x, $y); }}

__END__

= item -s[ize]=<h>x<w>

Specify size of simulation

=for Euclid:h.type: int > 0h.default: 24w.type: int >= 10w.default: 80

Page 52: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

7 Principles of Better API Designby Damian Conway

5.Preserve the metadata

use Config::Std;

read_config $file_name => my %config;# update %config herewrite_config %config => $file_name;

read_config $file_name => my %config;# update %config herewrite_config %config;

bash> cd /home/jlloydbash> lsbash> cd docs/bash> lsbash> cd modules/bash> lsYou have typed the commands “cd [path] ls” 3 times, would you like to create an alias? [y|n]

Page 53: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

7 Principles of Better API Designby Damian Conway

6.Leverage the familiar

use Log::Log4perl;Log::Log4perl->init($log_config_file);

my $logger = Log::Log4perl->get_logger(__PACKAGE__);

$logger->debug(‘this is a debug message’);$logger->info(‘this is an info message’);$logger->warn(‘this is a warning message’);$logger->error(‘this is an error message’);$logger->fatal(‘this is a fatal message’);

use Log::StdLog { file => $log_file };print STDLOG debug => ‘this is a debug message’;print STDLOG info => ‘this is an info message’;print STDLOG warn => ‘this is a warning message’;print STDLOG error => ‘this is an error message’;print STDLOG fatal => ‘this is a fatal message’;

Page 54: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

7 Principles of Better API Designby Damian Conway

7.The best code is no code at all

my $obj = MyClass->new(‘data’);print $obj;

MyClass=HASH[0x12a8f2];

my $obj = MyClass->new(‘data’);

use Object::Dumper;print $obj;

Page 55: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

The Presentations• Perl 6 Update & Perl 6: What? Why? How? - Larry Wall & Damian Conway

• Distributed Applications with CouchDB - J Chris Anderson

• Open Source Language Roundtable

• Transparent Sharing of Complex Data with YAML - Ingy döt Net

• Zen and the Art of Abstraction Maintenance - Alex Martelli

• Prism, Bringing Web Applications to the Desktop - Matthew Gertner

• Gearman: Building a Distributed Platform - Eric Day and Brian Aker

• 7 Principles of Better API Design - Damian Conway

• Situation Normal, Everything Must Change - Simon Wardley

Page 56: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Situation Normal, Everything Must Changeby Simon Wardley

• All good innovations undergo a process of commoditization

Page 57: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Situation Normal, Everything Must Changeby Simon Wardley

• All good innovations undergo a process of commoditization (i.e. Electricity)

Page 58: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Situation Normal, Everything Must Changeby Simon Wardley

• All good innovations undergo a process of commoditization (i.e. Electricity)

• This trend can be mapped and seen in the market

Page 59: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Situation Normal, Everything Must Changeby Simon Wardley

• All good innovations undergo a process of commoditization (i.e. Electricity)

• This trend can be mapped and seen in the market (i.e. CRM)

Page 60: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Situation Normal, Everything Must Changeby Simon Wardley

• All good innovations undergo a process of commoditization (i.e. Electricity)

• This trend can be mapped and seen in the market (i.e. CRM)

Page 61: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Situation Normal, Everything Must Changeby Simon Wardley

• All good innovations undergo a process of commoditization (i.e. Electricity)

• This trend can be mapped and seen in the market (i.e. CRM)

Page 62: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Situation Normal, Everything Must Changeby Simon Wardley

• All good innovations undergo a process of commoditization (i.e. Electricity)

• This trend can be mapped and seen in the market (i.e. CRM)

Page 63: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Situation Normal, Everything Must Changeby Simon Wardley

• All good innovations undergo a process of commoditization (i.e. Electricity)

• This trend can be mapped and seen in the market (i.e. CRM)

Page 64: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Situation Normal, Everything Must Changeby Simon Wardley

• All good innovations undergo a process of commoditization (i.e. Electricity)

• This trend can be mapped and seen in the market (i.e. CRM)

Page 65: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Situation Normal, Everything Must Changeby Simon Wardley

• All good innovations undergo a process of commoditization (i.e. Electricity)

• This trend can be mapped and seen in the market (i.e. CRM)

• Competitive disadvantage to companies that fail to follow the market

Page 66: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Situation Normal, Everything Must Changeby Simon Wardley

• All good innovations undergo a process of commoditization (i.e. Electricity)

• This trend can be mapped and seen in the market (i.e. CRM)

• Competitive disadvantage to companies that fail to follow the market

Page 67: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Situation Normal, Everything Must Changeby Simon Wardley

• Economies of scale

• Pay per use

• Speed to market

• Focus on core

• Price competition

• Not “locked-in”

• Secondary sourcing

Pros

• Management of data/applications (different way of thinking/designing)

• Trust / Security

Cons

Page 68: Jonathan Lloyd (majrmovies)sandiego.pm.org/presentations/oscon_2009.pdf · • Zen and the Art of Abstraction Maintenance - Alex Martelli • Gearman: Building a Distributed Platform

Thanks!Questions?