SlideShare a Scribd company logo
1 of 39
Download to read offline
TAKING PHP
SERIOUSLY
Keith Adams
Facebook
Strange Loop 2013
Why PHP?
What this talk is
•  Experience report
•  Apologia
•  Qualified advocacy
•  A surprise.
What this talk is not
•  “Network effects”/”Legacy”
•  “Right tool for the job”
•  tautological
•  some tools really are bad
•  PHP might be such a tool
•  “Worse is better”
•  pace Richard Gabriel
•  Better is better
•  Most people think of UNIX as “better” nowadays
Recent changes
•  Traits (ala Scala)
•  Closures
•  Generators (yield statement)
•  The HipHop VM (hhvm) is fast
•  https://github.com/facebook/hiphop-php/
•  https://www.hhvm.com
•  ...and we want it to run your code
•  http://www.hhvm.com/blog/?p=875
Conventional Wisdom on PHP
•  “PHP: A fractal of bad design”
•  http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/
•  “[ ] You have reinvented PHP better, but that’s still no
justification”
•  http://colinm.org/language_checklist.html
•  Etc.
And yet...
•  A lot of software that has changed the world has been
rendered in PHP
•  Mediawiki
•  Facebook
•  Wordpress
•  Drupal
•  This is at least interesting
•  Should they really have been written in Haskell?
•  Does PHP make projects more or less successful?
Facebook’s PHP Codebase
•  x * 105 files
•  y * 107 LoC
•  10 releases per week
•  Anecdotally, good engineers are astonishingly productive
in PHP
The Case Against PHP
•  Unexpected behaviors
$x	
  /	
  0	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  //	
  =>	
  bool(false)	
  
	
  
“11abcd”	
  +	
  “1xy”	
  //	
  =>	
  int(12)	
  
“0123”	
  +	
  “3456”	
  	
  //	
  =>	
  int(3579)	
  
“0123”	
  |	
  “3456”	
  	
  //	
  =>	
  string(“3577”)	
  
The Case Against PHP (2)
•  Schizophrenia about value/reference semantics
	
  	
  /*	
  	
  
	
  	
  	
  *	
  Probably	
  copy	
  $a	
  into	
  foo’s	
  0’th	
  param.	
  
	
  	
  	
  *	
  Unless	
  $a	
  is	
  a	
  user-­‐defined	
  object;	
  and	
  unless	
  
	
  	
  	
  *	
  foo’s	
  definition	
  specifies	
  that	
  arg	
  0	
  is	
  by	
  	
  
	
  	
  	
  *	
  reference.	
  
	
  	
  	
  */	
  
	
  	
  foo($a);	
  
The Case Against PHP (3)
•  Reliance on reference-counting
•  String, array need O(1) logical copies
•  User-defined classes have destructors that run at a deterministic
time
•  Some programs use the RAII idiom from C++
•  Heavily constrains implementation
The Case Against PHP (4)
•  Inconsistent, dangerous standard library
•  array_map vs. array_reduce argument orders
•  array_merge
•  mysql_escape_string vs. (sigh) mysql_real_escape_string
The Case Against PHP: “Guilty”
•  It’s all true!
•  These are “unforced errors”
•  Most other languages do better
•  You would want to avoid them in a PHP Reboot
In Defense of PHP
•  PHP gets three important things really right
•  Programmer workflow
•  State
•  Concurrency
Workflow
•  Save, reload-the-page
•  Short feedback cycle
•  Optimizes most precious resource of all: programmer
short-term memory
State
•  PHP requests always start with empty heap, namespace
•  Cross-request state must be saved explicitly
•  Filesystem, memcache, APC
•  Affirmative virtue
•  Typical FB requests spend 10ms initializing
•  Reduces the cost of bugs
•  Requests interact in limited ways
•  Natural boundary for failure isolation
Concurrency
•  PHP requests execute in a single thread
•  Concurrency happens via recursive web requests
•  shared-nothing
•  inputs/outputs copied
•  Limits PHP’s applicable domain
•  That’s actually good.
Workflow
StateConcurrency
The limits of conscious design
•  Discovered or invented?
•  Shrug
•  In my opinion, more important than PHP’s problems
•  They’re not available anywhere else
Workflow
StateConcurrency
Pushing PHP further
•  PHP engineer dare: rename this method
•  Reorder the parameters for this method
•  Remove this method that we think is not called anywhere
Pushing PHP further (2)
•  Enforce invariants:
•  Only escaped strings are passed to build_query	
  
