SlideShare ist ein Scribd-Unternehmen logo
1 von 61
Downloaden Sie, um offline zu lesen
Hack the Future
Jason McCreary
"JMac"
@gonedark
Hack the Future - Jason McCreary - php[world] 2015
Talk the Talk
1. What is Hack?
2. Key Features of Hack
3. Unsupported PHP features in Hack
4. How can I use Hack?
5. Why Hack?
6. The Future
2
Hack the Future - Jason McCreary - php[world] 2015
But first…
A quick disclaimer.
3
Hack the Future - Jason McCreary - php[world] 2015
"Some things are going to be said."
4
Hack the Future - Jason McCreary - php[world] 2015
"This is not a talk to push Hack."
5
Hack the Future - Jason McCreary - php[world] 2015
"This is not a talk to shit on PHP."
6
Hack the Future - Jason McCreary - php[world] 2015
"This is a talk about the evolution of a language."
7
Hack the Future - Jason McCreary - php[world] 2015
What is Hack?
A very brief history.
8
Hack the Future - Jason McCreary - php[world] 2015
Brief History
• In 2009, Facebook released HipHop - a PHP compiler
• In 2010, Facebook introduced new features into PHP
• In 2012, Facebook began working on Hack
• In 2013, Facebook released HHVM - a HipHopVM
• In 2014, Facebook released Hack
9
Hack the Future - Jason McCreary - php[world] 2015
So what is Hack?
"Hack is a programming language for HHVM that
interoperates seamlessly with PHP."
10
Hack the Future - Jason McCreary - php[world] 2015
So what is Hack, really?
"Hack is a superset of PHP that runs on HHVM which
provides type checking."
11
Hack the Future - Jason McCreary - php[world] 2015
WTF Facebook?
Just use PHP.
12
Hack the Future - Jason McCreary - php[world] 2015
"Well, they do."
13
Hack the Future - Jason McCreary - php[world] 2015
"Facebook has millions of lines of PHP."
14
Hack the Future - Jason McCreary - php[world] 2015
"Instead of a rewrite or waiting or influencing the PHP
community, they made Hack."
15
Hack the Future - Jason McCreary - php[world] 2015
"The goal being to write cleaner, safer, and
refactorable code."
16
Hack the Future - Jason McCreary - php[world] 2015
Key Features
A deeper look at some of the features of Hack.
17
Hack the Future - Jason McCreary - php[world] 2015
Key Features in Hack
• Type Annotations
• Additional types
• Generics and Nullable
• Asynchronous programming
• Syntactic sugar
18
Hack the Future - Jason McCreary - php[world] 2015
Type Annotations
<?hh

// parameter type annotations
function output(string $str) {
echo 'Hello, ' . $str;
}
// return type annotations
function get_output(string $str): string {
return 'Hello, ' . $str;
}
19
Hack the Future - Jason McCreary - php[world] 2015
"Hack is not a statically typed language."
20
Hack the Future - Jason McCreary - php[world] 2015
"Hack allows more type hinting than PHP."
21
Hack the Future - Jason McCreary - php[world] 2015
"HHVM performs type checking before runtime which
ensures your code is type safe."
22
Hack the Future - Jason McCreary - php[world] 2015
Additional Types
• Collections
• Enums
• Shapes
• Tuples
• Custom Types
23
Hack the Future - Jason McCreary - php[world] 2015
The problem with array
"In PHP, arrays are used for all the things!"
24
Hack the Future - Jason McCreary - php[world] 201525
Hack the Future - Jason McCreary - php[world] 2015
The problem with array
<?php
// indexed, starting at 0
$arr1 = array(1, 2, 3);
// indexed, starting at 1
$arr2 = array(1 => 1, 2, 3);
// keyed, mix of integer keys and string keys
$arr3 = array("foo" => 1, 73 => 2, "bar" => 3);
// all array values are the same
26
Hack the Future - Jason McCreary - php[world] 2015
The problem with array
"Primitive obsession is a code smell!"
27
Hack the Future - Jason McCreary - php[world] 2015
The problem with array
"In PHP, arrays are primitives (i.e. non-objects)."
28
Hack the Future - Jason McCreary - php[world] 2015
The problem with array
$ php -r 'var_dump(is_object(array()));'
bool(false)
29
Hack the Future - Jason McCreary - php[world] 2015
Collections
• Vector - an ordered, index collection
• Map - a key-based collection
• Set - an unordered, uniquely value collection
• Pair - an immutable, indexed, 2 element collection
• Both immutable and mutable versions
30
Hack the Future - Jason McCreary - php[world] 2015
Collections
<?hh


