SlideShare a Scribd company logo
Scott Sandler - June 2019
Scott Sandler
Senior Staff Engineer
@ Slack 2015 - Present
● Static type checker, hh_client
● Language Server Protocol
● VSCode, VIM, Emacs, and more
● Overview
● Static Type Checking
● Generics
○ Arrays
○ Hack Arrays
○ Shapes
● Standard Library
○ Pipeline
○ Typed Regex
● XHP
● Overview
● Static Type Checking
● Generics
○ Arrays
○ Hack Arrays
○ Shapes
● Standard Library
○ Pipeline
○ Typed Regex
● XHP
● Overview
● Static Type Checking
● Generics
○ Arrays
○ Hack Arrays
○ Shapes
● Standard Library
○ Pipeline
○ Typed Regex
● XHP
“Generic programming is a style of computer programming in
which algorithms are written in terms of types
to-be-specified-later that are then instantiated when needed
for specific types provided as parameters.”
- Wikipedia
Type Parameters like <T> allow classes, functions, and data
structures to act on multiple types
● Overview
● Static Type Checking
● Generics
○ Arrays
○ Hack Arrays
○ Shapes
● Standard Library
○ Pipeline
○ Typed Regex
● XHP
● Overview
● Static Type Checking
● Generics
○ Arrays
○ Hack Arrays
○ Shapes
● Standard Library
○ Pipeline
○ Typed Regex
● XHP
● Overview
● Static Type Checking
● Generics
○ Arrays
○ Hack Arrays
○ Shapes
● Standard Library
○ Pipeline
○ Typed Regex
● XHP
● Overview
● Static Type Checking
● Generics
○ Arrays
○ Hack Arrays
○ Shapes
● Standard Library
○ Pipeline
○ Typed Regex
● XHP
● Overview
● Static Type Checking
● Generics
○ Arrays
○ Hack Arrays
○ Shapes
● Standard Library
○ Pipeline
○ Typed Regex
● XHP
● Overview
● Static Type Checking
● Generics
○ Arrays
○ Hack Arrays
○ Shapes
● Standard Library
○ Pipeline
○ Typed Regex
● XHP
● Overview
● Static Type Checking
● Generics
○ Arrays
○ Hack Arrays
○ Shapes
● Standard Library
○ Pipeline
○ Typed Regex
● XHP
● Overview
● Static Type Checking
● Generics
○ Arrays
○ Hack Arrays
○ Shapes
● Standard Library
○ Pipeline
○ Typed Regex
● XHP
● Overview
● Static Type Checking
● Generics
○ Arrays
○ Hack Arrays
○ Shapes
● Standard Library
○ Pipeline
○ Typed Regex
● XHP
● Overview
● Static Type Checking
● Generics
○ Arrays
○ Hack Arrays
○ Shapes
● Standard Library
○ Pipeline
○ Typed Regex
● XHP
● Represent an array with known structure
● Named keys with known data types
○ Keys can be optional
● Structural subtyping
● Overview
● Static Type Checking
● Generics
○ Arrays
○ Hack Arrays
○ Shapes
● Standard Library
○ Pipeline
○ Typed Regex
● XHP
● Overview
● Static Type Checking
● Generics
○ Arrays
○ Hack Arrays
○ Shapes
● Standard Library
○ Pipeline
○ Typed Regex
● XHP
● Overview
● Static Type Checking
● Generics
○ Arrays
○ Hack Arrays
○ Shapes
● Standard Library
○ Pipeline
○ Typed Regex
● XHP
● Overview
● Static Type Checking
● Generics
○ Arrays
○ Hack Arrays
○ Shapes
● Standard Library
○ Pipeline
○ Typed Regex
● XHP
● Overview
● Static Type Checking
● Generics
○ Arrays
○ Hack Arrays
○ Shapes
● Standard Library
○ Pipeline
○ Typed Regex
● XHP
● Inconsistent Argument Order
○ array_map($callback, $array);
○ array_filter($array, $callback);
● Misleading return types
○ strpos() returns int OR false
● Overview
● Static Type Checking
● Generics
○ Arrays
○ Hack Arrays
○ Shapes
● Standard Library
○ Pipeline
○ Typed Regex
● XHP
Read from inside out…
or split into multiple lines and
name each intermediate value?
● Overview
● Static Type Checking
● Generics
○ Arrays
○ Hack Arrays
○ Shapes
● Standard Library
○ Pipeline
○ Typed Regex
● XHP
● Consistent Argument Order
● Consistent Return Types
○ null instead of false
● Namespaces:
○ Container Functions: Vec*, Dict*, Keyset*, C*
○ Basics: Str*, Regex*, Math*
○ More: IO*, PseudoRandom*, SecureRandom*
● |> Pipeline operator for chaining function calls
● Overview
● Static Type Checking
● Generics
○ Arrays
○ Hack Arrays
○ Shapes
● Standard Library
○ Pipeline
○ Typed Regex
● XHP
● Overview
● Static Type Checking
● Generics
○ Arrays
○ Hack Arrays
○ Shapes
● Standard Library
○ Pipeline
○ Typed Regex
● XHP
● Overview
● Static Type Checking
● Generics
○ Arrays
○ Hack Arrays
○ Shapes
● Standard Library
○ Pipeline
○ Typed Regex
● XHP
● Overview
● Static Type Checking
● Generics
○ Arrays
○ Hack Arrays
○ Shapes
● Standard Library
○ Pipeline
○ Typed Regex
● XHP
● async/await cooperative multi-tasking
● is/as keywords for type assertion
● lambdas
● enums
● <<__Memoize>> caching
● hackfmt
● Function Autoloading
● VSCode debugging
Migrating Slack
● <?php to <?hh
● Fix hh_client errors
● Blocking CI tests
○ hh_client
○ Linter
● Move code into functions
● Foundational Types
○ DB Shapes
○ Inferred returns
○ Untyped code
● Coverage Competition
● <?hh // strict
● Eliminate PHP deps
● HHVM 4.0 upgrade
Fix hh_client errors
● <?php to <?hh
● Fix hh_client errors
● Blocking CI tests
○ hh_client
○ Linter
● Move code into functions
● Foundational Types
○ DB Shapes
○ Inferred returns
○ Untyped code
● Coverage Competition
● <?hh // strict
● Eliminate PHP deps
● HHVM 4.0 upgrade
● Hundreds of bugs
● Convince typechecker
● <?php to <?hh
● Fix hh_client errors
● Blocking CI tests
○ hh_client
○ Linter
● Move code into functions
● Foundational Types
○ DB Shapes
○ Inferred returns
○ Untyped code
● Coverage Competition
● <?hh // strict
● Eliminate PHP deps
● HHVM 4.0 upgrade
● <?php to <?hh
● Fix hh_client errors
● Blocking CI tests
○ hh_client
○ Linter
● Move code into functions
● Foundational Types
○ DB Shapes
○ Inferred returns
○ Untyped code
● Coverage Competition
● <?hh // strict
● Eliminate PHP deps
● HHVM 4.0 upgrade
● <?php to <?hh
● Fix hh_client errors
● Blocking CI tests
○ hh_client
○ Linter
● Move code into functions
● Foundational Types
○ DB Shapes
○ Inferred returns
○ Untyped code
● Coverage Competition
● <?hh // strict
● Eliminate PHP deps
● HHVM 4.0 upgrade
● <?php to <?hh
● Fix hh_client errors
● Blocking CI tests
○ hh_client
○ Linter
● Move code into functions
● Foundational Types
○ DB Shapes
○ Inferred returns
○ Untyped code
● Coverage Competition
● <?hh // strict
● Eliminate PHP deps
● HHVM 4.0 upgrade
New Linter: HHAST
● Hack Abstract Syntax Tree
● More rigorous linters
● Migrations as well
Old Linter: PHP_CodeSniffer
● Stream of tokens
● Each linter is a mini-PHP
parser
● <?php to <?hh
● Fix hh_client errors
● Blocking CI tests
○ hh_client
○ Linter
● Move code into functions
● Foundational Types
○ DB Shapes
○ Inferred returns
○ Untyped code
● Coverage Competition
● <?hh // strict
● Eliminate PHP deps
● HHVM 4.0 upgrade
● <?php to <?hh
● Fix hh_client errors
● Blocking CI tests
○ hh_client
○ Linter
● Move code into
functions
● Foundational Types
○ DB Shapes
○ Inferred returns
○ Untyped code
● Coverage Competition
● <?hh // strict
● Eliminate PHP deps
● HHVM 4.0 upgrade
Foundational
Types
After: AsyncMysqlClient
● Shapes for each table
● Async queries
Before: mysqli
● Untyped arrays of strings
● Synchronous queries
● <?php to <?hh
● Fix hh_client errors
● Blocking CI tests
○ hh_client
○ Linter
● Move code into functions
● Foundational Types
○ DB Shapes
○ Inferred returns
○ Untyped code
● Coverage Competition
● <?hh // strict
● Eliminate PHP deps
● HHVM 4.0 upgrade
● <?php to <?hh
● Fix hh_client errors
● Blocking CI tests
○ hh_client
○ Linter
● Move code into functions
● Foundational Types
○ DB Shapes
○ Inferred returns
○ Untyped code
● Coverage Competition
● <?hh // strict
● Eliminate PHP deps
● HHVM 4.0 upgrade
● <?php to <?hh
● Fix hh_client errors
● Blocking CI tests
○ hh_client
○ Linter
● Move code into functions
● Foundational Types
○ DB Shapes
○ Inferred returns
○ Untyped code
● Coverage Competition
● <?hh // strict
● Eliminate PHP deps
● HHVM 4.0 upgrade
● <?php to <?hh
● Fix hh_client errors
● Blocking CI tests
○ hh_client
○ Linter
● Move code into functions
● Foundational Types
○ DB Shapes
○ Inferred returns
○ Untyped code
● Coverage Competition
● <?hh // strict
● Eliminate PHP deps
● HHVM 4.0 upgrade
Untyped code
● <?php to <?hh
● Fix hh_client errors
● Blocking CI tests
○ hh_client
○ Linter
● Move code into functions
● Foundational Types
○ DB Shapes
○ Inferred returns
○ Untyped code
● Coverage Competition
● <?hh // strict
● Eliminate PHP deps
● HHVM 4.0 upgrade
Untyped code
● <?php to <?hh
● Fix hh_client errors
● Blocking CI tests
○ hh_client
○ Linter
● Move code into functions
● Foundational Types
○ DB Shapes
○ Inferred returns
○ Untyped code
● Coverage Competition
● <?hh // strict
● Eliminate PHP deps
● HHVM 4.0 upgrade
Type Coverage
Colorized Type Coverage
● <?php to <?hh
● Fix hh_client errors
● Blocking CI tests
○ hh_client
○ Linter
● Move code into functions
● Foundational Types
○ DB Shapes
○ Inferred returns
○ Untyped code
● Coverage Competition
● <?hh // strict
● Eliminate PHP deps
● HHVM 4.0 upgrade
Coverage Numbers
● <?php to <?hh
● Fix hh_client errors
● Blocking CI tests
○ hh_client
○ Linter
● Move code into functions
● Foundational Types
○ DB Shapes
○ Inferred returns
○ Untyped code
● Coverage Competition
● <?hh // strict
● Eliminate PHP deps
● HHVM 4.0 upgrade
Track it and pipe it to Slack
● <?php to <?hh
● Fix hh_client errors
● Blocking CI tests
○ hh_client
○ Linter
● Move code into functions
● Foundational Types
○ DB Shapes
○ Inferred returns
○ Untyped code
● Coverage Competition
● <?hh // strict
● Eliminate PHP deps
● HHVM 4.0 upgrade
<?hh // strict
1. All functions and arguments must be typed
2. No top-level code
3. Other dynamicism like $GLOBALS banned
● <?php to <?hh
● Fix hh_client errors
● Blocking CI tests
○ hh_client
○ Linter
● Move code into functions
● Foundational Types
○ DB Shapes
○ Inferred returns
○ Untyped code
● Coverage Competition
● <?hh // strict
● Eliminate PHP deps
● HHVM 4.0 upgrade
Eliminate PHP Dependencies
1. Smarty to XHP migration
○ Smarty Parser -> hack-codegen
2. Other dependencies:
○ Convert to Hack
○ Remove dependency
○ Run as PHP7 web service
● <?php to <?hh
● Fix hh_client errors
● Blocking CI tests
○ hh_client
○ Linter
● Move code into functions
● Foundational Types
○ DB Shapes
○ Inferred returns
○ Untyped code
● Coverage Competition
● <?hh // strict
● Eliminate PHP deps
● HHVM 4.0 upgrade
HHVM 4.0 Upgrade
● <?php to <?hh
● Fix hh_client errors
● Blocking CI tests
○ hh_client
○ Linter
● Move code into functions
● Foundational Types
○ DB Shapes
○ Inferred returns
○ Untyped code
● Coverage Competition
● <?hh // strict
● Eliminate PHP deps
● HHVM 4.0 upgrade
● Thousands of bugs found and fixed
● Entire classes of problems eliminated
○ Call to undefined function
○ Missing include/require
○ Missing array keys
○ Missing null checks
● Developer Surveys
● Increased confidence
● Increased productivity
● “When the type checker passes, my code usually works on
the first try”
UI
Integration
Unit
UI
Integration
Unit
Types
● Types are the cheapest unit test
○ ...but only when you have a lot of them
● Types are the cheapest documentation
○ Especially complex types like shapes
● Typing is best done as part of feature work
Lessons Learned
Yes, this is possible
● Generics RFC
● Arrow functions in 7.4
● Property type hints
● JIT in PHP8
● Static analysis:
○ phan: https://github.com/phan/phan
○ phpstan: https://github.com/phpstan/phpstan
○ psalm: https://github.com/vimeo/psalm
● eval(), create_function(), extract(), compact()
● $GLOBAL variables
● $$variable variables
● call_user_func()
● &$references
Avoid PHP’s most dangerous features
PHP to Hack at Slack

