SlideShare ist ein Scribd-Unternehmen logo
1 von 25
Agenda
 What is the Hack Language ?
 Hack Modes
 Type Annotations
 Nullable
 Generics
 Collections
 Type Aliasing
 Constructor Argument Promotion
 PHP to Hack Conversion DEMO
Not on Agenda, but interesting
 Async - asynchronous programming support via
async/await
 XHP – an extension of the PHP and Hack syntax
where XML elements/blocks become valid
expressions
 Lamba expressions – a more advanced version of PHP
closures
What is the Hack Language ?
 Language for HHVM that interoperates with PHP
 Developed and used by Facebook
 Open-Sourced in March 2014
 Basically, PHP with a ton of extra features
 Hack = Fast development cycle of PHP + discipline of
strong typing
 Combines strong typing with weak typing => gradual
typing (you can strong type only the parts you want)
 Write cleaner/safer code while maintaining good
compatibility with existing PHP codebases
What is the Hack Language ? (II)
 Hack code uses “<?hh” instead of “<?php”. Not
mandatory but, if you do it, you won’t be able to jump
between Hack and HTML anymore
 Hack and PHP can coexist in the same project. Good if
you want an incremental switch to Hack.
 PHP code can call Hack code and vice-versa
 Closing tags (“?>”) are not supported
 Naming your files “*.hh” can be a good practice
Hack Modes (I)
 Intended for maximum flexibility converting PHP to
Hack
 Helps when running “hackificator”
 Each file can have only one Hack mode
 Default is “partial”
 Declared at the top: “<?hh // strict”
Hack Modes (II)
 Strict:
 <?hh // strict
 Type checker will catch every error
 All code in this mode must be correctly annotated
 Code in strict mode cannot call non-Hack code.
Hack Modes (III)
 Partial:
 <?hh // partial
 <?hh
 Default mode
 Allows calling non-Hack code
 Allows ommitting some function parameters
Hack Modes (IV)
 Decl:
 <?hh // decl
 used when annotating old APIs
 Allows Hack code written in strict mode to call into legacy
code. Just like in partial mode, but without having to fix
reported problems
Type Annotations (I)
 Readability by helping other developers understand the
purpose and intention of the code. Many used
comments to do this, but Hack formalizes it instead
 Correctness by forbidding unsafe coding practices
 Make use of automatic and solid refactoring tools of a
strong-typed language.
Type Annotations (II)
 class MyExampleClass {
 public int $number;
 public CustomClass $myObject;
 private string $theName;
 protected array $mystuff;

 function doStuff(string $name, bool $withHate): string {
 if ($withHate && $name === 'Satan') {
 return '666 HAHA';
 }
 return '';
 }
 }
Type Annotations (III)
 Possible annotations:
 Primitive types: int, string, float, bool, array
 User-defined classes: MyClass, Vector<mytype>
 Generics: MyClass<T>
 Mixed: mixed
 Void: void
 Typed arrays: array<Foo>, array<string, array<string, MyClass>>
 Tuples: e.g. tuple(string, bool)
 XHP elements
 Closures: (function(type_1, type_2): return_type)
 Resources: resource
 this: this
Nullable
 Safer way to deal with nulls
 In type annotation, add “?” to the type to make it
nullable. e.g. ?string
 Normal PHP code does allow some annotation:
 public function doStuff(MyClass $obj)
 But passing null to this results in a fatal error
 So in Hack you can do this:
 public function doStuff(?MyClass $obj)
 It’s best not to abuse this feature, but to use it when you
really need it
Generics (I)
 Allows classes and methods to be parameterized
 Generics code can be statically checked for correctness
 Offers a great alternative against using a top-level object + a
bunch of instanceof calls + type casts
 In most languages, classes must be used as types. But Hack
allows primitives too
 They are immutable: once a type has been associated, it can
not be changed
 In Hack, objects can be used as types too
 Nullable types are also supported
 Interfaces and Traits support Generics too
 See docs for more details
Generics (II)
 class MyClass<K> {
 private K $param;
 public function __construct(K $param) {
 $this->param = $param;
 }
 public function getParameter(): K {
 return $this->param;
 }
 }