•  A certain array() maps strings to Widgets
Wait...
•  A static type system?
•  Verbose types, or
incomprehensible error
messages
•  Either way hoses
programmer productivity
•  Millions of lines to migrate
Workflow
StateConcurrency
We think we’ve solved this problem
•  Introducing Hack
•  Gradual typing for PHP
•  Novel type inference system
•  Real-time type-checking
preserves PHP workflow
•  Credit: Julien Verlaguet
Hack
•  Opt into typing via <?hh (instead of <?php)
•  <?hh	
  //	
  strict	
  
•  Almost-totally sound analysis
•  Requires transitive closure of code has been hackified	
  
•  <?hh	
  
•  Tolerates missing annotations
•  Assumes undeclared classes/functions exist, behave as implied by
any types
•  Disallows most “silly” PHP-isms
Hack implementation
EditorType Checker HHVM
Filesystem
inotify
errors
web
requests
source
Changes from PHP
<?hh	
  
class	
  Point2	
  {	
  
	
  	
  public	
  float	
  $x,	
  $y;	
  
	
  	
  function	
  __construct(float	
  $x,	
  float	
  $y)	
  {	
  
	
  	
  	
  	
  $this-­‐>x	
  =	
  $x;	
  
	
  	
  	
  	
  $this-­‐>x	
  =	
  $y;	
  
	
  	
  }	
  
}	
  
Changes from PHP
<?hh	
  
class	
  Point2	
  {	
  
	
  	
  public	
  float	
  $x,	
  $y;	
  
	
  	
  function	
  __construct(float	
  $x,	
  float	
  $y)	
  {	
  
	
  	
  	
  	
  $this-­‐>x	
  =	
  $x;	
  
	
  	
  	
  	
  $this-­‐>x	
  =	
  $y;	
  //	
  Whoopsy.	
  Didn’t	
  init	
  y	
  
	
  	
  }	
  
}	
  
Changes from PHP
<?hh	
  
...	
  
function	
  meanOrigDistance(Point	
  $p,	
  Point	
  $q)	
  
	
  	
  :	
  float	
  {	
  
	
  	
  $distf	
  =	
  function(Point	
  $p)	
  :	
  float	
  {	
  
	
  	
  	
  	
  return	
  sqrt($p-­‐>x	
  *	
  $p-­‐>x	
  +	
  $p-­‐>y	
  *	
  $p-­‐>y);	
  
	
  	
  };	
  
	
  	
  $pdist	
  =	
  $distf($p);	
  
	
  	
  $qdist	
  =	
  $distf($q);	
  
	
  	
  return	
  ($pdist	
  +	
  $qdist)	
  /	
  2;	
  
}	
  
Hack Type Cheatsheet
•  Base PHP types: int,	
  MyClassName,	
  array,	
  ...	
  
•  Nullable: ?int,	
  ?MyClassName	
  
•  Mixed: anything (careful)
•  Tuples: (int,	
  bool,	
  X)	
  
•  Closures: (function(int):	
  int)	
  
•  Collections: Vector<int>,	
  Map<string,	
  int>	
  
•  Generics: A<T>,	
  foo<T>(T	
  $x):	
  T	
  
•  Constraints: foo<T	
  as	
  A>(T	
  $x):	
  T	
  