More Related Content

Similar to PHP to Hack at Slack

Heterogenous Persistence
Heterogenous PersistenceHeterogenous Persistence
Heterogenous Persistence
Jervin Real
 
RESTful Machine Learning with Flask and TensorFlow Serving - Carlo Mazzaferro
RESTful Machine Learning with Flask and TensorFlow Serving - Carlo MazzaferroRESTful Machine Learning with Flask and TensorFlow Serving - Carlo Mazzaferro
RESTful Machine Learning with Flask and TensorFlow Serving - Carlo Mazzaferro
PyData
 
Let’s template
Let’s templateLet’s template
Let’s template
AllenKao7
 
The secret of PHP7's Performance
The secret of PHP7's Performance The secret of PHP7's Performance
The secret of PHP7's Performance
Xinchen Hui
 
Introduction to GraphQL with Ruby
Introduction to GraphQL with RubyIntroduction to GraphQL with Ruby
Introduction to GraphQL with Ruby
Digital Natives
 
My 10 favorite haxe language features in 30 mins
My 10 favorite haxe language features in 30 minsMy 10 favorite haxe language features in 30 mins
My 10 favorite haxe language features in 30 mins
Francis Bourre
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
pratik tambekar
 
Typed Drupal - A great combination of Drupal 8 and PHP 7
Typed Drupal - A great combination of Drupal 8 and PHP 7Typed Drupal - A great combination of Drupal 8 and PHP 7
Typed Drupal - A great combination of Drupal 8 and PHP 7
Aditya Ghan
 
Frankfurt TYPO3 User Group (FTUG) 2017.11.15
Frankfurt TYPO3 User Group (FTUG) 2017.11.15Frankfurt TYPO3 User Group (FTUG) 2017.11.15
Frankfurt TYPO3 User Group (FTUG) 2017.11.15
ManuelSelbach
 
Quality Assurance in PostgreSQL
Quality Assurance in PostgreSQLQuality Assurance in PostgreSQL
Quality Assurance in PostgreSQL
Aleksander Alekseev
 
Simplify Access to Data from Pivotal GemFire Using the GraphQL (G2QL) Extension
Simplify Access to Data from Pivotal GemFire Using the GraphQL (G2QL) ExtensionSimplify Access to Data from Pivotal GemFire Using the GraphQL (G2QL) Extension
Simplify Access to Data from Pivotal GemFire Using the GraphQL (G2QL) Extension
VMware Tanzu
 
Build real time stream processing applications using Apache Kafka
Build real time stream processing applications using Apache KafkaBuild real time stream processing applications using Apache Kafka
Build real time stream processing applications using Apache Kafka
Hotstar
 
Extract Method Refactoring Workshop (2016)
Extract Method Refactoring Workshop (2016)Extract Method Refactoring Workshop (2016)
Extract Method Refactoring Workshop (2016)
Peter Kofler
 
