stevan's OSCON slides
[gitmo/moose-website.git] / hosted-presentations / 2007 / nothingmuch-YAPC-EU / Spork.slides~
CommitLineData
720accfe 1----
2presentation_topic: meta meta meta meta
3presentation_title: Object Meta Programming
4presentation_place: YAPC::EU::2007
5presentation_date: Aug 29, 2007
6----
7= HAI FRENDS
8{image:http://personal.inet.fi/taide/junttila/desert/2002/promopi.jpg}
9== My name is Yuval
10----
11= Meta Programming
12{image: http://www.prints.co.nz/Merchant2/graphics/00000001/7104_Squares_with_Concentric_Circles_Kandinsky_Wassily.jpg}
13----
14= Introduction
15{image: http://www.room101.net/door.jpg}
16+* Meta programming
17+* writing /code/ which /outputs/ or /manipulates/ /code/
18----
19= Many forms
20{image: http://www.internationalhero.co.uk/m/manimal.jpg}
21+* string `eval`
22+* `%::`
23+* closure generators
24+* macros
25+* real macros
26+* compilers
27----
28= Many forms
29{image: http://www.junjan.org/weblog/images/Flying_Spaghetti_Monster-thumb.jpg}
30+* Home grown snippets
31+* Home grown packages
32+* Stuff on the CPAN (e.g. `Class::Accessor`, `Code::Perl`)
33+* Large systems (`Template::Toolkit`)
34----
35= Summary
36{image: http://www.evc.org/programs/TD_web_projects/westside_amy_2003_1/teen_times/peerpressure/images/16_peer_pressure_smoking.gif}
37* You should already know it
38* You probably do it
39+* That's the intended audience anyway ;-)
40----
41= Object Meta Programming
42----
43= Object Meta Programming
44+* Code that outputs or manipulates /object oriented code/
45+* Often written in OO
46----
47= Simple Examples
48{image: http://www.wildoats.com/content/ApplePieSlice.jpg}
49+* `Class::Accessor`, `Class::InsideOut`
50+** Generates accessor methods
51+* `Class::Prototyped`
52+** Prototype object support in Perl
53+* Lots of stuff on the CPAN
54----
55= Modeling OO
56{image: http://www.nordicsubs.co.uk/covers/vogue.jpg}
57+* High level object meta programming
58+** The current trend
59+** The picture illustrates an object modelling with class =)
60+** Seriously though...
61----
62= Modeling OO
63{image: http://www.nordicsubs.co.uk/covers/vogue.jpg}
64* High level object meta programming
65* What is a class?
66+.vim
67filetype: perl6
68
69 class Class {
70 has @isa;
71 has %methods;
72 has %attributes;
73
74 ...
75 }
76.vim
77----
78= Modeling OO
79{image: http://www.nordicsubs.co.uk/covers/vogue.jpg}
80+* Implementing OO
81+** In OO
82+* Meta objects:
83+** Class
84+** Method
85+** Attribute
86----
87= Example class
88
89.vim
90filetype: perl6
91
92 class Point {
93 has $x;
94 has $y;
95
96 method distance_to { ... }
97 }
98.vim
99----
100= Modeled with objects
101
102.vim
103filetype: perl
104
105 Class->new(
106 attributes => [
107 Attribute->new( name => '$x' ),
108 Attribute->new( name => '$y' ),
109 ],
110 methods => [
111 Method->new(
112 name => "distance_to",
113 definition => sub { ... }
114 ),
115 ],
116 );
117.vim
118----
119= Metamodel Services
120{image: http://www1.istockphoto.com/file_thumbview_approve/944779/2/istockphoto_944779_reception_bell.jpg}
121+* Form
122+** Introspection/Reflection
123+* Function
124+** Class generation
125+** Class transformation
126+* Pattern packaging
127----
128= Case Study
129{image: http://www.iinteractive.com/moose/images/a_moose.gif}
130== Moose
131+* A deep meta object system
132+* 4 layers deep
133+** Syntactic sugar
134+** Custom metaclasses
135+** Class::MOP
136+** Perl's native OO
137----
138= Perl's native OO
139{image: http://www.mileslight.com/images/perl-camel.gif}
140+* Minimalistic
141+** Class = Package = Symbol table hash
142** Inheritence tree embedded in `@ISA` entry
143** `bless` links data to a class
144** `->`
145+* Insanely flexible
146+* Pretty klunky
147+* Written in C (not very accessible)
148----
149= Class::MOP
150{image: http://nothingmuch.woobling.org/MOP.jpg}
151+* port of CLOS, more or less
152+* MOP = Meta Object Protocol
153----
154= Class::MOP
155{image: http://nothingmuch.woobling.org/MOP.jpg}
156+* Model
157+** `Class::MOP::Class`
158** `Class::MOP::Method`
159** `Class::MOP::Attribute`
160+* Easy interface
161+** Introspection
162+** Transformation
163----
164= Class::MOP
165{image: http://nothingmuch.woobling.org/MOP.jpg}
166+* Can "parse" packages into meta objects
167+* Modifying the objects writes back to packages
168+* Code generation
169+** Accessors from attributes
170+** Constructor from attributes
171+** Method modifiers
172----
173= Moose's custom metaclasses
174{image: http://www.iinteractive.com/moose/images/a_moose.gif}
175+* Subclasses of `Class::MOP::Class` et al
176+* More fun features
177+** Roles
178+** `BUILD` etc a la Perl 6
179+* Type constraints
180----
181= Moose sugar layer
182{image: http://nothingmuch.woobling.org/sugar.jpg}
183+* Pseudo-declarative syntax
184+* Maps to metaclass manipulations
185+.vim
186 has foo => ( is => "rw" );
187.vim
188+* becomes
189+.vim
190 $metaclass->add_attribute(
191 Moose::Meta::Attribute->new(
192 foo => ( is => "rw" ),
193 )
194 );
195.vim
196----
197= Moose vs. Class::Accessor
198{image: http://nothingmuch.woobling.org/p-seal-at-toronto-zoo.jpg}
199+* All that bloat just for the `has` syntax?
200+* *NO!*
201+* Pattern packaging
202----
203= MooseX::
204{image: http://www.threadpit.com/photos/all_styles/small/401.jpg}
205+* Packaged meta code
206+* Pretty clean
207+* Mostly composable
208----
209= MooseX::
210{image: http://www.threadpit.com/photos/all_styles/small/401.jpg}
211+* `MooseX::Storage`
212+** Customizable serialization through metaprogramming
213+* `MooseX::AttributeHelpers`
214+** Additional methods for collection type attributes
215+* `MooseX::Getopt`
216+** Additional constructor compiles attributes into a `Getopt` spec
217+* `MooseX::IOC`
218+** Inversion of control integrated into the object system
219----
220= The point of Moose
221{image: http://nothingmuch.woobling.org/cute_moose.jpg}
222+* OO is less tedious
223+* Helps you write meta code
224+** Good APIs promote clean code
225+** Easier to build on existing base
226+** Conventions and structure let you play well with others (`MooseX::`)
227+** Introspectable & tranformable metamodel
228----
229= Another Case Study
230{image: http://www.rockies-ice.com/images/MainHeaderPic_5.gif}
231== ORMs
232+* Are *HARD*
233+* Not even fun like the picture
234----
235= ORMs
236{image: http://www.agiledata.org/images/legacyDataSources.jpg}
237+* Modeling
238+** Tables <-> Classes
239+** Fields <-> Attributes
240+* Code Generation
241+** SQL
242+** Accessors
243+** Relationship fetchers
244----
245= `Class::DBI`
246+* Meta code is in the base class
247+* No clear schema modelling
248+* No separation between regular & meta code
249+* Lots of hacks
250+* Don't go there
251----
252= `DBIx::Class`
253+* Meta enlightened
254+** Schema objects fully model the SQL side
255+** ResultSource etc partially model the OO side
256+** Components for everything
257----
258= `DBIx::Class`
259+* Meta code:
260+** Proxy objects
261+** Accessors
262+** Code generation (SQL, Perl)
263----
264= ORM related meta programming
265+* Complex
266+* But manageable
267----
268= Vaporware
269{image: http://www.nzgeothermal.org.nz/geothermal_energy/images/big/b-silencer-water-vapour.jpg}
270----
271= MO
272{image: http://www.nzgeothermal.org.nz/geothermal_energy/images/big/b-silencer-water-vapour.jpg}
273+* My baby
274+* Moose spinoff
275+** Stevan says it's Moose 2.0's
276+* Perl 5 & Haskell (in pugs)
277----
278= MO Sucks
279{image: http://www5f.biglobe.ne.jp/~tantan-kids/I.syokuzai/lollypop.jpg}
280+* Experimental code
281+* Boring parts messy or unwritten
282+* Lacking integration, sugar layer
283+** mst promised to help ;-)
284+* Some parts slow as $*!&%
285----
286= MO Rocks
287{image: http://nothingmuch.woobling.org/rocks.jpg}
288+* Purely functional
289+* Very suited for meta transformations
290+* Fine grained control over everything
291+* Can introduce entirely new conceptions of OO
292----
293= MO Architechture
294{image: http://www.narrabay.com/images/engineering_large.jpg}
295+* Modeling layer
296+** Corresponds to compilation
297+* Responder layer
298+** Corresponds to runtime
299----
300= MO Architechture
301{image: http://www.narrabay.com/images/engineering_large.jpg}
302+* Compiler/sugar layer creates the modeling layer
303+** Class objects are constructed, with all the details
304+** No meta calculations happen yet
305+* Modeling layer is "compiled" into responder layer
306+** Can be done on demand or upfront
307+* Obscurely named objects
308+** Bear with me
309----
310= "Concepts"
311{image: http://gallery.hd.org/_exhibits/light/_more2003/_more05/light-bulb-glowing-filament-light-blue-uncropped-lores-3-AHD.jpg}
312+* The purest form of OO is prototypes
313+** prototype OO can implement class OO
314+* Concepts are new ways to express objects
315+* A class is a concept
316+* A role is a concept
317----
318= "Responder Interfaces"
319{image: http://www.cs.usfca.edu/~parrt/course/652/lectures/images/vtable.jpg}
320+* `$ri->dispatch( $responder, $invocation )`
321+* Generated from concepts
322+* Abstract VTable
323+** The flattened method hierarchy
324+** ... or something completely different
325+** Performance
326+** Flexibility
327----
328= "Responders"
329{image: http://www.maine.gov/spo/flood/images/fema_seal.gif}
330+* Something that is the subject of invocations
331+** An object instance
332+** A class (class methods)
333+* A simple tuple `( $data, $ri )`
334----
335= "Invocations"
336{image: http://www.mobilenews.sk/wp-content/lg-banana.jpg}
337+* A method call, multimethod, message... whatever
338+** Arguments, too
339+* Whatever an RI will put up with
340+** Extensible calling semantics
341----
342= MO compilation flow
343{image: http://www.daveltd.com/photo/rolls/digital/water/waterfalls/snoqualmie-falls/snoqualmie-falls-flowing-3811-equalized.jpg}
344+* Instantiate a `Class` object
345+** Specify members (methods, attributes)
346+** ... and ancestor classes & roles
347+* Compile class
348+** `my $class_methods_ri = $class->class_interface()`
349+** Instance method RI closed in the constructor, within `$ri`
350+** Purely functional operation
351----
352= RI composition
353{image: http://www.daveltd.com/photo/rolls/digital/water/waterfalls/snoqualmie-falls/snoqualmie-falls-flowing-3811-equalized.jpg}
354+* Compute instance methods and attributes from ancestry
355+* Compute instance slots from attributes
356+* Generate accessors
357+.vim
358 MO::Run::ResponderInterface::MethodTable->new(
359 methods => %methods
360 );
361.vim
362+* Generate constructor
363+.vim
364 sub {
365 my $data = process_params(@_);
366 return box( $data, $instance_ri );
367 }
368.vim
369----
370= Instantiation
371{image: http://d6044171.u109.worldispnetwork.com/images/Creation-hands-L.jpg}
372+* Lookup RI using class name
373+* Dispatch constructor class method
374+* Compose data from params
375+** Slightly complicated
376+* Link data with closed `$instance_ri`
377+** Responder == ( Data, RI )
378+** Like `bless`
379----
380= Method calls
381{image: http://www.w3.org/2005/Talks/05-maxf-xtech/telephone.jpg}
382+* How to talk with your new object?
383+.vim
384 my $ri = $responder->responder_interface;
385
386
387+ my $method = MO::Run::Invocation::Method->new(
388 name => "foo"
389 arguments => \@blah,
390 );
391
392
393+ $ri->dispatch( $responder, $method );
394.vim
395+* Arbitrary responder interfaces also allowed
396+** Doesn't have to be `$responder->responder_interface`
397----
398= OH NOES!!!
399{image: http://www.encyclopediadramatica.com/images/f/f5/Surprise-buttsecks.jpg}
400+* What's wrong with the previous slide?
401+* RIs are objects too!
402+* Need to bootstrap method calls
403+* Runtime must bootstrap low level OO
404+** More on this soon
405----
406= Meta level polymorphism
407{image: http://www.worth1000.com/entries/44500/44790qV87_w.jpg}
408+* An important point
409+** In fact, *the* point of MO
410+* Responder interfaces are polymorphic
411+** Method table, network proxy, whatever
412+* Easy to specialize
413+** Optimizations
414+** Strange features
415+* Easy to mix several OO systems
416+** Just compile to separate RIs
417----
418= MO in Perl 5
419{image: http://www.vetaid.org/assets/shop/card-camel-108.jpg}
420+* Two runtimes
421+* Very different
422+* `MO::Run::Aux` wraps both
423+** Share tests by running with different `%ENV` var
424----
425= Hosted runtime
426{image: http://www.philnjill.com/collections/kubricks/kub_alien/S2Secret.jpg}
427+* Nested object system
428+* Bootstraps with Perl 5
429+** Native Perl OO == Low level, like VM opcodes
430+** Virtualized MO == High Level
431+** Completely separate levels
432+* `$ri->dispatch( $responder, $method )`
433+** not `$responder->$method()`
434+* Full expressiveness
435+* Slow, verbose
436----
437= Native runtime
438{image: http://www.sonofthesouth.net/american-indians/pictures/indian-camp.jpg}
439+* Integrated object system
440+* RIs are compiled into packages
441+** Simple RIs are dissassembled and stuffed into the stash
442+** Complex RIs use `AUTOLOAD`, delegating to the RI meta object
443+* Only named method calls
444+** No arbitrary call concepts
445+** `->` doesn't support anything else
446+* As fast as "regular" Perl OO
447+** Even makes simple, standalone `.pmc`s
448----
449= Perl 5 Runtimes
450+* Native
451+** Usable with regular Perl OO {html:&#9786;}
452+** Lacks arbitrary invocations {html:&#9785;}
453+* Virtualized
454+** Feature complete {html:&#9786;}
455+** Doesn't integrate {html:&#9785;}
456+** Slow {html:&#9785;}
457----
458= Idealized MO toolchain
459{image: http://www.ibiblio.org/wm/paint/auth/botticelli/botticelli.venus.jpg}
460+* Compiler handles modeling
461+** Constructs meta objects at compile time
462+* VM Opcodes support standard RI
463+* Custom RIs are just objects
464+** Bootstrapped using standard runtime objects
465+*** Method table RI
466+*** Named method invocation
467----
468= Perl 6
469{image: http://lolgeeks.com/wp-content/uploads/2007/05/lolgeeks016.jpg}
470+* Perl 6 is the idealized MO toolchain
471+** Can introduce syntax
472+*** Invocation types
473+*** Concept declarations
474+** Implement bootstrap RIs in VM opcodes
475+* Pugs might be using MO
476+** I'm not really sure
477+** It was ported a while ago
478----
479= Introducing new concepts
480+* Roles are the shit
481+* But what about next week's fad?
482+* MO lets you introduce a new concept
483+** Arbitrary at compile time
484+** RI protocol at runtime
485----
486= Example - Prototype Objects
487+* One shared RI
488.vim
489 sub dispatch {
490 my ( $object, $invocation ) = @_;
491
492 my $method = $object->{ $invocation->name };
493
494 $object->$method( $invocation->arguments );
495 }
496.vim
497----
498= Example - Attribute Grammars
499{image: http://nothingmuch.woobling.org/village_people.jpg}
500+* Crazy stuff from the 1970s
501+* Renewed interest in {html:&lambda;} land
502+* Was pretty easy in MO
503----
504= Attribute Grammer Implementation
505{image: http://grammar.ccc.commnet.edu/grammar/images/grammar.gif}
506+* Introduce new concept objects
507+** Attribute Grammar
508+** Attribute Grammer Instance - one per AG per class
509+* Runtime specialized RI
510+** Shadows any RI with additional context sensitive methods
511+* Additional runtime support code
512----
513= MO TODO
514{image: http://www.constructionownerslawblog.com/checklist.jpg}
515+* Write a sugar layer
516+** Make it fun to use
517+* Tests
518+* Refactor the Class objects
519+** Bloated example code
520+** There are some patterns to extract
521+* Self hosting
522----
523= Self Hosting
524+* Easier to maintain MO written in Moose
525+* Need to have clean syntax
526+* Stable `.pmc` compilation
527----
528= Conclusion
529{image: http://www1.istockphoto.com/file_thumbview_approve/2540021/2/istockphoto_2540021_painted_exclamation_mark.jpg}
530+* Meta code is awesome code
531+** Especially my meta code ;-)
532----
533= Conclusion
534{image: http://www1.istockphoto.com/file_thumbview_approve/2540021/2/istockphoto_2540021_painted_exclamation_mark.jpg}
535* Meta code is awesome code
536+** Lets you program in new ways
537+** Helps you take care of your other code
538+* Meta code is important code
539+** It can affect *anything*
540+** Keep it minimalistic, and clearly defined
541+** No spaghetti monsters
542+* Meta code can be simple
543+** Only complicated if you aren't careful
544----
545= BIE FRENDS
546{image: http://www.girlscoutsofblackhawk.org/Portals/0/webphotos/thanks.jpg}