SlideShare a Scribd company logo
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Stories from
the Other Side
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Exploring OOP and
Functional Programming
(to become a better programmer)
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Why am I interested in this?
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Smart guys go FP (lambdalicious, phunkie)
The Little Schemer
Scala is the rage!
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
What is this, OOP + FP?
Where did these paradigms start?
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
The term "Object Oriented Programming"
was coined by Alan Kay
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Original image by Marcin Wichary - Thanks!
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Amongst many other achievements,
Alan Kay created Smalltalk
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
"OOP to me means only messaging,
local retention and protection
and hiding of state-process,
and extreme late-binding of all things"
It can be done in Smalltalk and in LISP."
~ Alan Kay
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
"It can be done in Smalltalk and in LISP."
wait... WHAT?
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
OOP in LISP?
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
((lambda (f)
(define pick
(lambda (n lat)
(cond
((zero? (sub1 n)) (car lat))
(else (pick (sub1 n) (cdr lat))))))
It's lists and recursion all the way down
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
How does OOP work with that?
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
What is OOP?
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Is it about inheritance?
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
"OOP to me means only messaging,
local retention and protection
and hiding of state-process,
and extreme late-binding of all things"
~ Alan Kay
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Kay doesn't mention inheritance.
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Is OOP about classes?
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Kay doesn't mention classes either.
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
If OOP is not about
classes or inheritance,
what is it about?
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Lets start with
Messaging
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
I guess that means method calls.
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
In class based OOP,
the methods of a class define its
Interface.
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Interface
==
Related Methods
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Quite similar to
related Functions
within a Namespace
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
So OOP is about grouping methods together?
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
"... local retention and protection ..."
~ Alan Kay
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Oh yeah, objects have states.
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
What is a state?
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
State in class based OOP:
class Foo
{
private static $class_state = 42;
private $instance_state = -0.2;
}
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
State in RL is more like
public function __construct(...)
{
$this->type = 'simple';
$this->customerSession = $customerSession;
$this->scopeConfig = $scopeConfig;
$this->counter = 0;
$this->id = $_REQUEST['id'];
$this->names = $db->getNames();
}
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
What properties do these examples of
state have?
public function __construct(...)
{
$this->type = 'simple';
$this->customerSession = $customerSession;
$this->scopeConfig = $scopeConfig;
$this->counter = 0;
$this->id = $_REQUEST['id'];
$this->names = $db->getNames();
}
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
A literal
$this->type = 'simple';
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
A shared object
$this->customerSession = $customerSession;
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Literal zero
(but looks like that might change)
$this->counter = 0;
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Global state
$this->id = $_REQUEST['id'];
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Stuff from the DB
$this->names = $db->getNames();
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Can we partition those examples?
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
1. State that is always the same
2. State that might change
(within the lifespan of the object)
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
State that might change:
→ Counter
→ Session
→ Filesystem / DB / Internet
→ Globals
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Non-changing state
→ The Type ID
→ Application State
→ Configuration
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
What can we do with
this information?
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Pure
Functions!
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Pure functions?
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
→ Don't cause any side effects
→ Given the same arguments
always return the same result
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
What are
side effects?
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
→ Changing state non-local to the
function scope
→ DB or Filesystem or Network access
→ Throwing Exceptions
→ Forking
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
No side effects
was one part.
What was the other?
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Same Arguments
==>
Same Result
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
A function that always returns the same
result given the same arguments is called
Referentially Transparent
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Referentially Transparent Functions
must not use state that might change!
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Why should we care?
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Benefits
of Pure Functions!
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
→ Easier to think about
(reasonability)
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
→ Easier to break apart
(decomposability)
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
→ Easier to combine
(composability & reuseability)
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
→ Easier to show correctness
(testability)
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
→ Easier to parallelize
(threadability ;))
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Mkay.
But what about the
changing things?
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
How can we deal with changing state?
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
We treat objects as snapshots of the
state of the world in one moment.
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
The state of the world in that
moment will never change.
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
If change occurs, it means now is a
different moment in time.
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
We can represent change in two ways:
→ by modifying the object
→ by creating a new instance
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Immutability
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
For example, what happens when an
admin logs in?
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
$loggedInAdmin = $loggedOutAdmin->login();
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
public function login()
{
return new self($isLoggedIn = true);
}
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
But what if a method
needs the
"current instance"?
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Either that object has to be recreated
with the current instance,
or the current instance has to be
passed as a method argument.
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
OOP style
$authorizationManager->hasAccess($dashboard, $loggedInAdmin);
$authorizationManager->hasAccess($dashboard, $loggedOutAdmin);
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
In FP
$has_access($dashboard, $loggedInAdmin);
$has_access($dashboard, $loggedOutAdmin);
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
There are more
parameters in RL!
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Okay, lets reduce the argument count by
adding properties to the object.
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
$dashboardAuthorizationManager =
new class($authorizationManager, $dashboard) {
private $authorizationManager; private $page;
public function __construct($authorizationManager, $page)
{
$this->authorizationManager = $authorizationManager;
$this->page = $page;
}
public function hasAccess($admin)
{
return $this->authorizationManager
->hasAccess($this->page, $admin);
}
}
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Only one argument left:
$pageAuthorizationManager->hasAccess($loggedInAdmin);
$pageAuthorizationManager->hasAccess($loggedOutAdmin);
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
How might that look like in FP?
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
$has_access_to_dashboard =
function ($admin) use ($dashboard, $has_access) {
return $has_access($dashboard, $admin);
}
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
$has_access_to_dashboard($loggedInAdmin);
$has_access_to_dashboard($loggedOutAdmin);
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Can we remove all
arguments?
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
$loggedInAdminDashboardAuthorization =
new class($dashboardAuthorizationManager, $loggedInAdmin)
{
private $pageAuthorizationManager; private $admin;
public function __construct($pageAuthorizationManager, $admin)
{
$this->pageAuthorizationManager = $pageAuthorizationManager;
$this->admin = $admin;
}
public function hasAccess()
{
return $this->pageAuthorizationManager
->hasAccess($this->admin);
}
}
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
In FP:
$has_logged_in_admin_access_to_dashboard =
function () use ($has_access_to_dashboard, $admin) {
return $has_access_to_dashboard($admin);
}
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
We can bundle state
and functions
without classes!
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
We can bundle state
and process
without classes!
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Look Ma,
OOP in PHP without
hands classes!
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
We have the choice:
→ pass state with method arguments
→ set state as object properties
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
The more volatile the object state,
the more often we need to
create new instances...
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
...if we want to have
Pure Functions.
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Lesson from FP:
Distinguish between mutable and
immutable object properties.
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
"Mutable stateful objects are the new
spaghetti code"
~ Rich Hickey
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Summary
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Concepts from the FP languages can be
useful in OO PHP.
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
We can benefit from designing our
OO code so it exhibits the properties of
pure functions.
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
We barely scratched the surface.
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Don't be afraid of FP's mathematical
pattern names. It's still just code.
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
Building these slides I
learned something about OOP.
I hope you found it interesting, too!
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
(if (has-communication? you vinai)
(communicate you vinai)
(enjoy you remaining-agenda))
MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp

More Related Content

Viewers also liked

Secure input and output handling - Meet Magento Romania 2016
Secure input and output handling - Meet Magento Romania 2016Secure input and output handling - Meet Magento Romania 2016
Secure input and output handling - Meet Magento Romania 2016
Anna Völkl
 
Peter Gannon Presentation - BDI 3/29/12 HCP Healthcare Social Communicatio
Peter Gannon Presentation - BDI 3/29/12 HCP Healthcare Social CommunicatioPeter Gannon Presentation - BDI 3/29/12 HCP Healthcare Social Communicatio
Peter Gannon Presentation - BDI 3/29/12 HCP Healthcare Social Communicatio
Business Development Institute
 
Tectonic Summit 2016: Preparing for Cloud Native
Tectonic Summit 2016: Preparing for Cloud Native Tectonic Summit 2016: Preparing for Cloud Native
Tectonic Summit 2016: Preparing for Cloud Native
CoreOS
 
Cloud Solution Day 2016: Service Mesh for Kubernetes
Cloud Solution Day 2016: Service Mesh for KubernetesCloud Solution Day 2016: Service Mesh for Kubernetes
Cloud Solution Day 2016: Service Mesh for Kubernetes
AWS Vietnam Community
 
Resilience testing with Wiremock and Spock
Resilience testing with Wiremock and SpockResilience testing with Wiremock and Spock
Resilience testing with Wiremock and Spock
David Schmitz
 
AWS Keynote 1 - AWS Enterprise Summit - Hong Kong
AWS Keynote 1 - AWS Enterprise Summit - Hong KongAWS Keynote 1 - AWS Enterprise Summit - Hong Kong
AWS Keynote 1 - AWS Enterprise Summit - Hong Kong
Amazon Web Services
 
Gdeploy 2.0
Gdeploy 2.0Gdeploy 2.0
Gdeploy 2.0
Sachidananda Urs
 
SFScon16 - Michele Baldessari: "OpenStack – An introduction"
SFScon16 - Michele Baldessari: "OpenStack – An introduction"SFScon16 - Michele Baldessari: "OpenStack – An introduction"
SFScon16 - Michele Baldessari: "OpenStack – An introduction"
South Tyrol Free Software Conference
 
Openstack in 10 mins
Openstack in 10 minsOpenstack in 10 mins
Openstack in 10 mins
Dawood M.S
 
Liberty release: Preliminary marketing materials & messages
Liberty release: Preliminary marketing materials & messagesLiberty release: Preliminary marketing materials & messages
Liberty release: Preliminary marketing materials & messages
OpenStack Foundation
 
OpenStack Summits 101: A Guide For Attendees
OpenStack Summits 101: A Guide For AttendeesOpenStack Summits 101: A Guide For Attendees
OpenStack Summits 101: A Guide For Attendees
OpenStack Foundation
 
Infra for startup
Infra for startupInfra for startup
Infra for startup
Sira Sujjinanont
 
CIECH - Financial results for 1H2016
CIECH - Financial results for 1H2016CIECH - Financial results for 1H2016
CIECH - Financial results for 1H2016
CIECH Group IR
 

Viewers also liked (14)

Apache ManifoldCF
Apache ManifoldCFApache ManifoldCF
Apache ManifoldCF
 
Secure input and output handling - Meet Magento Romania 2016
Secure input and output handling - Meet Magento Romania 2016Secure input and output handling - Meet Magento Romania 2016
Secure input and output handling - Meet Magento Romania 2016
 
Peter Gannon Presentation - BDI 3/29/12 HCP Healthcare Social Communicatio
Peter Gannon Presentation - BDI 3/29/12 HCP Healthcare Social CommunicatioPeter Gannon Presentation - BDI 3/29/12 HCP Healthcare Social Communicatio
Peter Gannon Presentation - BDI 3/29/12 HCP Healthcare Social Communicatio
 
Tectonic Summit 2016: Preparing for Cloud Native
Tectonic Summit 2016: Preparing for Cloud Native Tectonic Summit 2016: Preparing for Cloud Native
Tectonic Summit 2016: Preparing for Cloud Native
 
Cloud Solution Day 2016: Service Mesh for Kubernetes
Cloud Solution Day 2016: Service Mesh for KubernetesCloud Solution Day 2016: Service Mesh for Kubernetes
Cloud Solution Day 2016: Service Mesh for Kubernetes
 
Resilience testing with Wiremock and Spock
Resilience testing with Wiremock and SpockResilience testing with Wiremock and Spock
Resilience testing with Wiremock and Spock
 
AWS Keynote 1 - AWS Enterprise Summit - Hong Kong
AWS Keynote 1 - AWS Enterprise Summit - Hong KongAWS Keynote 1 - AWS Enterprise Summit - Hong Kong
AWS Keynote 1 - AWS Enterprise Summit - Hong Kong
 
Gdeploy 2.0
Gdeploy 2.0Gdeploy 2.0
Gdeploy 2.0
 
SFScon16 - Michele Baldessari: "OpenStack – An introduction"
SFScon16 - Michele Baldessari: "OpenStack – An introduction"SFScon16 - Michele Baldessari: "OpenStack – An introduction"
SFScon16 - Michele Baldessari: "OpenStack – An introduction"
 
Openstack in 10 mins
Openstack in 10 minsOpenstack in 10 mins
Openstack in 10 mins
 
Liberty release: Preliminary marketing materials & messages
Liberty release: Preliminary marketing materials & messagesLiberty release: Preliminary marketing materials & messages
Liberty release: Preliminary marketing materials & messages
 
OpenStack Summits 101: A Guide For Attendees
OpenStack Summits 101: A Guide For AttendeesOpenStack Summits 101: A Guide For Attendees
OpenStack Summits 101: A Guide For Attendees
 
Infra for startup
Infra for startupInfra for startup
Infra for startup
 
CIECH - Financial results for 1H2016
CIECH - Financial results for 1H2016CIECH - Financial results for 1H2016
CIECH - Financial results for 1H2016
 

More from vinaikopp

Building Mage-OS - MageTitans 2023
Building Mage-OS - MageTitans 2023Building Mage-OS - MageTitans 2023
Building Mage-OS - MageTitans 2023
vinaikopp
 
Hyvä: Compatibility Modules
Hyvä: Compatibility ModulesHyvä: Compatibility Modules
Hyvä: Compatibility Modules
vinaikopp
 
Hyvä from a developer perspective
Hyvä from a developer perspectiveHyvä from a developer perspective
Hyvä from a developer perspective
vinaikopp
 
Property Based Testing in PHP
Property Based Testing in PHPProperty Based Testing in PHP
Property Based Testing in PHP
vinaikopp
 
Property based testing - MageTestFest 2019
Property based testing - MageTestFest 2019Property based testing - MageTestFest 2019
Property based testing - MageTestFest 2019
vinaikopp
 
Becoming Certified - MageTitansMCR 2018
Becoming Certified - MageTitansMCR 2018Becoming Certified - MageTitansMCR 2018
Becoming Certified - MageTitansMCR 2018
vinaikopp
 
SOS UiComponents
SOS UiComponentsSOS UiComponents
SOS UiComponents
vinaikopp
 
ClojureScript in Magento 2 - PHPUGMRN
ClojureScript in Magento 2 - PHPUGMRNClojureScript in Magento 2 - PHPUGMRN
ClojureScript in Magento 2 - PHPUGMRN
vinaikopp
 
Magento 2 TDD Code Kata
Magento 2 TDD Code KataMagento 2 TDD Code Kata
Magento 2 TDD Code Kata
vinaikopp
 
Magento 2 TDD Code Kata Intro
Magento 2 TDD Code Kata IntroMagento 2 TDD Code Kata Intro
Magento 2 TDD Code Kata Intro
vinaikopp
 
Testing Magento 2
Testing Magento 2Testing Magento 2
Testing Magento 2
vinaikopp
 
ClojureScript in Magento 2 - MageTitansMCR 2017
ClojureScript in Magento 2 - MageTitansMCR 2017ClojureScript in Magento 2 - MageTitansMCR 2017
ClojureScript in Magento 2 - MageTitansMCR 2017
vinaikopp
 
Lizards & Pumpkins Catalog Replacement at mm17de
Lizards & Pumpkins Catalog Replacement at mm17deLizards & Pumpkins Catalog Replacement at mm17de
Lizards & Pumpkins Catalog Replacement at mm17de
vinaikopp
 
Writing Testable Code (for Magento 1 and 2) 2016 Romaina
Writing Testable Code (for Magento 1 and 2)  2016 RomainaWriting Testable Code (for Magento 1 and 2)  2016 Romaina
Writing Testable Code (for Magento 1 and 2) 2016 Romaina
vinaikopp
 
Writing Testable Code (for Magento 1 and 2)
Writing Testable Code (for Magento 1 and 2)Writing Testable Code (for Magento 1 and 2)
Writing Testable Code (for Magento 1 and 2)
vinaikopp
 
Writing testable Code (MageTitans Mini 2016)
Writing testable Code (MageTitans Mini 2016)Writing testable Code (MageTitans Mini 2016)
Writing testable Code (MageTitans Mini 2016)
vinaikopp
 
Getting your Hands Dirty Testing Magento 2 (at London Meetup)
Getting your Hands Dirty Testing Magento 2 (at London Meetup)Getting your Hands Dirty Testing Magento 2 (at London Meetup)
Getting your Hands Dirty Testing Magento 2 (at London Meetup)
vinaikopp
 
Getting your hands dirty testing Magento 2 (at MageTitansIT)
Getting your hands dirty testing Magento 2 (at MageTitansIT)Getting your hands dirty testing Magento 2 (at MageTitansIT)
Getting your hands dirty testing Magento 2 (at MageTitansIT)
vinaikopp
 
Architecture in-the-small-slides
Architecture in-the-small-slidesArchitecture in-the-small-slides
Architecture in-the-small-slides
vinaikopp
 
Modern Module Architecture
Modern Module ArchitectureModern Module Architecture
Modern Module Architecture
vinaikopp
 

More from vinaikopp (20)

Building Mage-OS - MageTitans 2023
Building Mage-OS - MageTitans 2023Building Mage-OS - MageTitans 2023
Building Mage-OS - MageTitans 2023
 
Hyvä: Compatibility Modules
Hyvä: Compatibility ModulesHyvä: Compatibility Modules
Hyvä: Compatibility Modules
 
Hyvä from a developer perspective
Hyvä from a developer perspectiveHyvä from a developer perspective
Hyvä from a developer perspective
 
Property Based Testing in PHP
Property Based Testing in PHPProperty Based Testing in PHP
Property Based Testing in PHP
 
Property based testing - MageTestFest 2019
Property based testing - MageTestFest 2019Property based testing - MageTestFest 2019
Property based testing - MageTestFest 2019
 
Becoming Certified - MageTitansMCR 2018
Becoming Certified - MageTitansMCR 2018Becoming Certified - MageTitansMCR 2018
Becoming Certified - MageTitansMCR 2018
 
SOS UiComponents
SOS UiComponentsSOS UiComponents
SOS UiComponents
 
ClojureScript in Magento 2 - PHPUGMRN
ClojureScript in Magento 2 - PHPUGMRNClojureScript in Magento 2 - PHPUGMRN
ClojureScript in Magento 2 - PHPUGMRN
 
Magento 2 TDD Code Kata
Magento 2 TDD Code KataMagento 2 TDD Code Kata
Magento 2 TDD Code Kata
 
Magento 2 TDD Code Kata Intro
Magento 2 TDD Code Kata IntroMagento 2 TDD Code Kata Intro
Magento 2 TDD Code Kata Intro
 
Testing Magento 2
Testing Magento 2Testing Magento 2
Testing Magento 2
 
ClojureScript in Magento 2 - MageTitansMCR 2017
ClojureScript in Magento 2 - MageTitansMCR 2017ClojureScript in Magento 2 - MageTitansMCR 2017
ClojureScript in Magento 2 - MageTitansMCR 2017
 
Lizards & Pumpkins Catalog Replacement at mm17de
Lizards & Pumpkins Catalog Replacement at mm17deLizards & Pumpkins Catalog Replacement at mm17de
Lizards & Pumpkins Catalog Replacement at mm17de
 
Writing Testable Code (for Magento 1 and 2) 2016 Romaina
Writing Testable Code (for Magento 1 and 2)  2016 RomainaWriting Testable Code (for Magento 1 and 2)  2016 Romaina
Writing Testable Code (for Magento 1 and 2) 2016 Romaina
 
Writing Testable Code (for Magento 1 and 2)
Writing Testable Code (for Magento 1 and 2)Writing Testable Code (for Magento 1 and 2)
Writing Testable Code (for Magento 1 and 2)
 
Writing testable Code (MageTitans Mini 2016)
Writing testable Code (MageTitans Mini 2016)Writing testable Code (MageTitans Mini 2016)
Writing testable Code (MageTitans Mini 2016)
 
Getting your Hands Dirty Testing Magento 2 (at London Meetup)
Getting your Hands Dirty Testing Magento 2 (at London Meetup)Getting your Hands Dirty Testing Magento 2 (at London Meetup)
Getting your Hands Dirty Testing Magento 2 (at London Meetup)
 
Getting your hands dirty testing Magento 2 (at MageTitansIT)
Getting your hands dirty testing Magento 2 (at MageTitansIT)Getting your hands dirty testing Magento 2 (at MageTitansIT)
Getting your hands dirty testing Magento 2 (at MageTitansIT)
 
Architecture in-the-small-slides
Architecture in-the-small-slidesArchitecture in-the-small-slides
Architecture in-the-small-slides
 
Modern Module Architecture
Modern Module ArchitectureModern Module Architecture
Modern Module Architecture
 

Recently uploaded

SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
GohKiangHock
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
dakas1
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
safelyiotech
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
Peter Muessig
 
zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
YousufSait3
 
YAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring detailsYAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring details
NishanthaBulumulla1
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
Karya Keeper
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
mz5nrf0n
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
Rakesh Kumar R
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 

Recently uploaded (20)

SQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure MalaysiaSQL Accounting Software Brochure Malaysia
SQL Accounting Software Brochure Malaysia
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
 
zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
 
YAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring detailsYAML crash COURSE how to write yaml file for adding configuring details
YAML crash COURSE how to write yaml file for adding configuring details
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
What next after learning python programming basics
What next after learning python programming basicsWhat next after learning python programming basics
What next after learning python programming basics
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 

Stories from the other side

  • 1. MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 2. Stories from the Other Side MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 3. Exploring OOP and Functional Programming (to become a better programmer) MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 4. Why am I interested in this? MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 5. Smart guys go FP (lambdalicious, phunkie) The Little Schemer Scala is the rage! MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 6. What is this, OOP + FP? Where did these paradigms start? MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 7. The term "Object Oriented Programming" was coined by Alan Kay MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 8. Original image by Marcin Wichary - Thanks! MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 9. Amongst many other achievements, Alan Kay created Smalltalk MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 10. "OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things" It can be done in Smalltalk and in LISP." ~ Alan Kay MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 11. "It can be done in Smalltalk and in LISP." wait... WHAT? MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 12. OOP in LISP? MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 13. ((lambda (f) (define pick (lambda (n lat) (cond ((zero? (sub1 n)) (car lat)) (else (pick (sub1 n) (cdr lat)))))) It's lists and recursion all the way down MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 14. How does OOP work with that? MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 15. What is OOP? MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 16. Is it about inheritance? MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 17. "OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things" ~ Alan Kay MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 18. Kay doesn't mention inheritance. MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 19. Is OOP about classes? MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 20. Kay doesn't mention classes either. MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 21. If OOP is not about classes or inheritance, what is it about? MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 22. Lets start with Messaging MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 23. I guess that means method calls. MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 24. In class based OOP, the methods of a class define its Interface. MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 25. Interface == Related Methods MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 26. Quite similar to related Functions within a Namespace MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 27. So OOP is about grouping methods together? MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 28. "... local retention and protection ..." ~ Alan Kay MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 29. Oh yeah, objects have states. MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 30. What is a state? MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 31. State in class based OOP: class Foo { private static $class_state = 42; private $instance_state = -0.2; } MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 32. State in RL is more like public function __construct(...) { $this->type = 'simple'; $this->customerSession = $customerSession; $this->scopeConfig = $scopeConfig; $this->counter = 0; $this->id = $_REQUEST['id']; $this->names = $db->getNames(); } MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 33. What properties do these examples of state have? public function __construct(...) { $this->type = 'simple'; $this->customerSession = $customerSession; $this->scopeConfig = $scopeConfig; $this->counter = 0; $this->id = $_REQUEST['id']; $this->names = $db->getNames(); } MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 34. A literal $this->type = 'simple'; MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 35. A shared object $this->customerSession = $customerSession; MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 36. Literal zero (but looks like that might change) $this->counter = 0; MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 37. Global state $this->id = $_REQUEST['id']; MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 38. Stuff from the DB $this->names = $db->getNames(); MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 39. Can we partition those examples? MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 40. 1. State that is always the same 2. State that might change (within the lifespan of the object) MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 41. State that might change: → Counter → Session → Filesystem / DB / Internet → Globals MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 42. Non-changing state → The Type ID → Application State → Configuration MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 43. What can we do with this information? MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 44. Pure Functions! MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 45. Pure functions? MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 46. → Don't cause any side effects → Given the same arguments always return the same result MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 47. What are side effects? MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 48. → Changing state non-local to the function scope → DB or Filesystem or Network access → Throwing Exceptions → Forking MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 49. No side effects was one part. What was the other? MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 50. Same Arguments ==> Same Result MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 51. A function that always returns the same result given the same arguments is called Referentially Transparent MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 52. Referentially Transparent Functions must not use state that might change! MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 53. Why should we care? MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 54. Benefits of Pure Functions! MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 55. → Easier to think about (reasonability) MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 56. → Easier to break apart (decomposability) MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 57. → Easier to combine (composability & reuseability) MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 58. → Easier to show correctness (testability) MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 59. → Easier to parallelize (threadability ;)) MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 60. Mkay. But what about the changing things? MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 61. How can we deal with changing state? MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 62. We treat objects as snapshots of the state of the world in one moment. MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 63. The state of the world in that moment will never change. MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 64. If change occurs, it means now is a different moment in time. MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 65. We can represent change in two ways: → by modifying the object → by creating a new instance MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 66. Immutability MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 67. For example, what happens when an admin logs in? MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 68. $loggedInAdmin = $loggedOutAdmin->login(); MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 69. public function login() { return new self($isLoggedIn = true); } MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 70. But what if a method needs the "current instance"? MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 71. Either that object has to be recreated with the current instance, or the current instance has to be passed as a method argument. MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 72. OOP style $authorizationManager->hasAccess($dashboard, $loggedInAdmin); $authorizationManager->hasAccess($dashboard, $loggedOutAdmin); MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 73. In FP $has_access($dashboard, $loggedInAdmin); $has_access($dashboard, $loggedOutAdmin); MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 74. There are more parameters in RL! MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 75. Okay, lets reduce the argument count by adding properties to the object. MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 76. $dashboardAuthorizationManager = new class($authorizationManager, $dashboard) { private $authorizationManager; private $page; public function __construct($authorizationManager, $page) { $this->authorizationManager = $authorizationManager; $this->page = $page; } public function hasAccess($admin) { return $this->authorizationManager ->hasAccess($this->page, $admin); } } MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 77. Only one argument left: $pageAuthorizationManager->hasAccess($loggedInAdmin); $pageAuthorizationManager->hasAccess($loggedOutAdmin); MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 78. How might that look like in FP? MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 79. $has_access_to_dashboard = function ($admin) use ($dashboard, $has_access) { return $has_access($dashboard, $admin); } MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 81. Can we remove all arguments? MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 82. $loggedInAdminDashboardAuthorization = new class($dashboardAuthorizationManager, $loggedInAdmin) { private $pageAuthorizationManager; private $admin; public function __construct($pageAuthorizationManager, $admin) { $this->pageAuthorizationManager = $pageAuthorizationManager; $this->admin = $admin; } public function hasAccess() { return $this->pageAuthorizationManager ->hasAccess($this->admin); } } MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 83. In FP: $has_logged_in_admin_access_to_dashboard = function () use ($has_access_to_dashboard, $admin) { return $has_access_to_dashboard($admin); } MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 84. We can bundle state and functions without classes! MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 85. We can bundle state and process without classes! MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 86. Look Ma, OOP in PHP without hands classes! MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 87. We have the choice: → pass state with method arguments → set state as object properties MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 88. The more volatile the object state, the more often we need to create new instances... MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 89. ...if we want to have Pure Functions. MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 90. Lesson from FP: Distinguish between mutable and immutable object properties. MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 91. "Mutable stateful objects are the new spaghetti code" ~ Rich Hickey MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 92. Summary MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 93. Concepts from the FP languages can be useful in OO PHP. MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 94. We can benefit from designing our OO code so it exhibits the properties of pure functions. MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 95. We barely scratched the surface. MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 96. Don't be afraid of FP's mathematical pattern names. It's still just code. MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 97. Building these slides I learned something about OOP. I hope you found it interesting, too! MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp
  • 98. (if (has-communication? you vinai) (communicate you vinai) (enjoy you remaining-agenda)) MageTitans Manchester, UK - #MageTitansMCR 2016-11-12 - twitter://@VinaiKopp