$vector = Vector {5, 10, 15};
$map = Map {"A" => 1, "B" => 2, "C" => 3};
$set = Set {"A", "B"};
31
Hack the Future - Jason McCreary - php[world] 2015
Enums
<?hh
enum DayOfWeek: int {
Sunday = 0;
Monday = 1;
Tuesday = 2;
Wednesday = 3;
Thursday = 4;
Friday = 5;
Saturday = 6;
}
echo DayOfWeek::Wednesday; // outputs 3
32
Hack the Future - Jason McCreary - php[world] 2015
Shapes
<?hh
// fixed size and type
// keyed collection of mixed values
$sh = shape('x' => 3, 'y' => 5);
echo $sh['x'] . ',' . $sh['y']; // outputs 3,5
33
Hack the Future - Jason McCreary - php[world] 2015
Tuples
<?hh
// fixed size and type, index array of mixed values
$tup = tuple('3', 2, 3, 4, 'hi');
echo $tup[1]; // outputs 2
unset($tup[0]); // error
$tup[5] = 'new value'; // error
$tup[4] = 'change value'; // ok, string to string
34
Hack the Future - Jason McCreary - php[world] 2015
Custom Types
<?hh

// define your own types
type MyInt = int;
type Point = (int, int);
35
Hack the Future - Jason McCreary - php[world] 2015
Generics and Nullable
• Generics - ability to parameterize the type of a class
or method and declare it upon instantiation
• Nullable - ability to declare a type allows null
36
Hack the Future - Jason McCreary - php[world] 2015
Generics
<?hh
class Box<T> {
protected T $data;
public function __construct(T $data) {
$this->data = $data;
}
public function getData(): T {
return $this->data;
}
}
37
Hack the Future - Jason McCreary - php[world] 2015
Nullable
<?hh
function check_not_null(?int $x): int {
if ($x === null) {
return -1;
} else {
return $x;
}
}
38
Hack the Future - Jason McCreary - php[world] 2015
Asynchronous Programming
<?hh
async function helloAfter($name, $timeout): Awaitable<string> {
await SleepWaitHandle::create($timeout * 1000000);
echo sprintf("hello %sn", $name);
}
async function run() {
$joe = helloAfter('Joe', 3);
$mike = helloAfter('Mike', 1);
await GenArrayWaitHandle::create(array($joe, $mike));
}
run()->join();
// prints:
// hello Mike
// hello Joe
39
Hack the Future - Jason McCreary - php[world] 2015
Syntactic Sugar
• Constructor Argument Promotion
• Lambdas
40
Hack the Future - Jason McCreary - php[world] 2015
Constructor Argument Promotion
<?php
class Person {
private string $name;
private int $age;
public function __construct(string $name, int $age) {
$this->name = $name;
$this->age = $age;
}
}
41
Hack the Future - Jason McCreary - php[world] 2015
Constructor Argument Promotion
<?hh
class Person {
public function __construct(public string $name,
protected int $age) {}
}
42
Hack the Future - Jason McCreary - php[world] 2015
Lambdas
<?php
$foo = function($x) {
return $x + 1;
}
$foo(12); // returns 13
$squared = array_map(function($x) {
return $x * $x;
}, array(1,2,3));
var_dump($squared); // $squared is array(1,4,9)
43
Hack the Future - Jason McCreary - php[world] 2015
Lambdas
<?hh
$foo = $x ==> $x + 1;
$foo(12); // returns 13
$squared = array_map($x ==> $x * $x, array(1,2,3));
var_dump($squared); // $squared is array(1,4,9)
44
Hack the Future - Jason McCreary - php[world] 2015
Unsupported PHP Features
The things Hack no likey.
45
Hack the Future - Jason McCreary - php[world] 2015
Unsupported PHP Features
• Alternative syntaxes: AND, OR, XOR, endif, etc.
• Dynamic features: eval, continue n, break n,

$$var, $obj->{$var}
• Top Level Code
• References
• Globals
• Case insensitive function calls
• Explicitly named constructors
46
Hack the Future - Jason McCreary - php[world] 2015
How can I use Hack?
What you need to do to start Hack’in.
47
Hack the Future - Jason McCreary - php[world] 2015
"Change <?php to <?hh"
48
Hack the Future - Jason McCreary - php[world] 2015
"You’re right, first install HHVM."
49
Hack the Future - Jason McCreary - php[world] 2015
"Then change <?php to <?hh!"
50
Hack the Future - Jason McCreary - php[world] 2015
Hack Modes
• Hack has three modes: strict, partial, and
decl
• strict - type checker will catch every type error
• partial - type checker checks code that uses types
• decl - allows strict code to call separate, legacy
code
• The default is partial
51
Hack the Future - Jason McCreary - php[world] 2015
Hack Modes
<?hh // strict
function example(int $x) {
echo "I'm so strict!";
}
52
Hack the Future - Jason McCreary - php[world] 2015
Why Hack?
Some reasons for using Hack.
53
Hack the Future - Jason McCreary - php[world] 2015
Reasons to Hack
• Code clarity
• Performance
• Language features, like Asynchronous Programming
• Evolution
54
Hack the Future - Jason McCreary - php[world] 2015
The Future
So bright, I gotta wear shades.
55
Hack the Future - Jason McCreary - php[world] 2015
Some things in PHP
• Variadic functions (PHP 5.6)
• Scalar type declarations (PHP 7)
• Return type declarations (PHP 7)
• Null coalesce operator (PHP 7)
• Deprecations: alternative syntax and named
constructors (PHP 7)
56
Hack the Future - Jason McCreary - php[world] 2015
Look familiar?
<?php
function add(int $x, int $y): int {
return $x + $y;
}
$nil = null;
$foo = $nil ?? add(2, 3);
57
Hack the Future - Jason McCreary - php[world] 2015
"Yeah, Hack had it first."
58
Hack the Future - Jason McCreary - php[world] 2015
"Hack, coming soon in PHP 7+."
59
Hack the Future - Jason McCreary - php[world] 2015
"This is evolution."
60
Hack the Future - Jason McCreary - php[world] 2015
Questions…
Ask now or tweet me @gonedark.
61

Weitere ähnliche Inhalte

Was ist angesagt?

Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Lorvent56
 

Was ist angesagt? (20)

Adventures in Laravel 5 SunshinePHP 2016 Tutorial
Adventures in Laravel 5 SunshinePHP 2016 TutorialAdventures in Laravel 5 SunshinePHP 2016 Tutorial
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5
 
Workshop Laravel 5.2
Workshop Laravel 5.2Workshop Laravel 5.2
Workshop Laravel 5.2
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)
 
Laravel for Web Artisans
Laravel for Web ArtisansLaravel for Web Artisans
Laravel for Web Artisans
 
All the Laravel Things – Up & Running to Making $$
All the Laravel Things – Up & Running to Making $$All the Laravel Things – Up & Running to Making $$
All the Laravel Things – Up & Running to Making $$
 
Laravel 5 New Features
Laravel 5 New FeaturesLaravel 5 New Features
Laravel 5 New Features
 
MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1
 
Intro to Laravel
Intro to LaravelIntro to Laravel
Intro to Laravel
 
Laravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello ProductionLaravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello Production
 
Laravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingLaravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routing
 
Laravel 5.4
Laravel 5.4 Laravel 5.4
Laravel 5.4
 
Laravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello ProductionLaravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello Production
 
Laravel.IO A Use-Case Architecture
Laravel.IO A Use-Case ArchitectureLaravel.IO A Use-Case Architecture
Laravel.IO A Use-Case Architecture
 
Laravel 5
Laravel 5Laravel 5
Laravel 5
 
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
 
Web Development with Laravel 5
Web Development with Laravel 5Web Development with Laravel 5
Web Development with Laravel 5
 
A introduction to Laravel framework
A introduction to Laravel frameworkA introduction to Laravel framework
A introduction to Laravel framework
 

