Hack (programming language): Difference between revisions

Content deleted Content added
See also: rm Parrot link -- no direct relationship to Hack
Undid revision 1260410768 by 2600:1008:B12B:47DE:0:68:BEC5:E801 (talk) - reverted change that broke reference
 
(29 intermediate revisions by 26 users not shown)
Line 4:
| name = Hack
| logo = Hack (programming language) logo.svg
| logo size = x64px100px
| logo_altlogo alt = Hack logo, featuring white lowercase "hack" letters on a black background, with stylized triangular geometric shapes on the left
| released = 2014
| designer = Julien Verlaguet, Alok Menghrajani, Drew Paroski, and others<ref>{{cite web |url=http://www.serpentine.com/blog/2014/03/28/where-credit-belongs-for-hack/ |authorlast1=Bryan O'Sullivan |first1=Bryan |title=Where Credit Belongs for Hack |date=2014-03-28 |access-date=2019-02-06 |archive-date=2021-03-01 |archive-url=https://web.archive.org/web/20210301030703/http://www.serpentine.com/blog/2014/03/28/where-credit-belongs-for-hack/ |url-status=live }}</ref>
| developer = [[Meta Platforms]]
| paradigms = [[Multi-paradigm programming language|Multi-paradigm]]: [[Imperative programming|imperative]], [[Functional programming|functional]], [[Object-oriented programming|object-oriented]], [[Procedural programming|procedural]], [[Reflective programming|reflective]]
| typing = [[Static typing|Static]], [[Dynamic typing|dynamic]], [[Weak typing|weak]], [[Gradual_typing|gradual]]
| family = [[PHP]]
| released = {{Start date and age|2014}}
| latest release version = {{wikidata|property|edit|P548=Q2804309|P348}}
| latest release date = {{start date and age|{{wikidata|qualifier|single|P548=Q2804309|P348|P577}}}}
| typing = [[Static typing|Static]], [[Dynamic typing|dynamic]], [[WeakStrong and weak typing|weak]], [[Gradual_typingGradual typing|gradual]]
| programming language =
| platform =
| license = [[MIT License|MIT]]<ref name="license">{{cite web
| url = https://github.com/facebook/hhvm/blob/master/hphp/hack/LICENSE
| title = facebook/hhvm: hhvm /, hphp /, hack, / LICENSELicense
| date = 2018-04-11
| website = githubGitHub.com
| publisher = [[Meta Platforms]]
| access-date = 2019-02-06
Line 22 ⟶ 27:
| url-status = live
}}</ref>
| operating system = [[Cross-platform software|Cross-platform]]
| website = {{URL|https://hacklang.org/}}
| logo_size = 200px
| influenced_byinfluenced by = [[PHP]], [[OCaml]], [[Java (programming language)|Java]], [[C Sharp (programming language)|C#]], [[Scala (programming language)|Scala]], [[Haskell (programming language)|Haskell]]
| logo_alt = Hack logo, featuring white lowercase "hack" letters on a black background, with stylized triangular geometric shapes on the left
| influenced_by = [[PHP]], [[OCaml]], [[Java (programming language)|Java]], [[C Sharp (programming language)|C#]], [[Scala (programming language)|Scala]], [[Haskell (programming language)|Haskell]]
| operating_system = [[Cross-platform]]
}}
 
'''Hack''' is a [[programming language]] for the [[HipHop Virtual Machine]] (HHVM), created by [[Meta Platforms|Meta]] (formerly Facebook) as a dialect of [[PHP]]. The language implementation is [[Openfree and open-source software|open-source]], licensed under thean [[MIT License]].<ref name="license" /><ref name="oreilly">{{cite web
| url = http://radar.oreilly.com/2014/04/facebooks-hack-hhvm-and-the-future-of-php.html
| title = Facebook's Hack, HHVM, and the future of PHP
| date = 2014-04-03
| authorlast1 = Josh Lockhart |first1 = Josh
| publisher = [[O'Reilly Media]]
| access-date = 2019-02-06
Line 51 ⟶ 54:
}}</ref>
 
Hack allows programmers to use of both [[dynamic typing]] and [[static typing]]. This kind of a [[type systems|type system]] is called [[gradual typing]], which is also implemented in other programming languages such as [[ActionScript]].<ref>{{cite web
| url = https://www.cs.umd.edu/~avik/papers/iogti.pdf
| title = The Ins and Outs of Gradual Type Inference
Line 87 ⟶ 90:
| archive-url=https://web.archive.org/web/20190209124350/https://code.fb.com/developer-tools/hack-a-new-programming-language-for-hhvm/
| url-status=live
}}</ref> Before the announcement of the new programming language, Facebook had already implemented the code and tested it on a large portionpart of its web site.
 
==Features==
Hack is designed to interoperate seamlessly with PHP, which is a widely used open-source [[scripting language]] that has a focus on [[web development]] and can be embedded into [[HTML]]. A majority of valid PHP scripts are also valid in Hack; however, numerousmany less frequently-often used PHP features and language constructs are not supportedunsupported in Hack.<ref name="unsupported">{{cite web
| url = https://docs.hhvm.com/hhvm/inconsistencies/introduction
| title = Inconsistencies: Introduction
Line 100 ⟶ 103:
}}</ref>
 
Hack extends the [[type hinting]] available in PHP&nbsp;5 through the introduction of static typing, by adding new type hints (for example, for scalar types such as integer or string), as well as by extending the use of type hints (for example, for class properties or function return values). However, types of local variables cannot be specified.<ref name="hack.annotations" /> Since Hack uses a gradual typing system, in the default mode, type annotations are not mandatory even in places they cannot be inferred; the type system will assume the author is correct and admit the code.<ref>{{cite web
| url = https://docs.hhvm.com/hack/typechecker/modes#partial-mode
| title = Hack Manual: Partial Mode
Line 116 ⟶ 119:
| archive-url = https://web.archive.org/web/20181119215731/https://docs.hhvm.com/hack/typechecker/modes#strict-mode
| url-status = live
}}</ref>
 
== Syntax and semantics ==
Line 130 ⟶ 133:
| archive-url=https://web.archive.org/web/20210514021100/https://hhvm.com/blog/2019/02/11/hhvm-4.0.0.html
| url-status=live
}}</ref> Code must be placed in an entrypoint function. These are automatically executed if they are in the top-level file, but not if the file is included via <code>include</code>, <code>require</code>, or the autoloader. Like other functions in Hack, the function names must be unique within a project&nbsp; – i.e., projects with multiple entrypoints can not call both be called <code>main</code> :
 
<syntaxhighlight lang="php">
Line 163 ⟶ 166:
 
== References ==
{{Reflist|30em}}
 
== External links ==
Line 171 ⟶ 174:
* [http://www.phpsemantics.org/ KPHP: An Executable Formal Semantics for PHP]
 
{{Programming languages}}
{{PHP}}
{{FacebookMeta navboxPlatforms}}
{{Programming languages}}
 
[[Category:2014 software]]
Line 183 ⟶ 186:
[[Category:Scripting languages]]
[[Category:Statically typed programming languages]]
<!-- Hidden categories below -->
[[Category:Articles with example PHP code]]