Goodpractice
GoodpracticeGoodpractice
Goodpractice
Lorna Mitchell
 
Php 5.6 vs Php 7 performance comparison
Php 5.6 vs Php 7 performance comparisonPhp 5.6 vs Php 7 performance comparison
Php 5.6 vs Php 7 performance comparison
Tu Pham
 
IDE and Toolset For Magento Development
IDE and Toolset For Magento DevelopmentIDE and Toolset For Magento Development
IDE and Toolset For Magento Development
Abid Malik
 
PHP 7X New Features
PHP 7X New FeaturesPHP 7X New Features
PHP 7X New Features
Thanh Tai
 
Enforcing API Design Rules for High Quality Code Generation
Enforcing API Design Rules for High Quality Code GenerationEnforcing API Design Rules for High Quality Code Generation
Enforcing API Design Rules for High Quality Code Generation
Tim Burks
 
Os Koziarsky
Os KoziarskyOs Koziarsky
Os Koziarsky
oscon2007
 
MariaDB Paris Workshop 2023 - Performance Optimization
MariaDB Paris Workshop 2023 - Performance OptimizationMariaDB Paris Workshop 2023 - Performance Optimization
MariaDB Paris Workshop 2023 - Performance Optimization
MariaDB plc
 

Similar to PHP to Hack at Slack (20)

Heterogenous Persistence
Heterogenous PersistenceHeterogenous Persistence
Heterogenous Persistence
 
