SlideShare a Scribd company logo
1 of 40
Download to read offline
Copyright © 2006 David A. Golden
Eversion 101
An Introduction to Inside-Out Objects
David Golden
dagolden@cpan.org
June 26, 2006
YAPC::NA
Image source: Michal Kosmulski
1
Copyright © 2006 David A. Golden
An introduction to the inside-out technique
Inside-out objects first presented by Dutch Perl hacker Abigail in 2002
– Spring 2002 – First mention at Amsterdam.pm,
– June 28, 2002 – YAPC NA "Two alternative ways of doing OO"
– July 1, 2002 – First mention on Perlmonks
Gained recent attention (notoriety?) as a recommended best practice with the
publication of Damian Conway's Perl Best Practices
Offer some interesting advantages... but at the cost of substantial complexity
– Big question: Do the benefits outweight the complexity?
Agenda for this tutorial:
– Teach the basics
– Describe the complexity
– Let you decide
2
Copyright © 2006 David A. Golden
Eversion 101 Lesson Plan: Five C's
Image sources: Michal Kosmulski,Bill Odom
001 Concepts
010 Choices
011 Code
100 Complexity
101 CPAN
Copyright © 2006 David A. Golden
001 Concepts
Image source: Michal Kosmulski
4
Copyright © 2006 David A. Golden
Three ideas at the core of this tutorial
TIMTOWTDI: Everything else is combinations and variations
1. Encapsulation using lexical closure
2. Objects as indices versus objects as containers
3. Memory addresses as unique identifiers
5
Copyright © 2006 David A. Golden
'Classic' Perl objects reference a data structure of properties
Image source: Michal Kosmulski
serial_no
rank
name
3210
Hash-based object
Array-based object
Object 1
Object 2
$obj = bless {}, "Some::Class";
$obj = bless [], "Some::Class";
6
Copyright © 2006 David A. Golden
Complaint #1 for classic objects: No enforced encapsulation
Frequent confusion describing the encapsulation problem
– Not about hiding data, algorithms or implementation choices
– It is about minimizing coupling with the code that uses the object
The real question: Culture versus control?
– Usually a matter of strong personal opinions
– Advisory encapsulation: 'double yellow lines'
– Enforced encapsulation: 'Jersey barriers'
The underlying challenge: Tight coupling of superclasses and subclasses
– Type of reference for data storage, e.g. hashes, array, scalars, etc.
– Names of keys for hashes
– 'Strong' encapsulation isn't even an option
7
Copyright © 2006 David A. Golden
Complaint #2: Hash key typos (and proliferating accessors)
A typo in the name of a property creates a bug, not an error1
– Code runs fine but results aren't as expected
$self->{naem} = 'James';
print $self->{name}; # What happened?
Accessors to the rescue (?!)
– Runtime error where the typo occurs
– Every property access gains function call overhead
$self->naem('James'); # Runtime error here
print $self->name();
My view: accessor proliferation for typo safety is probably not best practice
– Private need for typo safety shouldn't drive public interface design
– Couples implementation and interface
1
Locked hashes are another solution as of Perl 5.8
8
Copyright © 2006 David A. Golden
Eureka! We can enforce encapsulation with lexical closure
Class properties always did this
package Some::Class;
my $counter;
sub inc_counter {
my $self = shift;
$counter++;
}
Damian Conway's flyweight pattern2
my @objects;
sub new {
my $class = shift;
my $id = scalar @objects;
$objects[$id] = {};
return bless $id, $class;
}
sub get_name {
my $self = shift;
return $objects[$$self]{name};
}
serial_no
rank
name
inc_counter
3210
my @objects
1
my $counter
new
get_name
Some::Class
2
A brief version of this was introduced in Advanced Perl Programming, 1st
edition as ObjectTemplate
9
Copyright © 2006 David A. Golden
'Inside-Out' objects use an index into lexicals for each property
Image source: Michal Kosmulski
Object 4
Object 3
Object 2
Object 1
Object 4
Object 3
Object 2
Object 1
Object 4
Object 3
Object 2
Object 1
my %name
my %rank
my %serial_no
new
get_name
do_stuff
# Correct:
$name{ $$self };
# Compiler error:
$naem{ $$self };
Lexical properties
give compile-time
typo checking
under strict!
Some::Class
10
Copyright © 2006 David A. Golden
Review: 'Classic' versus 'Inside-Out'
Classic: Objects as containers
– Object is a reference to a data structure of properties
– No enforced encapsulation
– Hash-key typo problem
Inside-Out: Objects as indices
– Object is an index into a lexical data structure for each property
– Enforced encapsulation using lexical closure
– Compile-time typo protection
Image source: Michal Kosmulski
serial_no
rank
name
Object 1
Object 4
Object 3
Object 2
Object 1
my %name
Object 2
Object 2
Index
Copyright © 2006 David A. Golden
010 Choices
Image source: Michal Kosmulski
12
Copyright © 2006 David A. Golden
What data structure to use for inside-out properties?
Object 2
Object 2
Index
?
13
Copyright © 2006 David A. Golden
What data structure to use for inside-out properties?
Array
– Fast access
– Index limited to sequential integers
– Needs DESTROY to recycle indices to prevent runaway growth of property arrays
Hash
– Slow(er) access
– Any string as index
– Uses much more memory (particularly if keys are long)
– Needs DESTROY to free property memory to avoid leakage
Object 4
Object 3
Object 2
Object 1
my %name
Object 2
Object 2
Index
3210
my @name
How to decide?
14
Copyright © 2006 David A. Golden
Sequential number, stored in a blessed scalar
– Tight coupling – subclasses must also use a blessed scalar
– Subclass must use an index provided by the superclass
– Unless made read-only, objects can masquerade as other objects, whether references
to them exist or not!
$$self = $$self + 1
A unique, hard-to-guess number, stored in a blessed scalar (e.g. with Data::UUID)
– Again, tight coupling – subclasses must also use a blessed scalar
What index? (And stored how?)
8c2d4691
my %rank
Object 2
8c2d4691
3210
Object 1
1
my @name
15
Copyright © 2006 David A. Golden
An alternative: use the memory address as a unique identifier
Unique and consistent for the life of the object
– Except under threads (needs a CLONE method)
Several ways to get the memory address; only refaddr()is safe3
$property{ refaddr $self }
Otherwise, overloading of stringification or numification can give unexpected results
$property{ "$self" }
$property{ $self } # like "$self"
$property{ 0+$self }
0x224e40
my %serial_no
Object 3
?
0x224e40
3
Available in Scalar::Util
16
Copyright © 2006 David A. Golden
Using the memory address directly allows 'black-box' inheritance
When used directly as refaddr $self, the type of blessed reference no longer matters
– Subclasses don't need to know or care what the superclass is using as a data type
– Downside is slight overhead of refaddr $self for each access
Black-box inheritance4 – using a superclass object as the reference to bless
– a.k.a. 'foreign inheritance' or 'opaque inheritance'
– An alternative to facade/delegator/adaptor patterns and some uses of tied variables
– Superclass doesn't even have to be an inside-out object
use base 'Super::Class';
sub new {
my $class = shift;
my $self = Super::Class->new( @_ );
bless $self, $class;
return $self;
}
There is still a problem for multiple inheritance of different base object types
4
Thanks to Boston.pm for name brainstorming
17
Copyright © 2006 David A. Golden
These choices give four types of inside-out objects
1. Array-based properties, with sequential ID's stored in a blessed scalar
– Fast and uses less memory
– Insecure unless index is made read-only
– Requires index recycling
– Subclasses must also use a blessed scalar – no black-box inheritance
2. Hash-based properties, with a unique, hard-to-guess number stored in a blessed scalar
– Slow and uses more memory
– Robust, even under threads
– Subclasses must also use a blessed scalar – no black-box inheritance
3. Hash-based properties, with the memory address stored in a blessed scalar
– Subclasses must also use a blessed scalar – no black-box inheritance
– Combines the worst of (2) and (4) for a slight speed increase
4. Hash-based properties, with the memory address used directly
– Slow and uses more memory
– Black-box inheritance possible
– Not thread-safe unless using a CLONE method
?
Copyright © 2006 David A. Golden
011 Code
Image source: Michal Kosmulski
19
Copyright © 2006 David A. Golden
File::Marker: a simple inside-out objects with black-box inheritance
Useable directly as a filehandle (IO::File) without tying
$fm = File::Marker->new( $filename );
$line = <$fm>;
Set named markers for the current location in an opened file
$fm->set_marker( $mark_name );
Jump to the location indicated by a marker
$fm->goto_marker( $mark_name );
Let users jump back to the last jump point with a special key-word
$fm->goto_marker( "LAST" );
Clear markers when opening a file
$fm->open( $another_file ); # clear all markers
Key Features
20
Copyright © 2006 David A. Golden
File::Marker constructor
use base 'IO::File';
use Scalar::Util qw( refaddr );
my %MARKS = ();
sub new {
my $class = shift;
my $self = IO::File->new();
bless $self, $class;
$self->open( @_ ) if @_;
return $self;
}
sub open {
my $self = shift;
$MARKS{ refaddr $self } = {};
$self->SUPER::open( @_ );
$MARKS{ refaddr $self }{ 'LAST' } = $self->getpos;
return 1;
}
Uses strict and warnings
Argument validation
Error handling
Extensive test coverage
Thread safety
Full version of File::Marker
available on CPAN
21
Copyright © 2006 David A. Golden
File::Marker destructor and methods
sub DESTROY {
my $self = shift;
delete $MARKS{ refaddr $self };
}
sub set_marker {
my ($self, $mark) = @_;
$MARKS{ refaddr $self }{ $mark } = $self->getpos;
return 1;
}
sub goto_marker {
my ($self, $mark) = @_;
my $old_position = $self->getpos; # save for LAST
$self->setpos( $MARKS{ refaddr $self }{ $mark } );
$MARKS{ refaddr $self }{ 'LAST' } = $old_position;
return 1;
}
22
Copyright © 2006 David A. Golden
Seeing it in action
use strict;
use warnings;
use File::Marker;
my $fm = File::Marker->new(
"textfile.txt"
);
print scalar <$fm>, "--n";
$fm->set_marker("line2");
print <$fm>, "--n";
$fm->goto_marker("line2");
print scalar <$fm>;
this is line one
this is line two
this is line three
this is line four
textfile.txtfile_marker_example.pl
this is line one
--
this is line two
this is line three
this is line four
--
this is line two
Output
Copyright © 2006 David A. Golden
Complexity
Image source: Michal Kosmulski
24
Copyright © 2006 David A. Golden
Five pitfalls
1. Not using DESTROY to free memory or reclaim indices
2. Serialization – without special precautions
3. Not using refaddr() to get a memory address
4. Not providing CLONE for thread-safety
5. Using a CPAN implementation that gets these wrong
Inherent to all
inside-out objects
Only if using
memory addresses
25
Copyright © 2006 David A. Golden
Serialization requires extra work
Programmers often assume an object reference is a data structure
Dump( $object ); # implicitly breaks encapsulation
OO purists might say that objects should provide a dump method
$object->dump(); # OO-style
But, what if objects are part of a larger non-OO data structure?
@list = ( $obj1, $obj2, $obj3 );
freeze( @list ); # What now?
Fortunately, Storable provides hooks for objects to control their serialization
STORABLE_freeze();
STORABLE_thaw();
STORABLE_attach(); # for singletons
Of Data::Dumper and clones, only Data::Dump::Streamer provides the right
kind of hooks (but doesn't easily support singleton objects... yet)
26
Copyright © 2006 David A. Golden
Use CLONE for thread-safe refaddr indices
Starting with Perl 5.8, thread creation calls CLONE once per package, if it exists
– Called from the context of the new thread
– Works for Win32 pseudo-forks (but not for Perl 5.6)
Use a registry with weak references to track and remap old indices
– weaken provided by the XS version of Scalar::Util
0x224d5c
0x224f84
0x224f48
0x224e40
%REGISTRY
0x224e40
0x224f48
0x224f84
0x224d5c 0x224d5c
0x224f84
0x224f48
0x224e40
%REGISTRY
0x1830864
0x1830884
0x1830894
0x1830918
Original Thread New Thread
Abigail0x224d5c
Mark0x224f84
Damian0x224f48
Larry0x224e40
%name
Abigail0x224d5c
Mark0x224f84
Damian0x224f48
Larry0x224e40
%name
Use the registry key
to locate old data
27
Copyright © 2006 David A. Golden
Use CLONE for thread-safe refaddr indices
Starting with Perl 5.8, thread creation calls CLONE once per package, if it exists
– Called from the context of the new thread
– Works for Win32 pseudo-forks (but not for Perl 5.6)
Use a registry with weak references to track and remap old indices
– weaken provided by the XS version of Scalar::Util
0x224d5c
0x224f84
0x224f48
0x224e40
%REGISTRY
0x224e40
0x224f48
0x224f84
0x224d5c 0x224d5c
0x224f84
0x224f48
0x224e40
%REGISTRY
0x1830864
0x1830884
0x1830894
0x1830918
Original Thread New Thread
Abigail0x224d5c
Mark0x224f84
Damian0x224f48
Larry0x224e40
%name
Abigail0x224d5c
Larry0x1830864
Mark0x224f84
Damian0x224f48
Larry0x224e40
%name
Use the registry key
to locate old data
Copy data to new
refaddr key
Delete the old key
28
Copyright © 2006 David A. Golden
Use CLONE for thread-safe refaddr indices
Starting with Perl 5.8, thread creation calls CLONE once per package, if it exists
– Called from the context of the new thread
– Works for Win32 pseudo-forks (but not for Perl 5.6)
Use a registry with weak references to track and remap old indices
– weaken provided by the XS version of Scalar::Util
0x224d5c
0x224f84
0x224f48
0x224e40
%REGISTRY
0x224e40
0x224f48
0x224f84
0x224d5c 0x224d5c
0x224f84
0x224f48
0x1830864
%REGISTRY
0x1830864
0x1830884
0x1830894
0x1830918
Original Thread New Thread
Abigail0x224d5c
Mark0x224f84
Damian0x224f48
Larry0x224e40
%name
Abigail0x224d5c
Larry0x1830864
Mark0x224f84
Damian0x224f48
Larry0x224e40
%name
Use the registry key
to locate old data
Copy data to new
refaddr key
Delete the old key
Update the registry
Copyright © 2006 David A. Golden
CPAN
Image source: Bill Odom
30
Copyright © 2006 David A. Golden
Two CPAN modules to consider and several to (probably) avoid
Object::InsideOut
– Currently the most flexible, robust implementation of inside-out objects
– But, black-box inheritance handled via delegation (including multiple inheritance)
Class::InsideOut (disclaimer: I wrote this one)
– A safe, simple, minimalist approach
– Manages inside-out complexity but leaves all other details to the user
– Supports black-box inheritance directly
Class::Std
– Rich support for class hierarchies and overloading
– But, not yet thread-safe
– Hash-based with memory-address, but not in a way that allows black-box inheritance
All of these have flaws or limitations:
... but coming "soon" in Perl 5.10: Hash::Util::FieldHash
?
Lexical::Attributes
Object::LocalVars
Base::Class
Class::BuildMethods
Class::MakeMethods::Templates::InsideOut
!?
31
Copyright © 2006 David A. Golden
Questions?
Copyright © 2006 David A. Golden
Bonus Slides
Image source: Michal Kosmulski
33
Copyright © 2006 David A. Golden
File::Marker with thread safety, part one
use base 'IO::File';
use Scalar::Util qw( refaddr weaken );
my %MARKS = ();
my %REGISTRY = ();
sub new {
my $class = shift;
my $self = IO::File->new();
bless $self, $class;
weaken( $REGISTRY{ refaddr $self } = $self );
$self->open( @_ ) if @_;
return $self;
}
sub DESTROY {
my $self = shift;
delete $MARKS{ refaddr $self };
delete $REGISTRY{ refaddr $self };
}
34
Copyright © 2006 David A. Golden
File::Marker with thread safety, part two
sub CLONE {
for my $old_id ( keys %REGISTRY ) {
# look under old_id to find the new, cloned reference
my $object = $REGISTRY{ $old_id };
my $new_id = refaddr $object;
# relocate data
$MARKS{ $new_id } = $MARKS{ $old_id };
delete $MARKS{ $old_id };
# update the weak reference to the new, cloned object
weaken ( $REGISTRY{ $new_id } = $object );
delete $REGISTRY{ $old_id };
}
return;
}
35
Copyright © 2006 David A. Golden
Inside-out CPAN module comparison table
Simple, minimalist approach
Supports direct black-box
inheritance
mod_perl safe
Storable
hooks
Yesrefaddr $selfHashClass::InsideOut
(1.00)
Custom :attribute handling;
mod_perl safe
No black-box inheritance
support
Rich class hierarchy support
Storable
hooks with
Class::Std::
Storable
Norefaddr $selfHashClass::Std
(0.0.8)
black-box inheritance using
delegation pattern
Custom :attribute handling
mod_perl safe
Good thread support
Custom
dump()
Storable
hooks
YesArray: Integers
Hash: Cached
refaddr $self
Array or
Hash
Object::InsideOut
(1.27)
Other NotesSerializes?CLONE?IndexStorageModule
36
Copyright © 2006 David A. Golden
Inside-out CPAN module comparison table (continued)
Lexical storage in
Base::Class
Autogenerates all
properties/accessors via
AUTOLOAD
Dumper to
STDERR
only
No Storable
support
No"$self"Hash of
Hashes
('Flyweight')
Base::Class
(0.11)
Lexical storage in
Class::BuildMethods, not the
class that uses it; provides
accessors for use in code
Custom
dump()
No Storable
support
Norefaddr $selfHash of
Hashes
('Flyweight')
Class::BuildMethods
(0.11)
Part of a complex class
generator system; steep
learning curve
NoNo"$self"HashClass::MakeMethods
::Template::InsideOut
(1.01)
Other NotesSerializes?CLONE?IndexStorageModule
37
Copyright © 2006 David A. Golden
Inside-out CPAN module comparison table (continued)
Source filters for Perl-6-like
syntax
NoNorefaddr $selfHashLexical::Attributes
(1.4)
Custom :attribute handling
mod_perl safe
Wraps methods to locally
alias $self and properties
Highly experimental
NoYesrefaddr $selfPackage
global hash
Object::LocalVars
(0.16)
Other NotesSerializes?CLONE?IndexStorageModule
38
Copyright © 2006 David A. Golden
Some CPAN Modules which use the inside-out technique
Data::Postponed
– Delay the evaluation of expressions to allow post facto changes to input variables
File::Marker (from this tutorial)
– Set and jump between named position markers on a filehandle
List::Cycle
– Objects for cycling through a list of values
Symbol::Glob
– Remove items from the symbol table, painlessly
39
Copyright © 2006 David A. Golden
References for further study
Books by Damian Conway
– Object Oriented Perl. Manning Publications. 2000
– Perl Best Practices. O'Reilly Media. 2005
Perlmonks – see my scratchpad for a full list: <http://perlmonks.org/index.pl?node_id=360998>
– Abigail-II. "Re: Where/When is OO useful?". July 1, 2002
<http://perlmonks.org/index.pl?node_id=178518>
– Abigail-II. "Re: Tutorial: Introduction to Object-Oriented Programming". December 11, 2002
<http://perlmonks.org/index.pl?node_id=219131>
– demerphq. "Yet Another Perl Object Model (Inside Out Objects)". December 14, 2002
<http://perlmonks.org/index.pl?node_id=219924>
– xdg. "Threads and fork and CLONE, oh my!". August 11, 2005
<http://perlmonks.org/index.pl?node_id=483162>
– jdhedden. "Anti-inside-out-object-ism". December 9, 2005
<http://perlmonks.org/index.pl?node_id=515650>
Perl documentation (aka "perldoc") – also at <http://perldoc.perl.org>
– perlmod
– perlfork

More Related Content

What's hot

Vocales en mayuscula y lectura de cadena DEV C++
Vocales en mayuscula y lectura de cadena DEV C++Vocales en mayuscula y lectura de cadena DEV C++
Vocales en mayuscula y lectura de cadena DEV C++Eli Diaz
 
Python Part 1
Python Part 1Python Part 1
Python Part 1Sunil OS
 
Kriptografi - MD5
Kriptografi - MD5Kriptografi - MD5
Kriptografi - MD5KuliahKita
 
Inheritance Dan Polimorfisme
Inheritance Dan PolimorfismeInheritance Dan Polimorfisme
Inheritance Dan PolimorfismeDiana Anggraini
 
Images and Tables in HTML
Images and Tables in HTMLImages and Tables in HTML
Images and Tables in HTMLAarti P
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaEdureka!
 
ED Unidad 3: Estructuras de datos lineales (listas)
ED Unidad 3: Estructuras de datos lineales (listas) ED Unidad 3: Estructuras de datos lineales (listas)
ED Unidad 3: Estructuras de datos lineales (listas) Franklin Parrales Bravo
 
Laporan praktikum 1 perintah dasar sistem operasi linux
Laporan praktikum 1 perintah dasar sistem operasi linuxLaporan praktikum 1 perintah dasar sistem operasi linux
Laporan praktikum 1 perintah dasar sistem operasi linuxistiocta
 
Lecture 2. MS SQL. Stored procedures.
Lecture 2. MS SQL. Stored procedures.Lecture 2. MS SQL. Stored procedures.
Lecture 2. MS SQL. Stored procedures.Alexey Furmanov
 
Bootstrap PPT Part - 2
Bootstrap PPT Part - 2Bootstrap PPT Part - 2
Bootstrap PPT Part - 2EPAM Systems
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and stringsRai University
 
Estructura de Datos - Unidad III Estructuras Lineales
Estructura de Datos - Unidad III Estructuras LinealesEstructura de Datos - Unidad III Estructuras Lineales
Estructura de Datos - Unidad III Estructuras LinealesJosé Antonio Sandoval Acosta
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data ObjectsWez Furlong
 

What's hot (20)

Vocales en mayuscula y lectura de cadena DEV C++
Vocales en mayuscula y lectura de cadena DEV C++Vocales en mayuscula y lectura de cadena DEV C++
Vocales en mayuscula y lectura de cadena DEV C++
 
Python Part 1
Python Part 1Python Part 1
Python Part 1
 
Kriptografi - MD5
Kriptografi - MD5Kriptografi - MD5
Kriptografi - MD5
 
Inheritance Dan Polimorfisme
Inheritance Dan PolimorfismeInheritance Dan Polimorfisme
Inheritance Dan Polimorfisme
 
Images and Tables in HTML
Images and Tables in HTMLImages and Tables in HTML
Images and Tables in HTML
 
DOM HTML Javascript
DOM HTML JavascriptDOM HTML Javascript
DOM HTML Javascript
 
Function & Recursion
Function & RecursionFunction & Recursion
Function & Recursion
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
 
Major Java 8 features
Major Java 8 featuresMajor Java 8 features
Major Java 8 features
 
ED Unidad 3: Estructuras de datos lineales (listas)
ED Unidad 3: Estructuras de datos lineales (listas) ED Unidad 3: Estructuras de datos lineales (listas)
ED Unidad 3: Estructuras de datos lineales (listas)
 
Laporan praktikum 1 perintah dasar sistem operasi linux
Laporan praktikum 1 perintah dasar sistem operasi linuxLaporan praktikum 1 perintah dasar sistem operasi linux
Laporan praktikum 1 perintah dasar sistem operasi linux
 
Php Basico
Php BasicoPhp Basico
Php Basico
 
Lecture 2. MS SQL. Stored procedures.
Lecture 2. MS SQL. Stored procedures.Lecture 2. MS SQL. Stored procedures.
Lecture 2. MS SQL. Stored procedures.
 
Linux intro 4 awk + makefile
Linux intro 4  awk + makefileLinux intro 4  awk + makefile
Linux intro 4 awk + makefile
 
File Management
File ManagementFile Management
File Management
 
Bootstrap PPT Part - 2
Bootstrap PPT Part - 2Bootstrap PPT Part - 2
Bootstrap PPT Part - 2
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and strings
 
Mètodos de Ordenaciòn y bùsqueda
Mètodos de Ordenaciòn y bùsquedaMètodos de Ordenaciòn y bùsqueda
Mètodos de Ordenaciòn y bùsqueda
 
Estructura de Datos - Unidad III Estructuras Lineales
Estructura de Datos - Unidad III Estructuras LinealesEstructura de Datos - Unidad III Estructuras Lineales
Estructura de Datos - Unidad III Estructuras Lineales
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data Objects
 

Similar to Eversion 101: An Introduction to Inside-Out Objects

FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3Toni Kolev
 
key aggregate cryptosystem for scalable data sharing in cloud storage abstract
key aggregate cryptosystem for scalable data sharing in cloud storage abstractkey aggregate cryptosystem for scalable data sharing in cloud storage abstract
key aggregate cryptosystem for scalable data sharing in cloud storage abstractSanjana Yemajala
 
ironing out Docker
ironing out Dockerironing out Docker
ironing out Dockernindustries
 
PHP-05-Objects.ppt
PHP-05-Objects.pptPHP-05-Objects.ppt
PHP-05-Objects.pptrani marri
 
Crash Course in Objective-C
Crash Course in Objective-CCrash Course in Objective-C
Crash Course in Objective-CStephen Gilmore
 
Drupal 8: Entities
Drupal 8: EntitiesDrupal 8: Entities
Drupal 8: Entitiesdrubb
 
Recommending Semantic Nearest Neighbors Using Storm and Dato
Recommending Semantic Nearest Neighbors Using Storm and DatoRecommending Semantic Nearest Neighbors Using Storm and Dato
Recommending Semantic Nearest Neighbors Using Storm and DatoAshok Venkatesan
 
7.Canon & Dt
7.Canon & Dt7.Canon & Dt
7.Canon & Dtphanleson
 
#MBLTdev: Уроки, которые мы выучили, создавая Realm
#MBLTdev: Уроки, которые мы выучили, создавая Realm#MBLTdev: Уроки, которые мы выучили, создавая Realm
#MBLTdev: Уроки, которые мы выучили, создавая Realme-Legion
 
Node.js Patterns for Discerning Developers
Node.js Patterns for Discerning DevelopersNode.js Patterns for Discerning Developers
Node.js Patterns for Discerning Developerscacois
 
Rails and alternative ORMs
Rails and alternative ORMsRails and alternative ORMs
Rails and alternative ORMsJonathan Dahl
 
Data abstraction and object orientation
Data abstraction and object orientationData abstraction and object orientation
Data abstraction and object orientationHoang Nguyen
 
MongoDB World 2019: Tutorial: A Journey to Magical Security Creatures’ Land
MongoDB World 2019: Tutorial: A Journey to Magical Security Creatures’ LandMongoDB World 2019: Tutorial: A Journey to Magical Security Creatures’ Land
MongoDB World 2019: Tutorial: A Journey to Magical Security Creatures’ LandMongoDB
 
Automating Content Import
Automating Content ImportAutomating Content Import
Automating Content ImportDavid Lippman
 
Modeling Tricks My Relational Database Never Taught Me
Modeling Tricks My Relational Database Never Taught MeModeling Tricks My Relational Database Never Taught Me
Modeling Tricks My Relational Database Never Taught MeDavid Boike
 

Similar to Eversion 101: An Introduction to Inside-Out Objects (20)

Rails Security
Rails SecurityRails Security
Rails Security
 
FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3
 
key aggregate cryptosystem for scalable data sharing in cloud storage abstract
key aggregate cryptosystem for scalable data sharing in cloud storage abstractkey aggregate cryptosystem for scalable data sharing in cloud storage abstract
key aggregate cryptosystem for scalable data sharing in cloud storage abstract
 
ironing out Docker
ironing out Dockerironing out Docker
ironing out Docker
 
PHP-05-Objects.ppt
PHP-05-Objects.pptPHP-05-Objects.ppt
PHP-05-Objects.ppt
 
Crash Course in Objective-C
Crash Course in Objective-CCrash Course in Objective-C
Crash Course in Objective-C
 
Drupal 8: Entities
Drupal 8: EntitiesDrupal 8: Entities
Drupal 8: Entities
 
Recommending Semantic Nearest Neighbors Using Storm and Dato
Recommending Semantic Nearest Neighbors Using Storm and DatoRecommending Semantic Nearest Neighbors Using Storm and Dato
Recommending Semantic Nearest Neighbors Using Storm and Dato
 
7.Canon & Dt
7.Canon & Dt7.Canon & Dt
7.Canon & Dt
 
The breakup
The breakupThe breakup
The breakup
 
#MBLTdev: Уроки, которые мы выучили, создавая Realm
#MBLTdev: Уроки, которые мы выучили, создавая Realm#MBLTdev: Уроки, которые мы выучили, создавая Realm
#MBLTdev: Уроки, которые мы выучили, создавая Realm
 
Node.js Patterns for Discerning Developers
Node.js Patterns for Discerning DevelopersNode.js Patterns for Discerning Developers
Node.js Patterns for Discerning Developers
 
Rails and alternative ORMs
Rails and alternative ORMsRails and alternative ORMs
Rails and alternative ORMs
 
Leak, lock and a long pause
Leak, lock and a long pauseLeak, lock and a long pause
Leak, lock and a long pause
 
Data abstraction and object orientation
Data abstraction and object orientationData abstraction and object orientation
Data abstraction and object orientation
 
MongoDB World 2019: Tutorial: A Journey to Magical Security Creatures’ Land
MongoDB World 2019: Tutorial: A Journey to Magical Security Creatures’ LandMongoDB World 2019: Tutorial: A Journey to Magical Security Creatures’ Land
MongoDB World 2019: Tutorial: A Journey to Magical Security Creatures’ Land
 
Automating Content Import
Automating Content ImportAutomating Content Import
Automating Content Import
 
Libertyvasion2010
Libertyvasion2010Libertyvasion2010
Libertyvasion2010
 
Basic Unix
Basic UnixBasic Unix
Basic Unix
 
Modeling Tricks My Relational Database Never Taught Me
Modeling Tricks My Relational Database Never Taught MeModeling Tricks My Relational Database Never Taught Me
Modeling Tricks My Relational Database Never Taught Me
 

More from David Golden

Slice Recycling Performance and Pitfalls
Slice Recycling Performance and PitfallsSlice Recycling Performance and Pitfalls
Slice Recycling Performance and PitfallsDavid Golden
 
One BSON to Rule Them
One BSON to Rule ThemOne BSON to Rule Them
One BSON to Rule ThemDavid Golden
 
Adventures in Optimization
Adventures in OptimizationAdventures in Optimization
Adventures in OptimizationDavid Golden
 
Make Comments Stand Out
Make Comments Stand OutMake Comments Stand Out
Make Comments Stand OutDavid Golden
 
State of the Velociraptor Mini-Keynote: Perl Toolchain
State of the Velociraptor Mini-Keynote: Perl ToolchainState of the Velociraptor Mini-Keynote: Perl Toolchain
State of the Velociraptor Mini-Keynote: Perl ToolchainDavid Golden
 
Practical Consistency
Practical ConsistencyPractical Consistency
Practical ConsistencyDavid Golden
 
How I get to the ☞
How I get to the ☞How I get to the ☞
How I get to the ☞David Golden
 
Real World Optimization
Real World OptimizationReal World Optimization
Real World OptimizationDavid Golden
 
Safer Chainsaw Juggling (Lightning Talk)
Safer Chainsaw Juggling (Lightning Talk)Safer Chainsaw Juggling (Lightning Talk)
Safer Chainsaw Juggling (Lightning Talk)David Golden
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsDavid Golden
 
Juggling Chainsaws: Perl and MongoDB
Juggling Chainsaws: Perl and MongoDBJuggling Chainsaws: Perl and MongoDB
Juggling Chainsaws: Perl and MongoDBDavid Golden
 
Cooking Perl with Chef: Real World Tutorial with Jitterbug
Cooking Perl with Chef: Real World Tutorial with JitterbugCooking Perl with Chef: Real World Tutorial with Jitterbug
Cooking Perl with Chef: Real World Tutorial with JitterbugDavid Golden
 
Cooking Perl with Chef: Hello World Tutorial
Cooking Perl with Chef: Hello World TutorialCooking Perl with Chef: Hello World Tutorial
Cooking Perl with Chef: Hello World TutorialDavid Golden
 
Cooking Perl with Chef
Cooking Perl with ChefCooking Perl with Chef
Cooking Perl with ChefDavid Golden
 

More from David Golden (17)

Slice Recycling Performance and Pitfalls
Slice Recycling Performance and PitfallsSlice Recycling Performance and Pitfalls
Slice Recycling Performance and Pitfalls
 
Free QA!
Free QA!Free QA!
Free QA!
 
Perl 5 Version 13
Perl 5 Version 13Perl 5 Version 13
Perl 5 Version 13
 
IsTrue(true)?
IsTrue(true)?IsTrue(true)?
IsTrue(true)?
 
One BSON to Rule Them
One BSON to Rule ThemOne BSON to Rule Them
One BSON to Rule Them
 
Adventures in Optimization
Adventures in OptimizationAdventures in Optimization
Adventures in Optimization
 
Make Comments Stand Out
Make Comments Stand OutMake Comments Stand Out
Make Comments Stand Out
 
State of the Velociraptor Mini-Keynote: Perl Toolchain
State of the Velociraptor Mini-Keynote: Perl ToolchainState of the Velociraptor Mini-Keynote: Perl Toolchain
State of the Velociraptor Mini-Keynote: Perl Toolchain
 
Practical Consistency
Practical ConsistencyPractical Consistency
Practical Consistency
 
How I get to the ☞
How I get to the ☞How I get to the ☞
How I get to the ☞
 
Real World Optimization
Real World OptimizationReal World Optimization
Real World Optimization
 
Safer Chainsaw Juggling (Lightning Talk)
Safer Chainsaw Juggling (Lightning Talk)Safer Chainsaw Juggling (Lightning Talk)
Safer Chainsaw Juggling (Lightning Talk)
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order Functions
 
Juggling Chainsaws: Perl and MongoDB
Juggling Chainsaws: Perl and MongoDBJuggling Chainsaws: Perl and MongoDB
Juggling Chainsaws: Perl and MongoDB
 
Cooking Perl with Chef: Real World Tutorial with Jitterbug
Cooking Perl with Chef: Real World Tutorial with JitterbugCooking Perl with Chef: Real World Tutorial with Jitterbug
Cooking Perl with Chef: Real World Tutorial with Jitterbug
 
Cooking Perl with Chef: Hello World Tutorial
Cooking Perl with Chef: Hello World TutorialCooking Perl with Chef: Hello World Tutorial
Cooking Perl with Chef: Hello World Tutorial
 
Cooking Perl with Chef
Cooking Perl with ChefCooking Perl with Chef
Cooking Perl with Chef
 

Recently uploaded

WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2WSO2
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...WSO2
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2
 
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Eraconfluent
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2
 
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2
 
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 

Recently uploaded (20)

WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid Environments
 
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Era
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
 
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 

Eversion 101: An Introduction to Inside-Out Objects

  • 1. Copyright © 2006 David A. Golden Eversion 101 An Introduction to Inside-Out Objects David Golden dagolden@cpan.org June 26, 2006 YAPC::NA Image source: Michal Kosmulski
  • 2. 1 Copyright © 2006 David A. Golden An introduction to the inside-out technique Inside-out objects first presented by Dutch Perl hacker Abigail in 2002 – Spring 2002 – First mention at Amsterdam.pm, – June 28, 2002 – YAPC NA "Two alternative ways of doing OO" – July 1, 2002 – First mention on Perlmonks Gained recent attention (notoriety?) as a recommended best practice with the publication of Damian Conway's Perl Best Practices Offer some interesting advantages... but at the cost of substantial complexity – Big question: Do the benefits outweight the complexity? Agenda for this tutorial: – Teach the basics – Describe the complexity – Let you decide
  • 3. 2 Copyright © 2006 David A. Golden Eversion 101 Lesson Plan: Five C's Image sources: Michal Kosmulski,Bill Odom 001 Concepts 010 Choices 011 Code 100 Complexity 101 CPAN
  • 4. Copyright © 2006 David A. Golden 001 Concepts Image source: Michal Kosmulski
  • 5. 4 Copyright © 2006 David A. Golden Three ideas at the core of this tutorial TIMTOWTDI: Everything else is combinations and variations 1. Encapsulation using lexical closure 2. Objects as indices versus objects as containers 3. Memory addresses as unique identifiers
  • 6. 5 Copyright © 2006 David A. Golden 'Classic' Perl objects reference a data structure of properties Image source: Michal Kosmulski serial_no rank name 3210 Hash-based object Array-based object Object 1 Object 2 $obj = bless {}, "Some::Class"; $obj = bless [], "Some::Class";
  • 7. 6 Copyright © 2006 David A. Golden Complaint #1 for classic objects: No enforced encapsulation Frequent confusion describing the encapsulation problem – Not about hiding data, algorithms or implementation choices – It is about minimizing coupling with the code that uses the object The real question: Culture versus control? – Usually a matter of strong personal opinions – Advisory encapsulation: 'double yellow lines' – Enforced encapsulation: 'Jersey barriers' The underlying challenge: Tight coupling of superclasses and subclasses – Type of reference for data storage, e.g. hashes, array, scalars, etc. – Names of keys for hashes – 'Strong' encapsulation isn't even an option
  • 8. 7 Copyright © 2006 David A. Golden Complaint #2: Hash key typos (and proliferating accessors) A typo in the name of a property creates a bug, not an error1 – Code runs fine but results aren't as expected $self->{naem} = 'James'; print $self->{name}; # What happened? Accessors to the rescue (?!) – Runtime error where the typo occurs – Every property access gains function call overhead $self->naem('James'); # Runtime error here print $self->name(); My view: accessor proliferation for typo safety is probably not best practice – Private need for typo safety shouldn't drive public interface design – Couples implementation and interface 1 Locked hashes are another solution as of Perl 5.8
  • 9. 8 Copyright © 2006 David A. Golden Eureka! We can enforce encapsulation with lexical closure Class properties always did this package Some::Class; my $counter; sub inc_counter { my $self = shift; $counter++; } Damian Conway's flyweight pattern2 my @objects; sub new { my $class = shift; my $id = scalar @objects; $objects[$id] = {}; return bless $id, $class; } sub get_name { my $self = shift; return $objects[$$self]{name}; } serial_no rank name inc_counter 3210 my @objects 1 my $counter new get_name Some::Class 2 A brief version of this was introduced in Advanced Perl Programming, 1st edition as ObjectTemplate
  • 10. 9 Copyright © 2006 David A. Golden 'Inside-Out' objects use an index into lexicals for each property Image source: Michal Kosmulski Object 4 Object 3 Object 2 Object 1 Object 4 Object 3 Object 2 Object 1 Object 4 Object 3 Object 2 Object 1 my %name my %rank my %serial_no new get_name do_stuff # Correct: $name{ $$self }; # Compiler error: $naem{ $$self }; Lexical properties give compile-time typo checking under strict! Some::Class
  • 11. 10 Copyright © 2006 David A. Golden Review: 'Classic' versus 'Inside-Out' Classic: Objects as containers – Object is a reference to a data structure of properties – No enforced encapsulation – Hash-key typo problem Inside-Out: Objects as indices – Object is an index into a lexical data structure for each property – Enforced encapsulation using lexical closure – Compile-time typo protection Image source: Michal Kosmulski serial_no rank name Object 1 Object 4 Object 3 Object 2 Object 1 my %name Object 2 Object 2 Index
  • 12. Copyright © 2006 David A. Golden 010 Choices Image source: Michal Kosmulski
  • 13. 12 Copyright © 2006 David A. Golden What data structure to use for inside-out properties? Object 2 Object 2 Index ?
  • 14. 13 Copyright © 2006 David A. Golden What data structure to use for inside-out properties? Array – Fast access – Index limited to sequential integers – Needs DESTROY to recycle indices to prevent runaway growth of property arrays Hash – Slow(er) access – Any string as index – Uses much more memory (particularly if keys are long) – Needs DESTROY to free property memory to avoid leakage Object 4 Object 3 Object 2 Object 1 my %name Object 2 Object 2 Index 3210 my @name How to decide?
  • 15. 14 Copyright © 2006 David A. Golden Sequential number, stored in a blessed scalar – Tight coupling – subclasses must also use a blessed scalar – Subclass must use an index provided by the superclass – Unless made read-only, objects can masquerade as other objects, whether references to them exist or not! $$self = $$self + 1 A unique, hard-to-guess number, stored in a blessed scalar (e.g. with Data::UUID) – Again, tight coupling – subclasses must also use a blessed scalar What index? (And stored how?) 8c2d4691 my %rank Object 2 8c2d4691 3210 Object 1 1 my @name
  • 16. 15 Copyright © 2006 David A. Golden An alternative: use the memory address as a unique identifier Unique and consistent for the life of the object – Except under threads (needs a CLONE method) Several ways to get the memory address; only refaddr()is safe3 $property{ refaddr $self } Otherwise, overloading of stringification or numification can give unexpected results $property{ "$self" } $property{ $self } # like "$self" $property{ 0+$self } 0x224e40 my %serial_no Object 3 ? 0x224e40 3 Available in Scalar::Util
  • 17. 16 Copyright © 2006 David A. Golden Using the memory address directly allows 'black-box' inheritance When used directly as refaddr $self, the type of blessed reference no longer matters – Subclasses don't need to know or care what the superclass is using as a data type – Downside is slight overhead of refaddr $self for each access Black-box inheritance4 – using a superclass object as the reference to bless – a.k.a. 'foreign inheritance' or 'opaque inheritance' – An alternative to facade/delegator/adaptor patterns and some uses of tied variables – Superclass doesn't even have to be an inside-out object use base 'Super::Class'; sub new { my $class = shift; my $self = Super::Class->new( @_ ); bless $self, $class; return $self; } There is still a problem for multiple inheritance of different base object types 4 Thanks to Boston.pm for name brainstorming
  • 18. 17 Copyright © 2006 David A. Golden These choices give four types of inside-out objects 1. Array-based properties, with sequential ID's stored in a blessed scalar – Fast and uses less memory – Insecure unless index is made read-only – Requires index recycling – Subclasses must also use a blessed scalar – no black-box inheritance 2. Hash-based properties, with a unique, hard-to-guess number stored in a blessed scalar – Slow and uses more memory – Robust, even under threads – Subclasses must also use a blessed scalar – no black-box inheritance 3. Hash-based properties, with the memory address stored in a blessed scalar – Subclasses must also use a blessed scalar – no black-box inheritance – Combines the worst of (2) and (4) for a slight speed increase 4. Hash-based properties, with the memory address used directly – Slow and uses more memory – Black-box inheritance possible – Not thread-safe unless using a CLONE method ?
  • 19. Copyright © 2006 David A. Golden 011 Code Image source: Michal Kosmulski
  • 20. 19 Copyright © 2006 David A. Golden File::Marker: a simple inside-out objects with black-box inheritance Useable directly as a filehandle (IO::File) without tying $fm = File::Marker->new( $filename ); $line = <$fm>; Set named markers for the current location in an opened file $fm->set_marker( $mark_name ); Jump to the location indicated by a marker $fm->goto_marker( $mark_name ); Let users jump back to the last jump point with a special key-word $fm->goto_marker( "LAST" ); Clear markers when opening a file $fm->open( $another_file ); # clear all markers Key Features
  • 21. 20 Copyright © 2006 David A. Golden File::Marker constructor use base 'IO::File'; use Scalar::Util qw( refaddr ); my %MARKS = (); sub new { my $class = shift; my $self = IO::File->new(); bless $self, $class; $self->open( @_ ) if @_; return $self; } sub open { my $self = shift; $MARKS{ refaddr $self } = {}; $self->SUPER::open( @_ ); $MARKS{ refaddr $self }{ 'LAST' } = $self->getpos; return 1; } Uses strict and warnings Argument validation Error handling Extensive test coverage Thread safety Full version of File::Marker available on CPAN
  • 22. 21 Copyright © 2006 David A. Golden File::Marker destructor and methods sub DESTROY { my $self = shift; delete $MARKS{ refaddr $self }; } sub set_marker { my ($self, $mark) = @_; $MARKS{ refaddr $self }{ $mark } = $self->getpos; return 1; } sub goto_marker { my ($self, $mark) = @_; my $old_position = $self->getpos; # save for LAST $self->setpos( $MARKS{ refaddr $self }{ $mark } ); $MARKS{ refaddr $self }{ 'LAST' } = $old_position; return 1; }
  • 23. 22 Copyright © 2006 David A. Golden Seeing it in action use strict; use warnings; use File::Marker; my $fm = File::Marker->new( "textfile.txt" ); print scalar <$fm>, "--n"; $fm->set_marker("line2"); print <$fm>, "--n"; $fm->goto_marker("line2"); print scalar <$fm>; this is line one this is line two this is line three this is line four textfile.txtfile_marker_example.pl this is line one -- this is line two this is line three this is line four -- this is line two Output
  • 24. Copyright © 2006 David A. Golden Complexity Image source: Michal Kosmulski
  • 25. 24 Copyright © 2006 David A. Golden Five pitfalls 1. Not using DESTROY to free memory or reclaim indices 2. Serialization – without special precautions 3. Not using refaddr() to get a memory address 4. Not providing CLONE for thread-safety 5. Using a CPAN implementation that gets these wrong Inherent to all inside-out objects Only if using memory addresses
  • 26. 25 Copyright © 2006 David A. Golden Serialization requires extra work Programmers often assume an object reference is a data structure Dump( $object ); # implicitly breaks encapsulation OO purists might say that objects should provide a dump method $object->dump(); # OO-style But, what if objects are part of a larger non-OO data structure? @list = ( $obj1, $obj2, $obj3 ); freeze( @list ); # What now? Fortunately, Storable provides hooks for objects to control their serialization STORABLE_freeze(); STORABLE_thaw(); STORABLE_attach(); # for singletons Of Data::Dumper and clones, only Data::Dump::Streamer provides the right kind of hooks (but doesn't easily support singleton objects... yet)
  • 27. 26 Copyright © 2006 David A. Golden Use CLONE for thread-safe refaddr indices Starting with Perl 5.8, thread creation calls CLONE once per package, if it exists – Called from the context of the new thread – Works for Win32 pseudo-forks (but not for Perl 5.6) Use a registry with weak references to track and remap old indices – weaken provided by the XS version of Scalar::Util 0x224d5c 0x224f84 0x224f48 0x224e40 %REGISTRY 0x224e40 0x224f48 0x224f84 0x224d5c 0x224d5c 0x224f84 0x224f48 0x224e40 %REGISTRY 0x1830864 0x1830884 0x1830894 0x1830918 Original Thread New Thread Abigail0x224d5c Mark0x224f84 Damian0x224f48 Larry0x224e40 %name Abigail0x224d5c Mark0x224f84 Damian0x224f48 Larry0x224e40 %name Use the registry key to locate old data
  • 28. 27 Copyright © 2006 David A. Golden Use CLONE for thread-safe refaddr indices Starting with Perl 5.8, thread creation calls CLONE once per package, if it exists – Called from the context of the new thread – Works for Win32 pseudo-forks (but not for Perl 5.6) Use a registry with weak references to track and remap old indices – weaken provided by the XS version of Scalar::Util 0x224d5c 0x224f84 0x224f48 0x224e40 %REGISTRY 0x224e40 0x224f48 0x224f84 0x224d5c 0x224d5c 0x224f84 0x224f48 0x224e40 %REGISTRY 0x1830864 0x1830884 0x1830894 0x1830918 Original Thread New Thread Abigail0x224d5c Mark0x224f84 Damian0x224f48 Larry0x224e40 %name Abigail0x224d5c Larry0x1830864 Mark0x224f84 Damian0x224f48 Larry0x224e40 %name Use the registry key to locate old data Copy data to new refaddr key Delete the old key
  • 29. 28 Copyright © 2006 David A. Golden Use CLONE for thread-safe refaddr indices Starting with Perl 5.8, thread creation calls CLONE once per package, if it exists – Called from the context of the new thread – Works for Win32 pseudo-forks (but not for Perl 5.6) Use a registry with weak references to track and remap old indices – weaken provided by the XS version of Scalar::Util 0x224d5c 0x224f84 0x224f48 0x224e40 %REGISTRY 0x224e40 0x224f48 0x224f84 0x224d5c 0x224d5c 0x224f84 0x224f48 0x1830864 %REGISTRY 0x1830864 0x1830884 0x1830894 0x1830918 Original Thread New Thread Abigail0x224d5c Mark0x224f84 Damian0x224f48 Larry0x224e40 %name Abigail0x224d5c Larry0x1830864 Mark0x224f84 Damian0x224f48 Larry0x224e40 %name Use the registry key to locate old data Copy data to new refaddr key Delete the old key Update the registry
  • 30. Copyright © 2006 David A. Golden CPAN Image source: Bill Odom
  • 31. 30 Copyright © 2006 David A. Golden Two CPAN modules to consider and several to (probably) avoid Object::InsideOut – Currently the most flexible, robust implementation of inside-out objects – But, black-box inheritance handled via delegation (including multiple inheritance) Class::InsideOut (disclaimer: I wrote this one) – A safe, simple, minimalist approach – Manages inside-out complexity but leaves all other details to the user – Supports black-box inheritance directly Class::Std – Rich support for class hierarchies and overloading – But, not yet thread-safe – Hash-based with memory-address, but not in a way that allows black-box inheritance All of these have flaws or limitations: ... but coming "soon" in Perl 5.10: Hash::Util::FieldHash ? Lexical::Attributes Object::LocalVars Base::Class Class::BuildMethods Class::MakeMethods::Templates::InsideOut !?
  • 32. 31 Copyright © 2006 David A. Golden Questions?
  • 33. Copyright © 2006 David A. Golden Bonus Slides Image source: Michal Kosmulski
  • 34. 33 Copyright © 2006 David A. Golden File::Marker with thread safety, part one use base 'IO::File'; use Scalar::Util qw( refaddr weaken ); my %MARKS = (); my %REGISTRY = (); sub new { my $class = shift; my $self = IO::File->new(); bless $self, $class; weaken( $REGISTRY{ refaddr $self } = $self ); $self->open( @_ ) if @_; return $self; } sub DESTROY { my $self = shift; delete $MARKS{ refaddr $self }; delete $REGISTRY{ refaddr $self }; }
  • 35. 34 Copyright © 2006 David A. Golden File::Marker with thread safety, part two sub CLONE { for my $old_id ( keys %REGISTRY ) { # look under old_id to find the new, cloned reference my $object = $REGISTRY{ $old_id }; my $new_id = refaddr $object; # relocate data $MARKS{ $new_id } = $MARKS{ $old_id }; delete $MARKS{ $old_id }; # update the weak reference to the new, cloned object weaken ( $REGISTRY{ $new_id } = $object ); delete $REGISTRY{ $old_id }; } return; }
  • 36. 35 Copyright © 2006 David A. Golden Inside-out CPAN module comparison table Simple, minimalist approach Supports direct black-box inheritance mod_perl safe Storable hooks Yesrefaddr $selfHashClass::InsideOut (1.00) Custom :attribute handling; mod_perl safe No black-box inheritance support Rich class hierarchy support Storable hooks with Class::Std:: Storable Norefaddr $selfHashClass::Std (0.0.8) black-box inheritance using delegation pattern Custom :attribute handling mod_perl safe Good thread support Custom dump() Storable hooks YesArray: Integers Hash: Cached refaddr $self Array or Hash Object::InsideOut (1.27) Other NotesSerializes?CLONE?IndexStorageModule
  • 37. 36 Copyright © 2006 David A. Golden Inside-out CPAN module comparison table (continued) Lexical storage in Base::Class Autogenerates all properties/accessors via AUTOLOAD Dumper to STDERR only No Storable support No"$self"Hash of Hashes ('Flyweight') Base::Class (0.11) Lexical storage in Class::BuildMethods, not the class that uses it; provides accessors for use in code Custom dump() No Storable support Norefaddr $selfHash of Hashes ('Flyweight') Class::BuildMethods (0.11) Part of a complex class generator system; steep learning curve NoNo"$self"HashClass::MakeMethods ::Template::InsideOut (1.01) Other NotesSerializes?CLONE?IndexStorageModule
  • 38. 37 Copyright © 2006 David A. Golden Inside-out CPAN module comparison table (continued) Source filters for Perl-6-like syntax NoNorefaddr $selfHashLexical::Attributes (1.4) Custom :attribute handling mod_perl safe Wraps methods to locally alias $self and properties Highly experimental NoYesrefaddr $selfPackage global hash Object::LocalVars (0.16) Other NotesSerializes?CLONE?IndexStorageModule
  • 39. 38 Copyright © 2006 David A. Golden Some CPAN Modules which use the inside-out technique Data::Postponed – Delay the evaluation of expressions to allow post facto changes to input variables File::Marker (from this tutorial) – Set and jump between named position markers on a filehandle List::Cycle – Objects for cycling through a list of values Symbol::Glob – Remove items from the symbol table, painlessly
  • 40. 39 Copyright © 2006 David A. Golden References for further study Books by Damian Conway – Object Oriented Perl. Manning Publications. 2000 – Perl Best Practices. O'Reilly Media. 2005 Perlmonks – see my scratchpad for a full list: <http://perlmonks.org/index.pl?node_id=360998> – Abigail-II. "Re: Where/When is OO useful?". July 1, 2002 <http://perlmonks.org/index.pl?node_id=178518> – Abigail-II. "Re: Tutorial: Introduction to Object-Oriented Programming". December 11, 2002 <http://perlmonks.org/index.pl?node_id=219131> – demerphq. "Yet Another Perl Object Model (Inside Out Objects)". December 14, 2002 <http://perlmonks.org/index.pl?node_id=219924> – xdg. "Threads and fork and CLONE, oh my!". August 11, 2005 <http://perlmonks.org/index.pl?node_id=483162> – jdhedden. "Anti-inside-out-object-ism". December 9, 2005 <http://perlmonks.org/index.pl?node_id=515650> Perl documentation (aka "perldoc") – also at <http://perldoc.perl.org> – perlmod – perlfork