Hack Type Inference (1)
•  Let’s infer the type of $x:
Hack Type Inference (2)
•  How does a type-system normally work?
•  Type-variables are introduced
•  A unification algorithm solves the type-variables (usually noted α)
if (…) {
$x = new A();
} else {
$x = new B();
}
type($x) = α
unify(α, A) => α = A
unify(α, B) => α = B
ERROR
Type inference in Hack
•  Hack introduces unresolved types (noted U)
if (…) {
$x = new A();
} else {
$x = new B();
}
takesAnIFace($x);
type($x) = α = U()
$x = α = U(A);
$x = α = U(A, B);
$x = α = U(A, B) = IFace
with (A ≤ IFace, B ≤ IFace)
Error messages
•  We can’t expect the user to understand all the type-
inference
•  The solution: keep the reason why we deduced a type
and expose it to the user
Hack
•  “[ X ] You have reinvented PHP better, but that’s still no
justification
•  [ X ] The name of your language makes it impossible to
find on Google”
•  Many millions of lines converted
•  Most new code in Hack
•  Most PHP users at Facebook regularly check in Hack
Postmodern PHP (2014-...)
•  HipHop project provides
great tools
•  Fast VM
•  Debugger
•  Profiler
•  Integrations with editors/IDEs
•  Hack is a SoA gradual typing
system
•  Maintains all of PHP’s
strengths
•  Compare to your favorite
“Dynamic Algol”
Workflow
StateConcurrency
When PHP?
•  Any time you might consider another “Dynamic Algol”
language
•  Python, Lua, JavaScript, Perl, Ruby, ...
•  Server-side
•  Request-oriented
•  ...but want to preserve some of the option value of
“BigLangs”
•  Type system
•  High-performance implementations
Backup
Everyone’s favorite generics slide
•  (Remember, “covariance” refers to type specifications for Type that accept T
>= Type. “Contravariance” means Type that accept T <= Type.)
•  We allow:
•  Covariant function parameters
•  Covariant arrays
•  Constraints on type parameters (Foo<T as IFace> will error if T
does not implement IFace)
•  We don’t allow
•  Contravariant function params (they don’t make sense)
•  Covariant type parameters
•  Remember, runtime throws everything away anyway, so
perfwise, it’s type erasure.

More Related Content

What's hot

PHP, PHP Developer, Hire PHP Developer, PHP Web Development, Hire PHP Program...
PHP, PHP Developer, Hire PHP Developer, PHP Web Development, Hire PHP Program...PHP, PHP Developer, Hire PHP Developer, PHP Web Development, Hire PHP Program...
PHP, PHP Developer, Hire PHP Developer, PHP Web Development, Hire PHP Program...bchrisopher
 
Introduction to PHP - SDPHP
Introduction to PHP - SDPHPIntroduction to PHP - SDPHP
Introduction to PHP - SDPHPEric Johnson
 
Practical PowerShell Programming for Professional People - Extended Edition
Practical PowerShell Programming for Professional People - Extended EditionPractical PowerShell Programming for Professional People - Extended Edition
Practical PowerShell Programming for Professional People - Extended EditionBen Ten (0xA)
 
Practical PowerShell Programming for Professional People - DerbyCon 4
Practical PowerShell Programming for Professional People - DerbyCon 4Practical PowerShell Programming for Professional People - DerbyCon 4
Practical PowerShell Programming for Professional People - DerbyCon 4Ben Ten (0xA)
 
Slicing, Dicing, And Linting OpenAPI
Slicing, Dicing, And Linting OpenAPISlicing, Dicing, And Linting OpenAPI
Slicing, Dicing, And Linting OpenAPIlestrrat
 
IPC 2013 - High Performance PHP with HipHop
IPC 2013 - High Performance PHP with HipHopIPC 2013 - High Performance PHP with HipHop
IPC 2013 - High Performance PHP with HipHopSteve Kamerman
 
NLP using JavaScript Natural Library
NLP using JavaScript Natural LibraryNLP using JavaScript Natural Library
NLP using JavaScript Natural LibraryAniruddha Chakrabarti
 
Getting started with Perl XS and Inline::C
Getting started with Perl XS and Inline::CGetting started with Perl XS and Inline::C
Getting started with Perl XS and Inline::Cdaoswald
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with PerlDave Cross
 
Taking PHP To the next level
Taking PHP To the next levelTaking PHP To the next level
Taking PHP To the next levelDavid Coallier
 
Packer Genetics: The selfish code
Packer Genetics: The selfish codePacker Genetics: The selfish code
Packer Genetics: The selfish codejduart
 
Gray Hat PowerShell - ShowMeCon 2015
Gray Hat PowerShell - ShowMeCon 2015Gray Hat PowerShell - ShowMeCon 2015
Gray Hat PowerShell - ShowMeCon 2015Ben Ten (0xA)
 
ShaREing Is Caring
ShaREing Is CaringShaREing Is Caring
ShaREing Is Caringsporst
 
Natural Language Processing sample code by Aiden
Natural Language Processing sample code by AidenNatural Language Processing sample code by Aiden
Natural Language Processing sample code by AidenAiden Wu, FRM
 