Collections (I)
 Classes specialized for data storage and retrieval
 PHP arrays are too general, they offer a “one-size-fits-all”
approach
 In both Hack and PHP, arrays are not objects. But
Collections are.
 Seeing the keyword "array" in a piece of code doesn't
make it clear how that array will be used
 But each Collection class is best suited for specific
situations.
 So code is clearer and, if used correctly, can be a
performance improvement
Collections (II)
 They are traversable with “foreach” loops
 Support bracket notations: $mycollection[$index]
 Since they are objects, they are not copied when passed
around as parameters
 They integrate and work very well with Generics
 Immutable variants of the Collection classes also exist.
This is to ensure that they are not changed when passed
around
 Classes are: Vector, Map, Set, Pair
 Immutable collections: ImmVector, ImmMap, ImmSet
Collections (III)
 Vector example:
 $vector = Vector {6, 5, 4, 9};
 $vector->add(97);
 $vector->add(31);
 $vector->get(1);
 $x = $vector[2];
 $vector->removeKey(2);
 $vector[] = 999;
 foreach ($vector as $key => $value) {...}
Collections (IV)
 Map example:
 $map = Map {“key1" => 1, “key2" => 2, “key3" => 3};
 $b = $map->get(“key2");
 $map->remove(“key2");
 $map->contains(“key1");
 foreach ($map as $key => $value) {...}
Type Aliasing
 Just like PHP has aliasing support in namespaces, so
does Hack provide the same functionality for any type
 Two modes of declaration:
 type MyType = string;
 newtype MyType = string;
 The 2nd is called “opaque aliasing” and is only visible in
the same file
 Composite types can also be declared:
 newtype Coordinate = (float, float);
 These are implemented as tuples, so that is how they must
be created in order to be used
Constructor Argument Promotion (I)
 Before:
 class User {
 private string $name;
 private string $email;
 private int $age;
 public function __construct(string $name, string $email, int $age)
{
 $this->name = $name;
 $this->email = $email;
 $this->age = $age;
 }
 }
Constructor Argument Promotion (II)
 After:
 class User {
 public function __construct(
 private string $name,
 private string $email,
 private int $age
 ) {}
 }
PHP to Hack
Conversion
DEMO
Q & A
Hack programming language

Weitere ähnliche Inhalte

Was ist angesagt?

Back to the Future with TypeScript
Back to the Future with TypeScriptBack to the Future with TypeScript
Back to the Future with TypeScriptAleš Najmann
 
C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)Olve Maudal
 
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...anshkhurana01
 
TDD in C - Recently Used List Kata
TDD in C - Recently Used List KataTDD in C - Recently Used List Kata
TDD in C - Recently Used List KataOlve Maudal
 
PHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityPHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityGeorgePeterBanyard
 
scala.reflect, Eugene Burmako
scala.reflect, Eugene Burmakoscala.reflect, Eugene Burmako
scala.reflect, Eugene BurmakoVasil Remeniuk
 
JavaScript 101 - Class 1
JavaScript 101 - Class 1JavaScript 101 - Class 1
JavaScript 101 - Class 1Robert Pearce
 
Methods of debugging - Atomate.net
Methods of debugging - Atomate.netMethods of debugging - Atomate.net
Methods of debugging - Atomate.netVitalie Chiperi
 
Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...Arthur Puthin
 
20 C programs
20 C programs20 C programs
20 C programsnavjoth
 
DDD on example of Symfony (Webcamp Odessa 2014)
DDD on example of Symfony (Webcamp Odessa 2014)DDD on example of Symfony (Webcamp Odessa 2014)
DDD on example of Symfony (Webcamp Odessa 2014)Oleg Zinchenko
 
Introduction to Dart
Introduction to DartIntroduction to Dart
Introduction to DartRamesh Nair
 
DTS s03e04 Typing
DTS s03e04 TypingDTS s03e04 Typing
DTS s03e04 TypingTuenti
 
Chap1introppt2php(finally done)
Chap1introppt2php(finally done)Chap1introppt2php(finally done)
Chap1introppt2php(finally done)monikadeshmane
 

Was ist angesagt? (20)

Back to the Future with TypeScript
Back to the Future with TypeScriptBack to the Future with TypeScript
Back to the Future with TypeScript
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
 
Lecture 9- Control Structures 1
Lecture 9- Control Structures 1Lecture 9- Control Structures 1
Lecture 9- Control Structures 1
 
C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)
 
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
 
TDD in C - Recently Used List Kata
TDD in C - Recently Used List KataTDD in C - Recently Used List Kata
TDD in C - Recently Used List Kata
 
PHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityPHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing Insanity
 
scala.reflect, Eugene Burmako
scala.reflect, Eugene Burmakoscala.reflect, Eugene Burmako
scala.reflect, Eugene Burmako
 
JavaScript 101 - Class 1
JavaScript 101 - Class 1JavaScript 101 - Class 1
JavaScript 101 - Class 1
 
Methods of debugging - Atomate.net
Methods of debugging - Atomate.netMethods of debugging - Atomate.net
Methods of debugging - Atomate.net
 
Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...Static types on javascript?! Type checking approaches to ensure healthy appli...
Static types on javascript?! Type checking approaches to ensure healthy appli...
 
Ruby
RubyRuby
Ruby
 
Php1
Php1Php1
Php1
 
PHP
PHPPHP
PHP
 
20 C programs
20 C programs20 C programs
20 C programs
 
DDD on example of Symfony (Webcamp Odessa 2014)
DDD on example of Symfony (Webcamp Odessa 2014)DDD on example of Symfony (Webcamp Odessa 2014)
DDD on example of Symfony (Webcamp Odessa 2014)
 
Introduction to Dart
Introduction to DartIntroduction to Dart
Introduction to Dart
 
DTS s03e04 Typing
DTS s03e04 TypingDTS s03e04 Typing
DTS s03e04 Typing
 
Chap1introppt2php(finally done)
Chap1introppt2php(finally done)Chap1introppt2php(finally done)
Chap1introppt2php(finally done)
 
Lecture 11 - Functions
Lecture 11 - FunctionsLecture 11 - Functions
Lecture 11 - Functions
 

Andere mochten auch

The World of PHP PSR Standards
The World of PHP PSR StandardsThe World of PHP PSR Standards
The World of PHP PSR StandardsRadu Murzea
 
SymfonyCon 2015 - A symphony of developers
SymfonyCon 2015 - A symphony of developersSymfonyCon 2015 - A symphony of developers
SymfonyCon 2015 - A symphony of developersRadu Murzea
 
PHP 7 - A look at the future
PHP 7 - A look at the futurePHP 7 - A look at the future
PHP 7 - A look at the futureRadu Murzea
 
God’s eye - Technology
God’s eye - TechnologyGod’s eye - Technology
God’s eye - TechnologyAkshit Mareedu
 
On taxonomies of code and how to hack it
On taxonomies of code and how to hack itOn taxonomies of code and how to hack it
On taxonomies of code and how to hack itparallellns
 
Introduction to ethical hacking
Introduction to ethical hackingIntroduction to ethical hacking
Introduction to ethical hackingankit sarode
 
the best hacking ppt
the best hacking pptthe best hacking ppt
the best hacking pptfuckubitches
 
30 Brilliant marketing growth hack cards.
30 Brilliant marketing growth hack cards.30 Brilliant marketing growth hack cards.
30 Brilliant marketing growth hack cards.ClavainSkade
 
Computer Hacking - An Introduction
Computer Hacking - An IntroductionComputer Hacking - An Introduction
Computer Hacking - An IntroductionJayaseelan Vejayon
 
Securing the Cloud
Securing the CloudSecuring the Cloud
Securing the CloudGGV Capital
 
10 Event Technology Trends to Watch in 2016
10 Event Technology Trends to Watch in 201610 Event Technology Trends to Watch in 2016
10 Event Technology Trends to Watch in 2016Eventbrite UK
 
Publishing Production: From the Desktop to the Cloud
Publishing Production: From the Desktop to the CloudPublishing Production: From the Desktop to the Cloud
Publishing Production: From the Desktop to the CloudDeanta
 
31 Best Growth Hacking Resources
31 Best Growth Hacking Resources31 Best Growth Hacking Resources
31 Best Growth Hacking ResourcesStephen Jeske
 

Andere mochten auch (14)

The World of PHP PSR Standards
The World of PHP PSR StandardsThe World of PHP PSR Standards
The World of PHP PSR Standards
 
SymfonyCon 2015 - A symphony of developers
SymfonyCon 2015 - A symphony of developersSymfonyCon 2015 - A symphony of developers
SymfonyCon 2015 - A symphony of developers
 
PHP 7 - A look at the future
PHP 7 - A look at the futurePHP 7 - A look at the future
PHP 7 - A look at the future
 
God’s eye - Technology
God’s eye - TechnologyGod’s eye - Technology
God’s eye - Technology
 
On taxonomies of code and how to hack it
On taxonomies of code and how to hack itOn taxonomies of code and how to hack it
On taxonomies of code and how to hack it
 
Introduction to ethical hacking
Introduction to ethical hackingIntroduction to ethical hacking
Introduction to ethical hacking
 
the best hacking ppt
the best hacking pptthe best hacking ppt
the best hacking ppt
 
30 Brilliant marketing growth hack cards.
30 Brilliant marketing growth hack cards.30 Brilliant marketing growth hack cards.
30 Brilliant marketing growth hack cards.
 
Computer Hacking - An Introduction
Computer Hacking - An IntroductionComputer Hacking - An Introduction
Computer Hacking - An Introduction
 
Securing the Cloud
Securing the CloudSecuring the Cloud
Securing the Cloud
 
Hacking ppt
Hacking pptHacking ppt
Hacking ppt
 
10 Event Technology Trends to Watch in 2016
10 Event Technology Trends to Watch in 201610 Event Technology Trends to Watch in 2016
10 Event Technology Trends to Watch in 2016
 
Publishing Production: From the Desktop to the Cloud
Publishing Production: From the Desktop to the CloudPublishing Production: From the Desktop to the Cloud
Publishing Production: From the Desktop to the Cloud
 
31 Best Growth Hacking Resources
31 Best Growth Hacking Resources31 Best Growth Hacking Resources
31 Best Growth Hacking Resources
 

Ähnlich wie Hack programming language

php&mysql with Ethical Hacking
php&mysql with Ethical Hackingphp&mysql with Ethical Hacking
php&mysql with Ethical HackingBCET
 
Embrace dynamic PHP
Embrace dynamic PHPEmbrace dynamic PHP
Embrace dynamic PHPPaul Houle
 
HHVM and Hack: A quick introduction
HHVM and Hack: A quick introductionHHVM and Hack: A quick introduction
HHVM and Hack: A quick introductionKuan Yen Heng
 
170517 damien gérard framework facebook
170517 damien gérard   framework facebook170517 damien gérard   framework facebook
170517 damien gérard framework facebookGeeks Anonymes
 
Why choose Hack/HHVM over PHP7
Why choose Hack/HHVM over PHP7Why choose Hack/HHVM over PHP7
Why choose Hack/HHVM over PHP7Yuji Otani
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial javaTpoint s
 
1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answersAkash Gawali
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Pythondn
 
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 DeckrICh morrow
 
Eight simple rules to writing secure PHP programs
Eight simple rules to writing secure PHP programsEight simple rules to writing secure PHP programs
Eight simple rules to writing secure PHP programsAleksandr Yampolskiy
 
Declaration programming 2017
Declaration programming 2017Declaration programming 2017
Declaration programming 2017Marke Greene
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to javaciklum_ods
 

Ähnlich wie Hack programming language (20)

php&mysql with Ethical Hacking
php&mysql with Ethical Hackingphp&mysql with Ethical Hacking
php&mysql with Ethical Hacking
 
Embrace dynamic PHP
Embrace dynamic PHPEmbrace dynamic PHP
Embrace dynamic PHP
 
HHVM and Hack: A quick introduction
HHVM and Hack: A quick introductionHHVM and Hack: A quick introduction
HHVM and Hack: A quick introduction
 
170517 damien gérard framework facebook
170517 damien gérard   framework facebook170517 damien gérard   framework facebook
170517 damien gérard framework facebook
 
Why choose Hack/HHVM over PHP7
Why choose Hack/HHVM over PHP7Why choose Hack/HHVM over PHP7
Why choose Hack/HHVM over PHP7
 
What is c language
What is c languageWhat is c language
What is c language
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
lab4_php
lab4_phplab4_php
lab4_php
 
lab4_php
lab4_phplab4_php
lab4_php
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Python
 
Clean Code
Clean CodeClean Code
Clean Code
 
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
 
Xtext Webinar
Xtext WebinarXtext Webinar
Xtext Webinar
 
Eight simple rules to writing secure PHP programs
Eight simple rules to writing secure PHP programsEight simple rules to writing secure PHP programs
Eight simple rules to writing secure PHP programs
 
Declaration programming 2017
Declaration programming 2017Declaration programming 2017
Declaration programming 2017
 
Clean code
Clean codeClean code
Clean code
 
Andy On Closures
Andy On ClosuresAndy On Closures
Andy On Closures
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 

Kürzlich hochgeladen

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 

Kürzlich hochgeladen (20)

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 

Hack programming language

  • 1.
  • 2. Agenda  What is the Hack Language ?  Hack Modes  Type Annotations  Nullable  Generics  Collections  Type Aliasing  Constructor Argument Promotion  PHP to Hack Conversion DEMO
  • 3. Not on Agenda, but interesting  Async - asynchronous programming support via async/await  XHP – an extension of the PHP and Hack syntax where XML elements/blocks become valid expressions  Lamba expressions – a more advanced version of PHP closures
  • 4. What is the Hack Language ?  Language for HHVM that interoperates with PHP  Developed and used by Facebook  Open-Sourced in March 2014  Basically, PHP with a ton of extra features  Hack = Fast development cycle of PHP + discipline of strong typing  Combines strong typing with weak typing => gradual typing (you can strong type only the parts you want)  Write cleaner/safer code while maintaining good compatibility with existing PHP codebases
  • 5. What is the Hack Language ? (II)  Hack code uses “<?hh” instead of “<?php”. Not mandatory but, if you do it, you won’t be able to jump between Hack and HTML anymore  Hack and PHP can coexist in the same project. Good if you want an incremental switch to Hack.  PHP code can call Hack code and vice-versa  Closing tags (“?>”) are not supported  Naming your files “*.hh” can be a good practice
  • 6. Hack Modes (I)  Intended for maximum flexibility converting PHP to Hack  Helps when running “hackificator”  Each file can have only one Hack mode  Default is “partial”  Declared at the top: “<?hh // strict”
  • 7. Hack Modes (II)  Strict:  <?hh // strict  Type checker will catch every error  All code in this mode must be correctly annotated  Code in strict mode cannot call non-Hack code.
  • 8. Hack Modes (III)  Partial:  <?hh // partial  <?hh  Default mode  Allows calling non-Hack code  Allows ommitting some function parameters
  • 9. Hack Modes (IV)  Decl:  <?hh // decl  used when annotating old APIs  Allows Hack code written in strict mode to call into legacy code. Just like in partial mode, but without having to fix reported problems
  • 10. Type Annotations (I)  Readability by helping other developers understand the purpose and intention of the code. Many used comments to do this, but Hack formalizes it instead  Correctness by forbidding unsafe coding practices  Make use of automatic and solid refactoring tools of a strong-typed language.
  • 11. Type Annotations (II)  class MyExampleClass {  public int $number;  public CustomClass $myObject;  private string $theName;  protected array $mystuff;   function doStuff(string $name, bool $withHate): string {  if ($withHate && $name === 'Satan') {  return '666 HAHA';  }  return '';  }  }
  • 12. Type Annotations (III)  Possible annotations:  Primitive types: int, string, float, bool, array  User-defined classes: MyClass, Vector<mytype>  Generics: MyClass<T>  Mixed: mixed  Void: void  Typed arrays: array<Foo>, array<string, array<string, MyClass>>  Tuples: e.g. tuple(string, bool)  XHP elements  Closures: (function(type_1, type_2): return_type)  Resources: resource  this: this
  • 13. Nullable  Safer way to deal with nulls  In type annotation, add “?” to the type to make it nullable. e.g. ?string  Normal PHP code does allow some annotation:  public function doStuff(MyClass $obj)  But passing null to this results in a fatal error  So in Hack you can do this:  public function doStuff(?MyClass $obj)  It’s best not to abuse this feature, but to use it when you really need it
  • 14. Generics (I)  Allows classes and methods to be parameterized  Generics code can be statically checked for correctness  Offers a great alternative against using a top-level object + a bunch of instanceof calls + type casts  In most languages, classes must be used as types. But Hack allows primitives too  They are immutable: once a type has been associated, it can not be changed  In Hack, objects can be used as types too  Nullable types are also supported  Interfaces and Traits support Generics too  See docs for more details
  • 15. Generics (II)  class MyClass<K> {  private K $param;  public function __construct(K $param) {  $this->param = $param;  }  public function getParameter(): K {  return $this->param;  }  }
  • 16. Collections (I)  Classes specialized for data storage and retrieval  PHP arrays are too general, they offer a “one-size-fits-all” approach  In both Hack and PHP, arrays are not objects. But Collections are.  Seeing the keyword "array" in a piece of code doesn't make it clear how that array will be used  But each Collection class is best suited for specific situations.  So code is clearer and, if used correctly, can be a performance improvement
  • 17. Collections (II)  They are traversable with “foreach” loops  Support bracket notations: $mycollection[$index]  Since they are objects, they are not copied when passed around as parameters  They integrate and work very well with Generics  Immutable variants of the Collection classes also exist. This is to ensure that they are not changed when passed around  Classes are: Vector, Map, Set, Pair  Immutable collections: ImmVector, ImmMap, ImmSet
  • 18. Collections (III)  Vector example:  $vector = Vector {6, 5, 4, 9};  $vector->add(97);  $vector->add(31);  $vector->get(1);  $x = $vector[2];  $vector->removeKey(2);  $vector[] = 999;  foreach ($vector as $key => $value) {...}
  • 19. Collections (IV)  Map example:  $map = Map {“key1" => 1, “key2" => 2, “key3" => 3};  $b = $map->get(“key2");  $map->remove(“key2");  $map->contains(“key1");  foreach ($map as $key => $value) {...}
  • 20. Type Aliasing  Just like PHP has aliasing support in namespaces, so does Hack provide the same functionality for any type  Two modes of declaration:  type MyType = string;  newtype MyType = string;  The 2nd is called “opaque aliasing” and is only visible in the same file  Composite types can also be declared:  newtype Coordinate = (float, float);  These are implemented as tuples, so that is how they must be created in order to be used
  • 21. Constructor Argument Promotion (I)  Before:  class User {  private string $name;  private string $email;  private int $age;  public function __construct(string $name, string $email, int $age) {  $this->name = $name;  $this->email = $email;  $this->age = $age;  }  }
  • 22. Constructor Argument Promotion (II)  After:  class User {  public function __construct(  private string $name,  private string $email,  private int $age  ) {}  }
  • 24. Q & A

Hinweis der Redaktion

  1. Alteratives: simpletest, behat
  2. Alteratives: simpletest, behat
  3. Alteratives: simpletest, behat
  4. Alteratives: simpletest, behat
  5. Alteratives: simpletest, behat
  6. Alteratives: simpletest, behat
  7. Alteratives: simpletest, behat
  8. Alteratives: simpletest, behat
  9. Alteratives: simpletest, behat
  10. Alteratives: simpletest, behat
  11. Alteratives: simpletest, behat
  12. Alteratives: simpletest, behat
  13. Alteratives: simpletest, behat
  14. Alteratives: simpletest, behat
  15. Alteratives: simpletest, behat
  16. Alteratives: simpletest, behat
  17. Alteratives: simpletest, behat
  18. Alteratives: simpletest, behat
  19. Alteratives: simpletest, behat
  20. Alteratives: simpletest, behat
  21. Alteratives: simpletest, behat
  22. Alteratives: simpletest, behat