RESTful Machine Learning with Flask and TensorFlow Serving - Carlo Mazzaferro
RESTful Machine Learning with Flask and TensorFlow Serving - Carlo MazzaferroRESTful Machine Learning with Flask and TensorFlow Serving - Carlo Mazzaferro
RESTful Machine Learning with Flask and TensorFlow Serving - Carlo Mazzaferro
 
Let’s template
Let’s templateLet’s template
Let’s template
 
The secret of PHP7's Performance
The secret of PHP7's Performance The secret of PHP7's Performance
The secret of PHP7's Performance
 
Introduction to GraphQL with Ruby
Introduction to GraphQL with RubyIntroduction to GraphQL with Ruby
Introduction to GraphQL with Ruby
 
My 10 favorite haxe language features in 30 mins
My 10 favorite haxe language features in 30 minsMy 10 favorite haxe language features in 30 mins
My 10 favorite haxe language features in 30 mins
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Typed Drupal - A great combination of Drupal 8 and PHP 7
Typed Drupal - A great combination of Drupal 8 and PHP 7Typed Drupal - A great combination of Drupal 8 and PHP 7
Typed Drupal - A great combination of Drupal 8 and PHP 7
 
Frankfurt TYPO3 User Group (FTUG) 2017.11.15
Frankfurt TYPO3 User Group (FTUG) 2017.11.15Frankfurt TYPO3 User Group (FTUG) 2017.11.15
Frankfurt TYPO3 User Group (FTUG) 2017.11.15
 
Quality Assurance in PostgreSQL
Quality Assurance in PostgreSQLQuality Assurance in PostgreSQL
Quality Assurance in PostgreSQL
 
Simplify Access to Data from Pivotal GemFire Using the GraphQL (G2QL) Extension
Simplify Access to Data from Pivotal GemFire Using the GraphQL (G2QL) ExtensionSimplify Access to Data from Pivotal GemFire Using the GraphQL (G2QL) Extension
Simplify Access to Data from Pivotal GemFire Using the GraphQL (G2QL) Extension
 
Build real time stream processing applications using Apache Kafka
Build real time stream processing applications using Apache KafkaBuild real time stream processing applications using Apache Kafka
Build real time stream processing applications using Apache Kafka
 
Extract Method Refactoring Workshop (2016)
Extract Method Refactoring Workshop (2016)Extract Method Refactoring Workshop (2016)
Extract Method Refactoring Workshop (2016)
 
Goodpractice
GoodpracticeGoodpractice
Goodpractice
 
Php 5.6 vs Php 7 performance comparison
Php 5.6 vs Php 7 performance comparisonPhp 5.6 vs Php 7 performance comparison
Php 5.6 vs Php 7 performance comparison
 
IDE and Toolset For Magento Development
IDE and Toolset For Magento DevelopmentIDE and Toolset For Magento Development
IDE and Toolset For Magento Development
 
PHP 7X New Features
PHP 7X New FeaturesPHP 7X New Features
PHP 7X New Features
 
Enforcing API Design Rules for High Quality Code Generation
Enforcing API Design Rules for High Quality Code GenerationEnforcing API Design Rules for High Quality Code Generation
Enforcing API Design Rules for High Quality Code Generation
 
Os Koziarsky
Os KoziarskyOs Koziarsky
Os Koziarsky
 
MariaDB Paris Workshop 2023 - Performance Optimization
MariaDB Paris Workshop 2023 - Performance OptimizationMariaDB Paris Workshop 2023 - Performance Optimization
MariaDB Paris Workshop 2023 - Performance Optimization
 

Recently uploaded

GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Zilliz
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
TIPNGVN2
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 

Recently uploaded (20)

GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 

PHP to Hack at Slack

  • 1. Scott Sandler - June 2019
  • 2. Scott Sandler Senior Staff Engineer @ Slack 2015 - Present
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9. ● Static type checker, hh_client ● Language Server Protocol ● VSCode, VIM, Emacs, and more ● Overview ● Static Type Checking ● Generics ○ Arrays ○ Hack Arrays ○ Shapes ● Standard Library ○ Pipeline ○ Typed Regex ● XHP
  • 10. ● Overview ● Static Type Checking ● Generics ○ Arrays ○ Hack Arrays ○ Shapes ● Standard Library ○ Pipeline ○ Typed Regex ● XHP
  • 11. ● Overview ● Static Type Checking ● Generics ○ Arrays ○ Hack Arrays ○ Shapes ● Standard Library ○ Pipeline ○ Typed Regex ● XHP
  • 12. “Generic programming is a style of computer programming in which algorithms are written in terms of types to-be-specified-later that are then instantiated when needed for specific types provided as parameters.” - Wikipedia Type Parameters like <T> allow classes, functions, and data structures to act on multiple types ● Overview ● Static Type Checking ● Generics ○ Arrays ○ Hack Arrays ○ Shapes ● Standard Library ○ Pipeline ○ Typed Regex ● XHP
  • 13. ● Overview ● Static Type Checking ● Generics ○ Arrays ○ Hack Arrays ○ Shapes ● Standard Library ○ Pipeline ○ Typed Regex ● XHP
  • 14. ● Overview ● Static Type Checking ● Generics ○ Arrays ○ Hack Arrays ○ Shapes ● Standard Library ○ Pipeline ○ Typed Regex ● XHP
  • 15. ● Overview ● Static Type Checking ● Generics ○ Arrays ○ Hack Arrays ○ Shapes ● Standard Library ○ Pipeline ○ Typed Regex ● XHP
  • 16. ● Overview ● Static Type Checking ● Generics ○ Arrays ○ Hack Arrays ○ Shapes ● Standard Library ○ Pipeline ○ Typed Regex ● XHP
  • 17. ● Overview ● Static Type Checking ● Generics ○ Arrays ○ Hack Arrays ○ Shapes ● Standard Library ○ Pipeline ○ Typed Regex ● XHP
  • 18. ● Overview ● Static Type Checking ● Generics ○ Arrays ○ Hack Arrays ○ Shapes ● Standard Library ○ Pipeline ○ Typed Regex ● XHP
  • 19. ● Overview ● Static Type Checking ● Generics ○ Arrays ○ Hack Arrays ○ Shapes ● Standard Library ○ Pipeline ○ Typed Regex ● XHP
  • 20. ● Overview ● Static Type Checking ● Generics ○ Arrays ○ Hack Arrays ○ Shapes ● Standard Library ○ Pipeline ○ Typed Regex ● XHP
  • 21. ● Overview ● Static Type Checking ● Generics ○ Arrays ○ Hack Arrays ○ Shapes ● Standard Library ○ Pipeline ○ Typed Regex ● XHP
  • 22. ● Represent an array with known structure ● Named keys with known data types ○ Keys can be optional ● Structural subtyping ● Overview ● Static Type Checking ● Generics ○ Arrays ○ Hack Arrays ○ Shapes ● Standard Library ○ Pipeline ○ Typed Regex ● XHP
  • 23. ● Overview ● Static Type Checking ● Generics ○ Arrays ○ Hack Arrays ○ Shapes ● Standard Library ○ Pipeline ○ Typed Regex ● XHP
  • 24. ● Overview ● Static Type Checking ● Generics ○ Arrays ○ Hack Arrays ○ Shapes ● Standard Library ○ Pipeline ○ Typed Regex ● XHP
  • 25. ● Overview ● Static Type Checking ● Generics ○ Arrays ○ Hack Arrays ○ Shapes ● Standard Library ○ Pipeline ○ Typed Regex ● XHP
  • 26. ● Overview ● Static Type Checking ● Generics ○ Arrays ○ Hack Arrays ○ Shapes ● Standard Library ○ Pipeline ○ Typed Regex ● XHP
  • 27.
  • 28. ● Inconsistent Argument Order ○ array_map($callback, $array); ○ array_filter($array, $callback); ● Misleading return types ○ strpos() returns int OR false ● Overview ● Static Type Checking ● Generics ○ Arrays ○ Hack Arrays ○ Shapes ● Standard Library ○ Pipeline ○ Typed Regex ● XHP
  • 29. Read from inside out… or split into multiple lines and name each intermediate value? ● Overview ● Static Type Checking ● Generics ○ Arrays ○ Hack Arrays ○ Shapes ● Standard Library ○ Pipeline ○ Typed Regex ● XHP
  • 30. ● Consistent Argument Order ● Consistent Return Types ○ null instead of false ● Namespaces: ○ Container Functions: Vec*, Dict*, Keyset*, C* ○ Basics: Str*, Regex*, Math* ○ More: IO*, PseudoRandom*, SecureRandom* ● |> Pipeline operator for chaining function calls ● Overview ● Static Type Checking ● Generics ○ Arrays ○ Hack Arrays ○ Shapes ● Standard Library ○ Pipeline ○ Typed Regex ● XHP
  • 31. ● Overview ● Static Type Checking ● Generics ○ Arrays ○ Hack Arrays ○ Shapes ● Standard Library ○ Pipeline ○ Typed Regex ● XHP
  • 32. ● Overview ● Static Type Checking ● Generics ○ Arrays ○ Hack Arrays ○ Shapes ● Standard Library ○ Pipeline ○ Typed Regex ● XHP
  • 33. ● Overview ● Static Type Checking ● Generics ○ Arrays ○ Hack Arrays ○ Shapes ● Standard Library ○ Pipeline ○ Typed Regex ● XHP
  • 34. ● async/await cooperative multi-tasking ● is/as keywords for type assertion ● lambdas ● enums ● <<__Memoize>> caching ● hackfmt ● Function Autoloading ● VSCode debugging
  • 36.
  • 37. ● <?php to <?hh ● Fix hh_client errors ● Blocking CI tests ○ hh_client ○ Linter ● Move code into functions ● Foundational Types ○ DB Shapes ○ Inferred returns ○ Untyped code ● Coverage Competition ● <?hh // strict ● Eliminate PHP deps ● HHVM 4.0 upgrade
  • 38. Fix hh_client errors ● <?php to <?hh ● Fix hh_client errors ● Blocking CI tests ○ hh_client ○ Linter ● Move code into functions ● Foundational Types ○ DB Shapes ○ Inferred returns ○ Untyped code ● Coverage Competition ● <?hh // strict ● Eliminate PHP deps ● HHVM 4.0 upgrade
  • 39. ● Hundreds of bugs ● Convince typechecker ● <?php to <?hh ● Fix hh_client errors ● Blocking CI tests ○ hh_client ○ Linter ● Move code into functions ● Foundational Types ○ DB Shapes ○ Inferred returns ○ Untyped code ● Coverage Competition ● <?hh // strict ● Eliminate PHP deps ● HHVM 4.0 upgrade
  • 40. ● <?php to <?hh ● Fix hh_client errors ● Blocking CI tests ○ hh_client ○ Linter ● Move code into functions ● Foundational Types ○ DB Shapes ○ Inferred returns ○ Untyped code ● Coverage Competition ● <?hh // strict ● Eliminate PHP deps ● HHVM 4.0 upgrade
  • 41. ● <?php to <?hh ● Fix hh_client errors ● Blocking CI tests ○ hh_client ○ Linter ● Move code into functions ● Foundational Types ○ DB Shapes ○ Inferred returns ○ Untyped code ● Coverage Competition ● <?hh // strict ● Eliminate PHP deps ● HHVM 4.0 upgrade
  • 42. ● <?php to <?hh ● Fix hh_client errors ● Blocking CI tests ○ hh_client ○ Linter ● Move code into functions ● Foundational Types ○ DB Shapes ○ Inferred returns ○ Untyped code ● Coverage Competition ● <?hh // strict ● Eliminate PHP deps ● HHVM 4.0 upgrade
  • 43. New Linter: HHAST ● Hack Abstract Syntax Tree ● More rigorous linters ● Migrations as well Old Linter: PHP_CodeSniffer ● Stream of tokens ● Each linter is a mini-PHP parser ● <?php to <?hh ● Fix hh_client errors ● Blocking CI tests ○ hh_client ○ Linter ● Move code into functions ● Foundational Types ○ DB Shapes ○ Inferred returns ○ Untyped code ● Coverage Competition ● <?hh // strict ● Eliminate PHP deps ● HHVM 4.0 upgrade
  • 44. ● <?php to <?hh ● Fix hh_client errors ● Blocking CI tests ○ hh_client ○ Linter ● Move code into functions ● Foundational Types ○ DB Shapes ○ Inferred returns ○ Untyped code ● Coverage Competition ● <?hh // strict ● Eliminate PHP deps ● HHVM 4.0 upgrade
  • 46. After: AsyncMysqlClient ● Shapes for each table ● Async queries Before: mysqli ● Untyped arrays of strings ● Synchronous queries ● <?php to <?hh ● Fix hh_client errors ● Blocking CI tests ○ hh_client ○ Linter ● Move code into functions ● Foundational Types ○ DB Shapes ○ Inferred returns ○ Untyped code ● Coverage Competition ● <?hh // strict ● Eliminate PHP deps ● HHVM 4.0 upgrade
  • 47. ● <?php to <?hh ● Fix hh_client errors ● Blocking CI tests ○ hh_client ○ Linter ● Move code into functions ● Foundational Types ○ DB Shapes ○ Inferred returns ○ Untyped code ● Coverage Competition ● <?hh // strict ● Eliminate PHP deps ● HHVM 4.0 upgrade
  • 48. ● <?php to <?hh ● Fix hh_client errors ● Blocking CI tests ○ hh_client ○ Linter ● Move code into functions ● Foundational Types ○ DB Shapes ○ Inferred returns ○ Untyped code ● Coverage Competition ● <?hh // strict ● Eliminate PHP deps ● HHVM 4.0 upgrade
  • 49. ● <?php to <?hh ● Fix hh_client errors ● Blocking CI tests ○ hh_client ○ Linter ● Move code into functions ● Foundational Types ○ DB Shapes ○ Inferred returns ○ Untyped code ● Coverage Competition ● <?hh // strict ● Eliminate PHP deps ● HHVM 4.0 upgrade
  • 50. Untyped code ● <?php to <?hh ● Fix hh_client errors ● Blocking CI tests ○ hh_client ○ Linter ● Move code into functions ● Foundational Types ○ DB Shapes ○ Inferred returns ○ Untyped code ● Coverage Competition ● <?hh // strict ● Eliminate PHP deps ● HHVM 4.0 upgrade
  • 51. Untyped code ● <?php to <?hh ● Fix hh_client errors ● Blocking CI tests ○ hh_client ○ Linter ● Move code into functions ● Foundational Types ○ DB Shapes ○ Inferred returns ○ Untyped code ● Coverage Competition ● <?hh // strict ● Eliminate PHP deps ● HHVM 4.0 upgrade
  • 53. Colorized Type Coverage ● <?php to <?hh ● Fix hh_client errors ● Blocking CI tests ○ hh_client ○ Linter ● Move code into functions ● Foundational Types ○ DB Shapes ○ Inferred returns ○ Untyped code ● Coverage Competition ● <?hh // strict ● Eliminate PHP deps ● HHVM 4.0 upgrade
  • 54. Coverage Numbers ● <?php to <?hh ● Fix hh_client errors ● Blocking CI tests ○ hh_client ○ Linter ● Move code into functions ● Foundational Types ○ DB Shapes ○ Inferred returns ○ Untyped code ● Coverage Competition ● <?hh // strict ● Eliminate PHP deps ● HHVM 4.0 upgrade
  • 55. Track it and pipe it to Slack ● <?php to <?hh ● Fix hh_client errors ● Blocking CI tests ○ hh_client ○ Linter ● Move code into functions ● Foundational Types ○ DB Shapes ○ Inferred returns ○ Untyped code ● Coverage Competition ● <?hh // strict ● Eliminate PHP deps ● HHVM 4.0 upgrade
  • 56. <?hh // strict 1. All functions and arguments must be typed 2. No top-level code 3. Other dynamicism like $GLOBALS banned ● <?php to <?hh ● Fix hh_client errors ● Blocking CI tests ○ hh_client ○ Linter ● Move code into functions ● Foundational Types ○ DB Shapes ○ Inferred returns ○ Untyped code ● Coverage Competition ● <?hh // strict ● Eliminate PHP deps ● HHVM 4.0 upgrade
  • 57. Eliminate PHP Dependencies 1. Smarty to XHP migration ○ Smarty Parser -> hack-codegen 2. Other dependencies: ○ Convert to Hack ○ Remove dependency ○ Run as PHP7 web service ● <?php to <?hh ● Fix hh_client errors ● Blocking CI tests ○ hh_client ○ Linter ● Move code into functions ● Foundational Types ○ DB Shapes ○ Inferred returns ○ Untyped code ● Coverage Competition ● <?hh // strict ● Eliminate PHP deps ● HHVM 4.0 upgrade
  • 58. HHVM 4.0 Upgrade ● <?php to <?hh ● Fix hh_client errors ● Blocking CI tests ○ hh_client ○ Linter ● Move code into functions ● Foundational Types ○ DB Shapes ○ Inferred returns ○ Untyped code ● Coverage Competition ● <?hh // strict ● Eliminate PHP deps ● HHVM 4.0 upgrade
  • 59.
  • 60. ● Thousands of bugs found and fixed ● Entire classes of problems eliminated ○ Call to undefined function ○ Missing include/require ○ Missing array keys ○ Missing null checks
  • 61. ● Developer Surveys ● Increased confidence ● Increased productivity ● “When the type checker passes, my code usually works on the first try”
  • 62.
  • 65. ● Types are the cheapest unit test ○ ...but only when you have a lot of them ● Types are the cheapest documentation ○ Especially complex types like shapes ● Typing is best done as part of feature work Lessons Learned
  • 66.
  • 67.
  • 68. Yes, this is possible ● Generics RFC ● Arrow functions in 7.4 ● Property type hints ● JIT in PHP8 ● Static analysis: ○ phan: https://github.com/phan/phan ○ phpstan: https://github.com/phpstan/phpstan ○ psalm: https://github.com/vimeo/psalm
  • 69. ● eval(), create_function(), extract(), compact() ● $GLOBAL variables ● $$variable variables ● call_user_func() ● &$references Avoid PHP’s most dangerous features