Andere mochten auch

Andere mochten auch (20)

Zend Framework Foundations
Zend Framework FoundationsZend Framework Foundations
Zend Framework Foundations
 
Amp your site an intro to accelerated mobile pages
Amp your site  an intro to accelerated mobile pagesAmp your site  an intro to accelerated mobile pages
Amp your site an intro to accelerated mobile pages
 
Create, test, secure, repeat
Create, test, secure, repeatCreate, test, secure, repeat
Create, test, secure, repeat
 
php[world] 2015 Training - Laravel from the Ground Up
php[world] 2015 Training - Laravel from the Ground Upphp[world] 2015 Training - Laravel from the Ground Up
php[world] 2015 Training - Laravel from the Ground Up
 
Adding 1.21 Gigawatts to Applications with RabbitMQ (Bulgaria PHP 2016 - Tuto...
Adding 1.21 Gigawatts to Applications with RabbitMQ (Bulgaria PHP 2016 - Tuto...Adding 1.21 Gigawatts to Applications with RabbitMQ (Bulgaria PHP 2016 - Tuto...
Adding 1.21 Gigawatts to Applications with RabbitMQ (Bulgaria PHP 2016 - Tuto...
 
Engineer - Mastering the Art of Software
Engineer - Mastering the Art of SoftwareEngineer - Mastering the Art of Software
Engineer - Mastering the Art of Software
 
Presentation Bulgaria PHP
Presentation Bulgaria PHPPresentation Bulgaria PHP
Presentation Bulgaria PHP
 
Console Apps: php artisan forthe:win
Console Apps: php artisan forthe:win Console Apps: php artisan forthe:win
Console Apps: php artisan forthe:win
 
Dip Your Toes in the Sea of Security
Dip Your Toes in the Sea of SecurityDip Your Toes in the Sea of Security
Dip Your Toes in the Sea of Security
 
Code Coverage for Total Security in Application Migrations
Code Coverage for Total Security in Application MigrationsCode Coverage for Total Security in Application Migrations
Code Coverage for Total Security in Application Migrations
 
Git Empowered
Git EmpoweredGit Empowered
Git Empowered
 
Php extensions
Php extensionsPhp extensions
Php extensions
 
Conscious Coupling
Conscious CouplingConscious Coupling
Conscious Coupling
 
SunshinePHP 2017 - Making the most out of MySQL
SunshinePHP 2017 - Making the most out of MySQLSunshinePHP 2017 - Making the most out of MySQL
SunshinePHP 2017 - Making the most out of MySQL
 
200K+ reasons security is a must
200K+ reasons security is a must200K+ reasons security is a must
200K+ reasons security is a must
 
Modern sql
Modern sqlModern sql
Modern sql
 
PHP World DC 2015 - What Can Go Wrong with Agile Development and How to Fix It
PHP World DC 2015 - What Can Go Wrong with Agile Development and How to Fix ItPHP World DC 2015 - What Can Go Wrong with Agile Development and How to Fix It
PHP World DC 2015 - What Can Go Wrong with Agile Development and How to Fix It
 
Intermediate OOP in PHP
Intermediate OOP in PHPIntermediate OOP in PHP
Intermediate OOP in PHP
 
Enough suffering, fix your architecture!
Enough suffering, fix your architecture!Enough suffering, fix your architecture!
Enough suffering, fix your architecture!
 
Website Accessibility: It’s the Right Thing to do
Website Accessibility: It’s the Right Thing to doWebsite Accessibility: It’s the Right Thing to do
Website Accessibility: It’s the Right Thing to do
 

Ähnlich wie Hack the Future

A Gentle Introduction To Object Oriented Php
A Gentle Introduction To Object Oriented PhpA Gentle Introduction To Object Oriented Php
A Gentle Introduction To Object Oriented Php
Michael Girouard
 
DDD on example of Symfony (SfCampUA14)
DDD on example of Symfony (SfCampUA14)DDD on example of Symfony (SfCampUA14)
DDD on example of Symfony (SfCampUA14)
Oleg Zinchenko
 

Ähnlich wie Hack the Future (20)

2009-02 Oops!
2009-02 Oops!2009-02 Oops!
2009-02 Oops!
 
PHP unserialization vulnerabilities: What are we missing?
PHP unserialization vulnerabilities: What are we missing?PHP unserialization vulnerabilities: What are we missing?
PHP unserialization vulnerabilities: What are we missing?
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
 
Zend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample QuestionsZend Certification PHP 5 Sample Questions
Zend Certification PHP 5 Sample Questions
 
QA for PHP projects
QA for PHP projectsQA for PHP projects
QA for PHP projects
 
A Gentle Introduction To Object Oriented Php
A Gentle Introduction To Object Oriented PhpA Gentle Introduction To Object Oriented Php
A Gentle Introduction To Object Oriented Php
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
The why and how of moving to php 5.4
The why and how of moving to php 5.4The why and how of moving to php 5.4
The why and how of moving to php 5.4
 
501 - PHP MYSQL.pdf
501 - PHP MYSQL.pdf501 - PHP MYSQL.pdf
501 - PHP MYSQL.pdf
 
Dip Your Toes in the Sea of Security (PHP UK 2016)
Dip Your Toes in the Sea of Security (PHP UK 2016)Dip Your Toes in the Sea of Security (PHP UK 2016)
Dip Your Toes in the Sea of Security (PHP UK 2016)
 
Intro to Php Security
Intro to Php SecurityIntro to Php Security
Intro to Php Security
 
How to write not breakable unit tests
How to write not breakable unit testsHow to write not breakable unit tests
How to write not breakable unit tests
 
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег ЗинченкоWebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
 
Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016
 
Becoming a better WordPress Developer
Becoming a better WordPress DeveloperBecoming a better WordPress Developer
Becoming a better WordPress Developer
 
Symfony2 - OSIDays 2010
Symfony2 - OSIDays 2010Symfony2 - OSIDays 2010
Symfony2 - OSIDays 2010
 
Modern Web Development in Perl
Modern Web Development in PerlModern Web Development in Perl
Modern Web Development in Perl
 
The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015
 
Protect Your Payloads: Modern Keying Techniques
Protect Your Payloads: Modern Keying TechniquesProtect Your Payloads: Modern Keying Techniques
Protect Your Payloads: Modern Keying Techniques
 
DDD on example of Symfony (SfCampUA14)
DDD on example of Symfony (SfCampUA14)DDD on example of Symfony (SfCampUA14)
DDD on example of Symfony (SfCampUA14)
 

Mehr von Jason McCreary

Mehr von Jason McCreary (6)

BDD in iOS with Cedar
BDD in iOS with CedarBDD in iOS with Cedar
BDD in iOS with Cedar
 
Patterns, Code Smells, and The Pragmattic Programmer
Patterns, Code Smells, and The Pragmattic ProgrammerPatterns, Code Smells, and The Pragmattic Programmer
Patterns, Code Smells, and The Pragmattic Programmer
 
Cache, Workers, and Queues
Cache, Workers, and QueuesCache, Workers, and Queues
Cache, Workers, and Queues
 
21 Ways to Make WordPress Fast
21 Ways to Make WordPress Fast21 Ways to Make WordPress Fast
21 Ways to Make WordPress Fast
 
21 Ways to Make WordPress Fast
21 Ways to Make WordPress Fast21 Ways to Make WordPress Fast
21 Ways to Make WordPress Fast
 
Configuring WordPress for Multiple Environments
Configuring WordPress for Multiple EnvironmentsConfiguring WordPress for Multiple Environments
Configuring WordPress for Multiple Environments
 

Kürzlich hochgeladen

( Pune ) VIP Pimpri Chinchwad Call Girls 🎗️ 9352988975 Sizzling | Escorts | G...
( Pune ) VIP Pimpri Chinchwad Call Girls 🎗️ 9352988975 Sizzling | Escorts | G...( Pune ) VIP Pimpri Chinchwad Call Girls 🎗️ 9352988975 Sizzling | Escorts | G...
( Pune ) VIP Pimpri Chinchwad Call Girls 🎗️ 9352988975 Sizzling | Escorts | G...
nilamkumrai
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
imonikaupta
 
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men 🔝mehsana🔝 Escorts...
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men  🔝mehsana🔝   Escorts...➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men  🔝mehsana🔝   Escorts...
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men 🔝mehsana🔝 Escorts...
nirzagarg
 
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
Call Girls In Delhi Whatsup 9873940964 Enjoy Unlimited Pleasure
 

Kürzlich hochgeladen (20)

Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
 
( Pune ) VIP Pimpri Chinchwad Call Girls 🎗️ 9352988975 Sizzling | Escorts | G...
( Pune ) VIP Pimpri Chinchwad Call Girls 🎗️ 9352988975 Sizzling | Escorts | G...( Pune ) VIP Pimpri Chinchwad Call Girls 🎗️ 9352988975 Sizzling | Escorts | G...
( Pune ) VIP Pimpri Chinchwad Call Girls 🎗️ 9352988975 Sizzling | Escorts | G...
 
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 
Al Barsha Night Partner +0567686026 Call Girls Dubai
Al Barsha Night Partner +0567686026 Call Girls  DubaiAl Barsha Night Partner +0567686026 Call Girls  Dubai
Al Barsha Night Partner +0567686026 Call Girls Dubai
 
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
 
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
 
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
Russian Call Girls in %(+971524965298  )#  Call Girls in DubaiRussian Call Girls in %(+971524965298  )#  Call Girls in Dubai
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
 
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
 
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men 🔝mehsana🔝 Escorts...
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men  🔝mehsana🔝   Escorts...➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men  🔝mehsana🔝   Escorts...
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men 🔝mehsana🔝 Escorts...
 
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
valsad Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call Girls...
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 

Hack the Future

  • 1. Hack the Future Jason McCreary "JMac" @gonedark
  • 2. Hack the Future - Jason McCreary - php[world] 2015 Talk the Talk 1. What is Hack? 2. Key Features of Hack 3. Unsupported PHP features in Hack 4. How can I use Hack? 5. Why Hack? 6. The Future 2
  • 3. Hack the Future - Jason McCreary - php[world] 2015 But first… A quick disclaimer. 3
  • 4. Hack the Future - Jason McCreary - php[world] 2015 "Some things are going to be said." 4
  • 5. Hack the Future - Jason McCreary - php[world] 2015 "This is not a talk to push Hack." 5
  • 6. Hack the Future - Jason McCreary - php[world] 2015 "This is not a talk to shit on PHP." 6
  • 7. Hack the Future - Jason McCreary - php[world] 2015 "This is a talk about the evolution of a language." 7
  • 8. Hack the Future - Jason McCreary - php[world] 2015 What is Hack? A very brief history. 8
  • 9. Hack the Future - Jason McCreary - php[world] 2015 Brief History • In 2009, Facebook released HipHop - a PHP compiler • In 2010, Facebook introduced new features into PHP • In 2012, Facebook began working on Hack • In 2013, Facebook released HHVM - a HipHopVM • In 2014, Facebook released Hack 9
  • 10. Hack the Future - Jason McCreary - php[world] 2015 So what is Hack? "Hack is a programming language for HHVM that interoperates seamlessly with PHP." 10
  • 11. Hack the Future - Jason McCreary - php[world] 2015 So what is Hack, really? "Hack is a superset of PHP that runs on HHVM which provides type checking." 11
  • 12. Hack the Future - Jason McCreary - php[world] 2015 WTF Facebook? Just use PHP. 12
  • 13. Hack the Future - Jason McCreary - php[world] 2015 "Well, they do." 13
  • 14. Hack the Future - Jason McCreary - php[world] 2015 "Facebook has millions of lines of PHP." 14
  • 15. Hack the Future - Jason McCreary - php[world] 2015 "Instead of a rewrite or waiting or influencing the PHP community, they made Hack." 15
  • 16. Hack the Future - Jason McCreary - php[world] 2015 "The goal being to write cleaner, safer, and refactorable code." 16
  • 17. Hack the Future - Jason McCreary - php[world] 2015 Key Features A deeper look at some of the features of Hack. 17
  • 18. Hack the Future - Jason McCreary - php[world] 2015 Key Features in Hack • Type Annotations • Additional types • Generics and Nullable • Asynchronous programming • Syntactic sugar 18
  • 19. Hack the Future - Jason McCreary - php[world] 2015 Type Annotations <?hh
 // parameter type annotations function output(string $str) { echo 'Hello, ' . $str; } // return type annotations function get_output(string $str): string { return 'Hello, ' . $str; } 19
  • 20. Hack the Future - Jason McCreary - php[world] 2015 "Hack is not a statically typed language." 20
  • 21. Hack the Future - Jason McCreary - php[world] 2015 "Hack allows more type hinting than PHP." 21
  • 22. Hack the Future - Jason McCreary - php[world] 2015 "HHVM performs type checking before runtime which ensures your code is type safe." 22
  • 23. Hack the Future - Jason McCreary - php[world] 2015 Additional Types • Collections • Enums • Shapes • Tuples • Custom Types 23
  • 24. Hack the Future - Jason McCreary - php[world] 2015 The problem with array "In PHP, arrays are used for all the things!" 24
  • 25. Hack the Future - Jason McCreary - php[world] 201525
  • 26. Hack the Future - Jason McCreary - php[world] 2015 The problem with array <?php // indexed, starting at 0 $arr1 = array(1, 2, 3); // indexed, starting at 1 $arr2 = array(1 => 1, 2, 3); // keyed, mix of integer keys and string keys $arr3 = array("foo" => 1, 73 => 2, "bar" => 3); // all array values are the same 26
  • 27. Hack the Future - Jason McCreary - php[world] 2015 The problem with array "Primitive obsession is a code smell!" 27
  • 28. Hack the Future - Jason McCreary - php[world] 2015 The problem with array "In PHP, arrays are primitives (i.e. non-objects)." 28
  • 29. Hack the Future - Jason McCreary - php[world] 2015 The problem with array $ php -r 'var_dump(is_object(array()));' bool(false) 29
  • 30. Hack the Future - Jason McCreary - php[world] 2015 Collections • Vector - an ordered, index collection • Map - a key-based collection • Set - an unordered, uniquely value collection • Pair - an immutable, indexed, 2 element collection • Both immutable and mutable versions 30
  • 31. Hack the Future - Jason McCreary - php[world] 2015 Collections <?hh 
 $vector = Vector {5, 10, 15}; $map = Map {"A" => 1, "B" => 2, "C" => 3}; $set = Set {"A", "B"}; 31
  • 32. Hack the Future - Jason McCreary - php[world] 2015 Enums <?hh enum DayOfWeek: int { Sunday = 0; Monday = 1; Tuesday = 2; Wednesday = 3; Thursday = 4; Friday = 5; Saturday = 6; } echo DayOfWeek::Wednesday; // outputs 3 32
  • 33. Hack the Future - Jason McCreary - php[world] 2015 Shapes <?hh // fixed size and type // keyed collection of mixed values $sh = shape('x' => 3, 'y' => 5); echo $sh['x'] . ',' . $sh['y']; // outputs 3,5 33
  • 34. Hack the Future - Jason McCreary - php[world] 2015 Tuples <?hh // fixed size and type, index array of mixed values $tup = tuple('3', 2, 3, 4, 'hi'); echo $tup[1]; // outputs 2 unset($tup[0]); // error $tup[5] = 'new value'; // error $tup[4] = 'change value'; // ok, string to string 34
  • 35. Hack the Future - Jason McCreary - php[world] 2015 Custom Types <?hh
 // define your own types type MyInt = int; type Point = (int, int); 35
  • 36. Hack the Future - Jason McCreary - php[world] 2015 Generics and Nullable • Generics - ability to parameterize the type of a class or method and declare it upon instantiation • Nullable - ability to declare a type allows null 36
  • 37. Hack the Future - Jason McCreary - php[world] 2015 Generics <?hh class Box<T> { protected T $data; public function __construct(T $data) { $this->data = $data; } public function getData(): T { return $this->data; } } 37
  • 38. Hack the Future - Jason McCreary - php[world] 2015 Nullable <?hh function check_not_null(?int $x): int { if ($x === null) { return -1; } else { return $x; } } 38
  • 39. Hack the Future - Jason McCreary - php[world] 2015 Asynchronous Programming <?hh async function helloAfter($name, $timeout): Awaitable<string> { await SleepWaitHandle::create($timeout * 1000000); echo sprintf("hello %sn", $name); } async function run() { $joe = helloAfter('Joe', 3); $mike = helloAfter('Mike', 1); await GenArrayWaitHandle::create(array($joe, $mike)); } run()->join(); // prints: // hello Mike // hello Joe 39
  • 40. Hack the Future - Jason McCreary - php[world] 2015 Syntactic Sugar • Constructor Argument Promotion • Lambdas 40
  • 41. Hack the Future - Jason McCreary - php[world] 2015 Constructor Argument Promotion <?php class Person { private string $name; private int $age; public function __construct(string $name, int $age) { $this->name = $name; $this->age = $age; } } 41
  • 42. Hack the Future - Jason McCreary - php[world] 2015 Constructor Argument Promotion <?hh class Person { public function __construct(public string $name, protected int $age) {} } 42
  • 43. Hack the Future - Jason McCreary - php[world] 2015 Lambdas <?php $foo = function($x) { return $x + 1; } $foo(12); // returns 13 $squared = array_map(function($x) { return $x * $x; }, array(1,2,3)); var_dump($squared); // $squared is array(1,4,9) 43
  • 44. Hack the Future - Jason McCreary - php[world] 2015 Lambdas <?hh $foo = $x ==> $x + 1; $foo(12); // returns 13 $squared = array_map($x ==> $x * $x, array(1,2,3)); var_dump($squared); // $squared is array(1,4,9) 44
  • 45. Hack the Future - Jason McCreary - php[world] 2015 Unsupported PHP Features The things Hack no likey. 45
  • 46. Hack the Future - Jason McCreary - php[world] 2015 Unsupported PHP Features • Alternative syntaxes: AND, OR, XOR, endif, etc. • Dynamic features: eval, continue n, break n,
 $$var, $obj->{$var} • Top Level Code • References • Globals • Case insensitive function calls • Explicitly named constructors 46
  • 47. Hack the Future - Jason McCreary - php[world] 2015 How can I use Hack? What you need to do to start Hack’in. 47
  • 48. Hack the Future - Jason McCreary - php[world] 2015 "Change <?php to <?hh" 48
  • 49. Hack the Future - Jason McCreary - php[world] 2015 "You’re right, first install HHVM." 49
  • 50. Hack the Future - Jason McCreary - php[world] 2015 "Then change <?php to <?hh!" 50
  • 51. Hack the Future - Jason McCreary - php[world] 2015 Hack Modes • Hack has three modes: strict, partial, and decl • strict - type checker will catch every type error • partial - type checker checks code that uses types • decl - allows strict code to call separate, legacy code • The default is partial 51
  • 52. Hack the Future - Jason McCreary - php[world] 2015 Hack Modes <?hh // strict function example(int $x) { echo "I'm so strict!"; } 52
  • 53. Hack the Future - Jason McCreary - php[world] 2015 Why Hack? Some reasons for using Hack. 53
  • 54. Hack the Future - Jason McCreary - php[world] 2015 Reasons to Hack • Code clarity • Performance • Language features, like Asynchronous Programming • Evolution 54
  • 55. Hack the Future - Jason McCreary - php[world] 2015 The Future So bright, I gotta wear shades. 55
  • 56. Hack the Future - Jason McCreary - php[world] 2015 Some things in PHP • Variadic functions (PHP 5.6) • Scalar type declarations (PHP 7) • Return type declarations (PHP 7) • Null coalesce operator (PHP 7) • Deprecations: alternative syntax and named constructors (PHP 7) 56
  • 57. Hack the Future - Jason McCreary - php[world] 2015 Look familiar? <?php function add(int $x, int $y): int { return $x + $y; } $nil = null; $foo = $nil ?? add(2, 3); 57
  • 58. Hack the Future - Jason McCreary - php[world] 2015 "Yeah, Hack had it first." 58
  • 59. Hack the Future - Jason McCreary - php[world] 2015 "Hack, coming soon in PHP 7+." 59
  • 60. Hack the Future - Jason McCreary - php[world] 2015 "This is evolution." 60
  • 61. Hack the Future - Jason McCreary - php[world] 2015 Questions… Ask now or tweet me @gonedark. 61