From ac474904b1d49a3d2372a9283a6b7e7bf5bc7ac0 Mon Sep 17 00:00:00 2001 From: meinkej Date: Fri, 16 Oct 2015 11:10:26 +0100 Subject: [hack/de] Translation to German of the article about Hack --- de-de/hack-de.html.markdown | 320 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 320 insertions(+) create mode 100644 de-de/hack-de.html.markdown (limited to 'de-de/hack-de.html.markdown') diff --git a/de-de/hack-de.html.markdown b/de-de/hack-de.html.markdown new file mode 100644 index 00000000..330d0b9b --- /dev/null +++ b/de-de/hack-de.html.markdown @@ -0,0 +1,320 @@ +--- +language: Hack +contributors: + - ["Stephen Holdaway", "https://github.com/stecman"] + - ["David Lima", "https://github.com/davelima"] + - ["Jerome Meinke", "https://github.com/jmeinke"] +filename: learnhack.hh +--- + +Hack ist eine von Facebook neu entwickelte Programmiersprache auf Basis von PHP. +Sie wird von der HipHop Virtual Machine (HHVM) ausgeführt. Die HHVM kann +aufgrund der Ähnlichkeit der Programmiersprachen nicht nur Hack, sondern auch +PHP-Code ausführen. Der wesentliche Unterschied zu PHP besteht in der statischen +Typisierung der Sprache, die eine wesentlich höhere Performance erlaubt. + + +Hier werden nur Hack-spezifische Eigenschaften beschrieben. Details über PHP's +Syntax findet man im [PHP Artikel](http://learnxinyminutes.com/docs/php/) dieser +Seite. + +```php +id = $id; + } +} + + +// Kurzgefasste anonyme Funktionen (lambdas) +$multiplier = 5; +array_map($y ==> $y * $multiplier, [1, 2, 3]); + + +// Weitere, spezielle Felder (Generics) +// Diese kann man sich als ein zugreifbares Interface vorstellen +class Box +{ + protected T $data; + + public function __construct(T $data) { + $this->data = $data; + } + + public function getData(): T { + return $this->data; + } +} + +function openBox(Box $box) : int +{ + return $box->getData(); +} + + +// Formen +// +// Hack fügt das Konzept von Formen hinzu, wie struct-ähnliche arrays +// mit einer typ-geprüften Menge von Schlüsseln +type Point2D = shape('x' => int, 'y' => int); + +function distance(Point2D $a, Point2D $b) : float +{ + return sqrt(pow($b['x'] - $a['x'], 2) + pow($b['y'] - $a['y'], 2)); +} + +distance( + shape('x' => -1, 'y' => 5), + shape('x' => 2, 'y' => 50) +); + + +// Typen-Definition bzw. Aliasing +// +// Hack erlaubt es Typen zu definieren und sorgt somit für bessere Lesbarkeit +newtype VectorArray = array>; + +// Ein Tupel mit zwei Integern +newtype Point = (int, int); + +function addPoints(Point $p1, Point $p2) : Point +{ + return tuple($p1[0] + $p2[0], $p1[1] + $p2[1]); +} + +addPoints( + tuple(1, 2), + tuple(5, 6) +); + + +// Erstklassige Aufzählungen (enums) +enum RoadType : int +{ + Road = 0; + Street = 1; + Avenue = 2; + Boulevard = 3; +} + +function getRoadType() : RoadType +{ + return RoadType::Avenue; +} + + +// Automatische Erstellung von Klassen-Eigenschaften durch Konstruktor-Argumente +// +// Wiederkehrende Definitionen von Klassen-Eigenschaften können durch die Hack- +// Syntax vermieden werden. Hack erlaubt es die Klassen-Eigenschaften über +// Argumente des Konstruktors zu definieren. +class ArgumentPromotion +{ + public function __construct(public string $name, + protected int $age, + private bool $isAwesome) {} +} + +class WithoutArgumentPromotion +{ + public string $name; + + protected int $age; + + private bool $isAwesome; + + public function __construct(string $name, int $age, bool $isAwesome) + { + $this->name = $name; + $this->age = $age; + $this->isAwesome = $isAwesome; + } +} + + +// Kooperatives Multitasking +// +// Die Schlüsselworte "async" and "await" führen Multitasking ein. +// Achtung, hier werden keine Threads benutzt, sondern nur Aktivität getauscht. +async function cooperativePrint(int $start, int $end) : Awaitable +{ + for ($i = $start; $i <= $end; $i++) { + echo "$i "; + + // Geben anderen Tasks die Möglichkeit aktiv zu werden + await RescheduleWaitHandle::create(RescheduleWaitHandle::QUEUE_DEFAULT, 0); + } +} + +// Die Ausgabe von folgendem Code ist "1 4 7 2 5 8 3 6 9" +AwaitAllWaitHandle::fromArray([ + cooperativePrint(1, 3), + cooperativePrint(4, 6), + cooperativePrint(7, 9) +])->getWaitHandle()->join(); + + +// Attribute +// +// Attribute repräsentieren eine Form von Metadaten für Funktionen. +// Hack bietet Spezial-Attribute, die nützliche Eigenschaften mit sich bringen. + +// Das __Memoize Attribut erlaubt es die Ausgabe einer Funktion zu cachen. +<<__Memoize>> +function doExpensiveTask() : ?string +{ + return file_get_contents('http://example.com'); +} + +// Der Funktionsrumpf wird im Folgenden nur ein einziges mal ausgeführt: +doExpensiveTask(); +doExpensiveTask(); + + +// Das __ConsistentConstruct Attribut signalisiert dem type-checker, dass +// die Funktionsdeklaration von __construct für alle Unterklassen dieselbe ist. +<<__ConsistentConstruct>> +class ConsistentFoo +{ + public function __construct(int $x, float $y) + { + // ... + } + + public function someMethod() + { + // ... + } +} + +class ConsistentBar extends ConsistentFoo +{ + public function __construct(int $x, float $y) + { + // Der Type-checker erzwingt den Aufruf des Eltern-Klassen-Konstruktors + parent::__construct($x, $y); + + // ... + } + + // Das __Override Attribut ist ein optionales Signal an den Type-Checker, + // das erzwingt, dass die annotierte Methode die Methode der Eltern-Klasse + // oder des Traits verändert. + <<__Override>> + public function someMethod() + { + // ... + } +} + +class InvalidFooSubclass extends ConsistentFoo +{ + // Wenn der Konstruktor der Eltern-Klasse nicht übernommen wird, + // wird der Type-Checker einen Fehler ausgeben: + // + // "This object is of type ConsistentBaz. It is incompatible with this object + // of type ConsistentFoo because some of their methods are incompatible" + // + public function __construct(float $x) + { + // ... + } + + // Auch bei der Benutzung des __Override Attributs für eine nicht veränderte + // Methode wird vom Type-Checker eine Fehler ausgegeben: + // + // "InvalidFooSubclass::otherMethod() is marked as override; no non-private + // parent definition found or overridden parent is defined in non-> + public function otherMethod() + { + // ... + } +} + +// Ein Trait ist ein Begriff aus der objektorientierten Programmierung und +// beschreibt eine wiederverwendbare Sammlung von Methoden und Attributen, +// ähnlich einer Klasse. + +// Anders als in PHP können Traits auch als Schnittstellen (Interfaces) +// implementiert werden und selbst Schnittstellen implementieren. +interface KittenInterface +{ + public function play() : void; +} + +trait CatTrait implements KittenInterface +{ + public function play() : void + { + // ... + } +} + +class Samuel +{ + use CatTrait; +} + + +$cat = new Samuel(); +$cat instanceof KittenInterface === true; // True + +``` + +## Weitere Informationen + +Die Hack [Programmiersprachen-Referenz](http://docs.hhvm.com/manual/de/hacklangref.php) +erklärt die neuen Eigenschaften der Sprache detailliert auf Englisch. Für +allgemeine Informationen kann man auch die offizielle Webseite [hacklang.org](http://hacklang.org/) +besuchen. + +Die offizielle Webseite [hhvm.com](http://hhvm.com/) bietet Infos zum Download +und zur Installation der HHVM. + +Hack's [nicht-untersützte PHP Syntax-Elemente](http://docs.hhvm.com/manual/en/hack.unsupported.php) +werden im offiziellen Handbuch beschrieben. -- cgit v1.2.3 From 12e513c70d5c8bd0d59784a4e6e6c3ae3708b04a Mon Sep 17 00:00:00 2001 From: meinkej Date: Sat, 12 Mar 2016 14:55:23 +0100 Subject: added a -de suffix to the filename, and a lang: de-de field --- de-de/hack-de.html.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'de-de/hack-de.html.markdown') diff --git a/de-de/hack-de.html.markdown b/de-de/hack-de.html.markdown index 330d0b9b..d85c8d86 100644 --- a/de-de/hack-de.html.markdown +++ b/de-de/hack-de.html.markdown @@ -1,10 +1,11 @@ --- language: Hack +lang: de-de contributors: - ["Stephen Holdaway", "https://github.com/stecman"] - ["David Lima", "https://github.com/davelima"] - ["Jerome Meinke", "https://github.com/jmeinke"] -filename: learnhack.hh +filename: learnhack-de.hh --- Hack ist eine von Facebook neu entwickelte Programmiersprache auf Basis von PHP. -- cgit v1.2.3 From e78b5924a7eb27589e8a8269ad45b4c83bd59d93 Mon Sep 17 00:00:00 2001 From: ven Date: Sun, 13 Mar 2016 10:40:11 +0100 Subject: jmeinke is a translator --- de-de/hack-de.html.markdown | 1 + 1 file changed, 1 insertion(+) (limited to 'de-de/hack-de.html.markdown') diff --git a/de-de/hack-de.html.markdown b/de-de/hack-de.html.markdown index d85c8d86..42428130 100644 --- a/de-de/hack-de.html.markdown +++ b/de-de/hack-de.html.markdown @@ -4,6 +4,7 @@ lang: de-de contributors: - ["Stephen Holdaway", "https://github.com/stecman"] - ["David Lima", "https://github.com/davelima"] +translators: - ["Jerome Meinke", "https://github.com/jmeinke"] filename: learnhack-de.hh --- -- cgit v1.2.3