Not Your Fathers C - C Application Development In 2016
Not Your Fathers C - C Application Development In 2016Not Your Fathers C - C Application Development In 2016
Not Your Fathers C - C Application Development In 2016maiktoepfer
 

What's hot (19)

PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
 
Php
PhpPhp
Php
 
PHP, PHP Developer, Hire PHP Developer, PHP Web Development, Hire PHP Program...
PHP, PHP Developer, Hire PHP Developer, PHP Web Development, Hire PHP Program...PHP, PHP Developer, Hire PHP Developer, PHP Web Development, Hire PHP Program...
PHP, PHP Developer, Hire PHP Developer, PHP Web Development, Hire PHP Program...
 
Introduction to PHP - SDPHP
Introduction to PHP - SDPHPIntroduction to PHP - SDPHP
Introduction to PHP - SDPHP
 
Practical PowerShell Programming for Professional People - Extended Edition
Practical PowerShell Programming for Professional People - Extended EditionPractical PowerShell Programming for Professional People - Extended Edition
Practical PowerShell Programming for Professional People - Extended Edition
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Practical PowerShell Programming for Professional People - DerbyCon 4
Practical PowerShell Programming for Professional People - DerbyCon 4Practical PowerShell Programming for Professional People - DerbyCon 4
Practical PowerShell Programming for Professional People - DerbyCon 4
 
Slicing, Dicing, And Linting OpenAPI
Slicing, Dicing, And Linting OpenAPISlicing, Dicing, And Linting OpenAPI
Slicing, Dicing, And Linting OpenAPI
 
Variety of automated tests
Variety of automated testsVariety of automated tests
Variety of automated tests
 
IPC 2013 - High Performance PHP with HipHop
IPC 2013 - High Performance PHP with HipHopIPC 2013 - High Performance PHP with HipHop
IPC 2013 - High Performance PHP with HipHop
 
NLP using JavaScript Natural Library
NLP using JavaScript Natural LibraryNLP using JavaScript Natural Library
NLP using JavaScript Natural Library
 
Getting started with Perl XS and Inline::C
Getting started with Perl XS and Inline::CGetting started with Perl XS and Inline::C
Getting started with Perl XS and Inline::C
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
 
Taking PHP To the next level
Taking PHP To the next levelTaking PHP To the next level
Taking PHP To the next level
 
Packer Genetics: The selfish code
Packer Genetics: The selfish codePacker Genetics: The selfish code
Packer Genetics: The selfish code
 
Gray Hat PowerShell - ShowMeCon 2015
Gray Hat PowerShell - ShowMeCon 2015Gray Hat PowerShell - ShowMeCon 2015
Gray Hat PowerShell - ShowMeCon 2015
 
ShaREing Is Caring
ShaREing Is CaringShaREing Is Caring
ShaREing Is Caring
 
Natural Language Processing sample code by Aiden
Natural Language Processing sample code by AidenNatural Language Processing sample code by Aiden
Natural Language Processing sample code by Aiden
 
Not Your Fathers C - C Application Development In 2016
Not Your Fathers C - C Application Development In 2016Not Your Fathers C - C Application Development In 2016
Not Your Fathers C - C Application Development In 2016
 

Similar to TAKING PHP SERIOUSLY - Keith Adams

Similar to TAKING PHP SERIOUSLY - Keith Adams (20)

Php
PhpPhp
Php
 
Php
PhpPhp
Php
 
Preparing code for Php 7 workshop
Preparing code for Php 7 workshopPreparing code for Php 7 workshop
Preparing code for Php 7 workshop
 
PHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckPHP from soup to nuts Course Deck
PHP from soup to nuts Course Deck
 
Wt unit 4 server side technology-2
Wt unit 4 server side technology-2Wt unit 4 server side technology-2
Wt unit 4 server side technology-2
 
Peek at PHP 7
Peek at PHP 7Peek at PHP 7
Peek at PHP 7
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
PHP MySQL Workshop - facehook
PHP MySQL Workshop - facehookPHP MySQL Workshop - facehook
PHP MySQL Workshop - facehook
 
What To Expect From PHP7
What To Expect From PHP7What To Expect From PHP7
What To Expect From PHP7
 
Intro about PHP,PHP Training in jaipur
Intro about PHP,PHP Training in jaipurIntro about PHP,PHP Training in jaipur
Intro about PHP,PHP Training in jaipur
 
Introduction About PHP
 Introduction About PHP Introduction About PHP
Introduction About PHP
 
PHP Basics and Demo HackU
PHP Basics and Demo HackUPHP Basics and Demo HackU
PHP Basics and Demo HackU
 
Basics of PHP
Basics of PHPBasics of PHP
Basics of PHP
 
HHVM and Hack: A quick introduction
HHVM and Hack: A quick introductionHHVM and Hack: A quick introduction
HHVM and Hack: A quick introduction
 
50 shades of PHP
50 shades of PHP50 shades of PHP
50 shades of PHP
 
What's new in PHP 7.1
What's new in PHP 7.1What's new in PHP 7.1
What's new in PHP 7.1
 
Prersentation
PrersentationPrersentation
Prersentation
 
Php internal architecture
Php internal architecturePhp internal architecture
Php internal architecture
 
Hsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdfHsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdf
 
PHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityPHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing Insanity
 

More from Hermes Alves

PROPOSTA COPERGAS ARARIPINA.pdf
PROPOSTA COPERGAS ARARIPINA.pdfPROPOSTA COPERGAS ARARIPINA.pdf
PROPOSTA COPERGAS ARARIPINA.pdfHermes Alves
 
araripina-com-br-midia-kit-2014.ppt.pdf
araripina-com-br-midia-kit-2014.ppt.pdfararipina-com-br-midia-kit-2014.ppt.pdf
araripina-com-br-midia-kit-2014.ppt.pdfHermes Alves
 
O Panorama Industrial do Sertao do Araripe
O Panorama Industrial do Sertao do AraripeO Panorama Industrial do Sertao do Araripe
O Panorama Industrial do Sertao do AraripeHermes Alves
 
Codigo de postura do municipio
Codigo de postura do municipioCodigo de postura do municipio
Codigo de postura do municipioHermes Alves
 
1º Encontro de Blogueiros do Araripe - Blogosfera em debate
1º Encontro de Blogueiros do Araripe - Blogosfera em debate1º Encontro de Blogueiros do Araripe - Blogosfera em debate
1º Encontro de Blogueiros do Araripe - Blogosfera em debateHermes Alves
 
Cdl monitoramento-eletrônico-araripina-bb.compressed
Cdl monitoramento-eletrônico-araripina-bb.compressedCdl monitoramento-eletrônico-araripina-bb.compressed
Cdl monitoramento-eletrônico-araripina-bb.compressedHermes Alves
 
Estatuto da CDL de Araripina Pernambuco
Estatuto da CDL de Araripina PernambucoEstatuto da CDL de Araripina Pernambuco
Estatuto da CDL de Araripina PernambucoHermes Alves
 
Monitoramento eletrônico de Araripina Pernambuco
Monitoramento eletrônico de Araripina PernambucoMonitoramento eletrônico de Araripina Pernambuco
Monitoramento eletrônico de Araripina PernambucoHermes Alves
 
10 anos de planejamento para o Comércio de Araripina
10 anos de planejamento para o Comércio de Araripina10 anos de planejamento para o Comércio de Araripina
10 anos de planejamento para o Comércio de AraripinaHermes Alves
 
Treinamento E-commerce Softagon
Treinamento E-commerce SoftagonTreinamento E-commerce Softagon
Treinamento E-commerce SoftagonHermes Alves
 
Streaming.dyb.fm tarefas-vendas 2
Streaming.dyb.fm tarefas-vendas 2Streaming.dyb.fm tarefas-vendas 2
Streaming.dyb.fm tarefas-vendas 2Hermes Alves
 
Take photo with kinect and share on facebook fan page, for windows or linux.
Take photo with kinect and share on facebook fan page, for windows or linux. Take photo with kinect and share on facebook fan page, for windows or linux.
Take photo with kinect and share on facebook fan page, for windows or linux. Hermes Alves
 
Resultados alcancandos marco-2014 casadaconstrucaope.com.br
Resultados alcancandos marco-2014 casadaconstrucaope.com.brResultados alcancandos marco-2014 casadaconstrucaope.com.br
Resultados alcancandos marco-2014 casadaconstrucaope.com.brHermes Alves
 
Region andina colombiana
Region andina colombianaRegion andina colombiana
Region andina colombianaHermes Alves
 
Orinoquia en Colombia
Orinoquia en ColombiaOrinoquia en Colombia
Orinoquia en ColombiaHermes Alves
 
Fortaleza y sus playas
Fortaleza y sus playasFortaleza y sus playas
Fortaleza y sus playasHermes Alves
 
Inovação na Uniclinic do Araripe
Inovação na Uniclinic do AraripeInovação na Uniclinic do Araripe
Inovação na Uniclinic do AraripeHermes Alves
 
Alcance de público alvo para o Xerife
Alcance de público alvo para o XerifeAlcance de público alvo para o Xerife
Alcance de público alvo para o XerifeHermes Alves
 
Rouge Esmalteria em Araripina
Rouge Esmalteria em AraripinaRouge Esmalteria em Araripina
Rouge Esmalteria em AraripinaHermes Alves
 

More from Hermes Alves (20)

PROPOSTA COPERGAS ARARIPINA.pdf
PROPOSTA COPERGAS ARARIPINA.pdfPROPOSTA COPERGAS ARARIPINA.pdf
PROPOSTA COPERGAS ARARIPINA.pdf
 
araripina-com-br-midia-kit-2014.ppt.pdf
araripina-com-br-midia-kit-2014.ppt.pdfararipina-com-br-midia-kit-2014.ppt.pdf
araripina-com-br-midia-kit-2014.ppt.pdf
 
O Panorama Industrial do Sertao do Araripe
O Panorama Industrial do Sertao do AraripeO Panorama Industrial do Sertao do Araripe
O Panorama Industrial do Sertao do Araripe
 
Codigo de postura do municipio
Codigo de postura do municipioCodigo de postura do municipio
Codigo de postura do municipio
 
1º Encontro de Blogueiros do Araripe - Blogosfera em debate
1º Encontro de Blogueiros do Araripe - Blogosfera em debate1º Encontro de Blogueiros do Araripe - Blogosfera em debate
1º Encontro de Blogueiros do Araripe - Blogosfera em debate
 
Cdl monitoramento-eletrônico-araripina-bb.compressed
Cdl monitoramento-eletrônico-araripina-bb.compressedCdl monitoramento-eletrônico-araripina-bb.compressed
Cdl monitoramento-eletrônico-araripina-bb.compressed
 
Estatuto da CDL de Araripina Pernambuco
Estatuto da CDL de Araripina PernambucoEstatuto da CDL de Araripina Pernambuco
Estatuto da CDL de Araripina Pernambuco
 
Monitoramento eletrônico de Araripina Pernambuco
Monitoramento eletrônico de Araripina PernambucoMonitoramento eletrônico de Araripina Pernambuco
Monitoramento eletrônico de Araripina Pernambuco
 
10 anos de planejamento para o Comércio de Araripina
10 anos de planejamento para o Comércio de Araripina10 anos de planejamento para o Comércio de Araripina
10 anos de planejamento para o Comércio de Araripina
 
Treinamento E-commerce Softagon
Treinamento E-commerce SoftagonTreinamento E-commerce Softagon
Treinamento E-commerce Softagon
 
Streaming.dyb.fm tarefas-vendas 2
Streaming.dyb.fm tarefas-vendas 2Streaming.dyb.fm tarefas-vendas 2
Streaming.dyb.fm tarefas-vendas 2
 
Take photo with kinect and share on facebook fan page, for windows or linux.
Take photo with kinect and share on facebook fan page, for windows or linux. Take photo with kinect and share on facebook fan page, for windows or linux.
Take photo with kinect and share on facebook fan page, for windows or linux.
 
Resultados alcancandos marco-2014 casadaconstrucaope.com.br
Resultados alcancandos marco-2014 casadaconstrucaope.com.brResultados alcancandos marco-2014 casadaconstrucaope.com.br
Resultados alcancandos marco-2014 casadaconstrucaope.com.br
 
Region andina colombiana
Region andina colombianaRegion andina colombiana
Region andina colombiana
 
Orinoquia en Colombia
Orinoquia en ColombiaOrinoquia en Colombia
Orinoquia en Colombia
 
Fortaleza y sus playas
Fortaleza y sus playasFortaleza y sus playas
Fortaleza y sus playas
 
Inovação na Uniclinic do Araripe
Inovação na Uniclinic do AraripeInovação na Uniclinic do Araripe
Inovação na Uniclinic do Araripe
 
Alcance de público alvo para o Xerife
Alcance de público alvo para o XerifeAlcance de público alvo para o Xerife
Alcance de público alvo para o Xerife
 
Rouge Esmalteria em Araripina
Rouge Esmalteria em AraripinaRouge Esmalteria em Araripina
Rouge Esmalteria em Araripina
 
Documento
DocumentoDocumento
Documento
 

Recently uploaded

Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 

Recently uploaded (20)

Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 

TAKING PHP SERIOUSLY - Keith Adams

  • 3. What this talk is •  Experience report •  Apologia •  Qualified advocacy •  A surprise.
  • 4. What this talk is not •  “Network effects”/”Legacy” •  “Right tool for the job” •  tautological •  some tools really are bad •  PHP might be such a tool •  “Worse is better” •  pace Richard Gabriel •  Better is better •  Most people think of UNIX as “better” nowadays
  • 5. Recent changes •  Traits (ala Scala) •  Closures •  Generators (yield statement) •  The HipHop VM (hhvm) is fast •  https://github.com/facebook/hiphop-php/ •  https://www.hhvm.com •  ...and we want it to run your code •  http://www.hhvm.com/blog/?p=875
  • 6. Conventional Wisdom on PHP •  “PHP: A fractal of bad design” •  http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/ •  “[ ] You have reinvented PHP better, but that’s still no justification” •  http://colinm.org/language_checklist.html •  Etc.
  • 7. And yet... •  A lot of software that has changed the world has been rendered in PHP •  Mediawiki •  Facebook •  Wordpress •  Drupal •  This is at least interesting •  Should they really have been written in Haskell? •  Does PHP make projects more or less successful?
  • 8. Facebook’s PHP Codebase •  x * 105 files •  y * 107 LoC •  10 releases per week •  Anecdotally, good engineers are astonishingly productive in PHP
  • 9. The Case Against PHP •  Unexpected behaviors $x  /  0                      //  =>  bool(false)     “11abcd”  +  “1xy”  //  =>  int(12)   “0123”  +  “3456”    //  =>  int(3579)   “0123”  |  “3456”    //  =>  string(“3577”)  
  • 10. The Case Against PHP (2) •  Schizophrenia about value/reference semantics    /*          *  Probably  copy  $a  into  foo’s  0’th  param.        *  Unless  $a  is  a  user-­‐defined  object;  and  unless        *  foo’s  definition  specifies  that  arg  0  is  by          *  reference.        */      foo($a);  
  • 11. The Case Against PHP (3) •  Reliance on reference-counting •  String, array need O(1) logical copies •  User-defined classes have destructors that run at a deterministic time •  Some programs use the RAII idiom from C++ •  Heavily constrains implementation
  • 12. The Case Against PHP (4) •  Inconsistent, dangerous standard library •  array_map vs. array_reduce argument orders •  array_merge •  mysql_escape_string vs. (sigh) mysql_real_escape_string
  • 13. The Case Against PHP: “Guilty” •  It’s all true! •  These are “unforced errors” •  Most other languages do better •  You would want to avoid them in a PHP Reboot
  • 14. In Defense of PHP •  PHP gets three important things really right •  Programmer workflow •  State •  Concurrency
  • 15. Workflow •  Save, reload-the-page •  Short feedback cycle •  Optimizes most precious resource of all: programmer short-term memory
  • 16. State •  PHP requests always start with empty heap, namespace •  Cross-request state must be saved explicitly •  Filesystem, memcache, APC •  Affirmative virtue •  Typical FB requests spend 10ms initializing •  Reduces the cost of bugs •  Requests interact in limited ways •  Natural boundary for failure isolation
  • 17. Concurrency •  PHP requests execute in a single thread •  Concurrency happens via recursive web requests •  shared-nothing •  inputs/outputs copied •  Limits PHP’s applicable domain •  That’s actually good.
  • 19. The limits of conscious design •  Discovered or invented? •  Shrug •  In my opinion, more important than PHP’s problems •  They’re not available anywhere else Workflow StateConcurrency
  • 20. Pushing PHP further •  PHP engineer dare: rename this method •  Reorder the parameters for this method •  Remove this method that we think is not called anywhere
  • 21. Pushing PHP further (2) •  Enforce invariants: •  Only escaped strings are passed to build_query   •  A certain array() maps strings to Widgets
  • 22. Wait... •  A static type system? •  Verbose types, or incomprehensible error messages •  Either way hoses programmer productivity •  Millions of lines to migrate Workflow StateConcurrency
  • 23. We think we’ve solved this problem •  Introducing Hack •  Gradual typing for PHP •  Novel type inference system •  Real-time type-checking preserves PHP workflow •  Credit: Julien Verlaguet
  • 24. Hack •  Opt into typing via <?hh (instead of <?php) •  <?hh  //  strict   •  Almost-totally sound analysis •  Requires transitive closure of code has been hackified   •  <?hh   •  Tolerates missing annotations •  Assumes undeclared classes/functions exist, behave as implied by any types •  Disallows most “silly” PHP-isms
  • 25. Hack implementation EditorType Checker HHVM Filesystem inotify errors web requests source
  • 26. Changes from PHP <?hh   class  Point2  {      public  float  $x,  $y;      function  __construct(float  $x,  float  $y)  {          $this-­‐>x  =  $x;          $this-­‐>x  =  $y;      }   }  
  • 27. Changes from PHP <?hh   class  Point2  {      public  float  $x,  $y;      function  __construct(float  $x,  float  $y)  {          $this-­‐>x  =  $x;          $this-­‐>x  =  $y;  //  Whoopsy.  Didn’t  init  y      }   }  
  • 28. Changes from PHP <?hh   ...   function  meanOrigDistance(Point  $p,  Point  $q)      :  float  {      $distf  =  function(Point  $p)  :  float  {          return  sqrt($p-­‐>x  *  $p-­‐>x  +  $p-­‐>y  *  $p-­‐>y);      };      $pdist  =  $distf($p);      $qdist  =  $distf($q);      return  ($pdist  +  $qdist)  /  2;   }  
  • 29. Hack Type Cheatsheet •  Base PHP types: int,  MyClassName,  array,  ...   •  Nullable: ?int,  ?MyClassName   •  Mixed: anything (careful) •  Tuples: (int,  bool,  X)   •  Closures: (function(int):  int)   •  Collections: Vector<int>,  Map<string,  int>   •  Generics: A<T>,  foo<T>(T  $x):  T   •  Constraints: foo<T  as  A>(T  $x):  T  
  • 30. Hack Type Inference (1) •  Let’s infer the type of $x:
  • 31. Hack Type Inference (2) •  How does a type-system normally work? •  Type-variables are introduced •  A unification algorithm solves the type-variables (usually noted α) if (…) { $x = new A(); } else { $x = new B(); } type($x) = α unify(α, A) => α = A unify(α, B) => α = B ERROR
  • 32. Type inference in Hack •  Hack introduces unresolved types (noted U) if (…) { $x = new A(); } else { $x = new B(); } takesAnIFace($x); type($x) = α = U() $x = α = U(A); $x = α = U(A, B); $x = α = U(A, B) = IFace with (A ≤ IFace, B ≤ IFace)
  • 33. Error messages •  We can’t expect the user to understand all the type- inference •  The solution: keep the reason why we deduced a type and expose it to the user
  • 34. Hack •  “[ X ] You have reinvented PHP better, but that’s still no justification •  [ X ] The name of your language makes it impossible to find on Google” •  Many millions of lines converted •  Most new code in Hack •  Most PHP users at Facebook regularly check in Hack
  • 35. Postmodern PHP (2014-...) •  HipHop project provides great tools •  Fast VM •  Debugger •  Profiler •  Integrations with editors/IDEs •  Hack is a SoA gradual typing system •  Maintains all of PHP’s strengths •  Compare to your favorite “Dynamic Algol” Workflow StateConcurrency
  • 36. When PHP? •  Any time you might consider another “Dynamic Algol” language •  Python, Lua, JavaScript, Perl, Ruby, ... •  Server-side •  Request-oriented •  ...but want to preserve some of the option value of “BigLangs” •  Type system •  High-performance implementations
  • 37.
  • 39. Everyone’s favorite generics slide •  (Remember, “covariance” refers to type specifications for Type that accept T >= Type. “Contravariance” means Type that accept T <= Type.) •  We allow: •  Covariant function parameters •  Covariant arrays •  Constraints on type parameters (Foo<T as IFace> will error if T does not implement IFace) •  We don’t allow •  Contravariant function params (they don’t make sense) •  Covariant type parameters •  Remember, runtime throws everything away anyway, so perfwise, it’s type erasure.