Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Hack (programming language)

From Wikipedia, the free encyclopedia
Programming language
Not to be confused withHaxe.
Hack
Hack logo, featuring white lowercase "hack" letters on a black background, with stylized triangular geometric shapes on the left
ParadigmsMulti-paradigm:imperative,functional,object-oriented,procedural,reflective
FamilyPHP
Designed byJulien Verlaguet, Alok Menghrajani, Drew Paroski, others[1]
DeveloperMeta Platforms
First appeared2014; 11 years ago (2014)
Stable release
4.172 Edit this on Wikidata / 2 November 2022; 3 years ago (2 November 2022)
Typing disciplineStatic,dynamic,weak,gradual
OSCross-platform
LicenseMIT[2]
Websitehacklang.org
Influenced by
PHP,OCaml,Java,C#,Scala,Haskell

Hack is aprogramming language for theHipHop Virtual Machine (HHVM), created byMeta (formerly Facebook) as a dialect ofPHP. The language implementation isfree and open-source software, licensed under anMIT License.[2][3][4]

Hack allows use of bothdynamic typing andstatic typing. This kind of atype system is calledgradual typing, which is also implemented in other programming languages such asActionScript.[5] Hack's type system allows types to be specified forfunctionarguments, functionreturn values, andclass properties; however, types oflocal variables are always inferred and cannot be specified.[3][6]

History

[edit]

Hack was introduced on March 20, 2014.[7] Before the announcement of the new language, Facebook had already implemented the code and tested it on a large part of its web site.

Features

[edit]

Hack is designed to interoperate seamlessly with PHP, which is a widely used open-sourcescripting language that has a focus onweb development and can be embedded intoHTML. A majority of valid PHP scripts are also valid in Hack; however, many less-often used PHP features and language constructs are unsupported in Hack.[8]

Hack extends thetype hinting available in PHP 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.[6] 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.[9] However, a "strict" mode is available which requires such annotations, and thus enforces fully sound code.[10]

Syntax and semantics

[edit]

The basic file structure of a Hack script is similar to a PHP script with a few changes. A Hack file does not include the<?php opening markup tag and forbids using top-level declarations.[11] 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 viainclude,require, or the autoloader. Like other functions in Hack, the function names must be unique within a project – i.e., projects with multiple entrypoints can not both be calledmain:

<<__EntryPoint>>functionmain():void{echo'Hello, World!';}

The above script, similar to PHP, will be executed and the following output is sent to the browser:

Hello, World!

Unlike PHP, Hack and HTML code do not mix; eitherXHP or anothertemplate engine needs to be used.[8]

Functions

[edit]

Like PHP 7, Hack allows types to be specified for function arguments and function return values. Functions in Hack are thus annotated with types like the following:

// Hack functions are annotated with types.functionnegate(bool$x):bool{return!$x;}

See also

[edit]

References

[edit]
  1. ^O'Sullivan, Bryan (2014-03-28)."Where Credit Belongs for Hack".Archived from the original on 2021-03-01. Retrieved2019-02-06.
  2. ^ab"facebook/hhvm: hhvm, hphp, hack, License".GitHub.com.Meta Platforms. 2018-04-11.Archived from the original on 2019-01-07. Retrieved2019-02-06.
  3. ^abLockhart, Josh (2014-04-03)."Facebook's Hack, HHVM, and the future of PHP".O'Reilly Media.Archived from the original on 2019-01-07. Retrieved2019-02-06.
  4. ^Cade Metz (2014-03-20)."Facebook Introduces 'Hack,' the Programming Language of the Future".Wired.Archived from the original on 2014-03-28. Retrieved2019-02-06.
  5. ^Aseem Rastogi; Avik Chaudhuri; Basil Hosmer (January 2012)."The Ins and Outs of Gradual Type Inference"(PDF).Association for Computing Machinery (ACM).Archived(PDF) from the original on 2017-08-12. Retrieved2019-02-06.
  6. ^ab"Hack Manual: Hack and HHVM – Type Annotations".docs.hhvm.com.Archived from the original on 2018-08-02. Retrieved2019-02-06.
  7. ^Verlaguet, Julien; Menghrajani, GANDHI (2014-03-20)."Hack: a new programming language for HHVM".Facebook.Archived from the original on 2019-02-09. Retrieved2019-02-06.
  8. ^ab"Inconsistencies: Introduction".docs.hhvm.com. Archived fromthe original on 2019-04-04. Retrieved2019-04-04.
  9. ^"Hack Manual: Partial Mode".docs.hhvm.com.Archived from the original on 2018-11-19. Retrieved2019-02-06.
  10. ^"Hack Manual: Strict Mode".docs.hhvm.com.Archived from the original on 2018-11-19. Retrieved2019-02-06.
  11. ^Emmott, Fred (2019-02-11)."HHVM 4.0.0".hhvm.com.Archived from the original on 2021-05-14. Retrieved2019-05-02.

External links

[edit]
People
Resources
Implementations
Web frameworks
Testing
ORMs
IDEs
Widget toolkit
Products
and services
Facebook
Instagram
Hardware
Other
Former
People
Founders
Board
Current
Former
Executive
officers
Current
Former
Oversight
Board
Members
Board of
Trustees
Former
members
Notable
employees
Current
Former
Open source
Mass media
Concepts
Business
Lists
Related
Retrieved from "https://en.wikipedia.org/w/index.php?title=Hack_(programming_language)&oldid=1319111584"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp