forked from HaxeFoundation/HaxeManual
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01-introduction.tex
117 lines (77 loc) · 8.93 KB
/
01-introduction.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
\chapter{Introduction}
\label{introduction}
\state{NoContent}
\section{What is Haxe?}
\label{introduction-what-is-haxe}
\todo{Could we have a big Haxe logo in the First Manual Page (Introduction) under the menu (a bit like a book cover ?) It looks a bit empty now and is a landing page for "Manual"}
Haxe consists of a high-level, open source programming language and a compiler. It allows compilation of programs, written using an ECMAScript\footnote{http://www.ecma-international.org/publications/standards/Ecma-327.htm}-oriented syntax, to multiple target languages. Employing proper abstraction, it is possible to maintain a single code-base which compiles to multiple targets.
Haxe is strongly typed but the typing system can be subverted where required. Utilizing type information, the Haxe type system can detect errors at compile-time which would only be noticeable at run-time in the target language. Furthermore, type information can be used by the target generators to generate optimized and robust code.
Currently, there are nine supported target languages which allow for different use-cases:
\begin{center}
\begin{tabular}{| l | l | l |}
\hline
Name & Output type & Main usages \\ \hline
Javascript & Sourcecode & Browser, Desktop, Mobile, Server \\
Neko & Bytecode & Desktop, Server \\
PHP & Sourcecode & Server \\
Python & Sourcecode & Desktop, Server \\
C++ & Sourcecode & Desktop, Mobile, Server \\
Actionscript 3 & Sourcecode & Browser, Desktop, Mobile \\
Flash & Bytecode & Browser, Desktop, Mobile \\
Java & Sourcecode & Desktop, Server \\
C\# & Sourcecode & Desktop, Mobile, Server \\ \hline
\end{tabular}
\end{center}
The remainder of section \ref{introduction} gives a brief overview of what a Haxe program looks like and how Haxe evolved since its inception in 2005.
\Fullref{types} introduces the seven different kinds of types in Haxe and how they interact with each other. The discussion of types is continued in \Fullref{type-system}, where features like \emph{unification}, \emph{type parameters} and \emph{type inference} are explained.
\Fullref{class-field} is all about the structure of Haxe classes and, among other topics, deals with \emph{properties}, \emph{inline fields} and \emph{generic functions}.
In \Fullref{expression} we see how to actually get programs to do something by using \emph{expressions}.
\Fullref{lf} describes some of the Haxe features in detail such as \emph{pattern matching}, \emph{string interpolation} and \emph{dead code elimination}. This concludes the Haxe language reference.
We continue with the Haxe compiler reference, which first handles the basics in \Fullref{compiler-reference} before getting into the advanced features in \Fullref{cr-features}. Finally, we will venture into the exciting land of \emph{haxe macros} in \Fullref{macro} to see how some common tasks can be greatly simplified.
In the following chapter, \Fullref{std}, we explore important types and concepts from the Haxe Standard Library. We then learn about Haxe's package manager Haxelib in \Fullref{haxelib}.
Haxe abstracts away many target differences, but sometimes it is important to interact with a target directly, which is the subject of \Fullref{target-details}.
\section{About this Document}
\label{introduction-about-this-document}
This document is the official manual for Haxe 3. As such, it is not a beginner's tutorial and does not teach programming. However, the topics are roughly designed to be read in order and there are references to topics ``previously seen'' and topics ``yet to come''. In some cases, an earlier section makes use of the information of a later section if it simplifies the explanation. These references are linked accordingly and it should generally not be a problem to read ahead on other topics.
We use a lot of Haxe source code to keep a practical connection of theoretical matters. These code examples are often complete programs that come with a main function and can be compiled as-is. However, sometimes only the most important parts are shown.
Source code looks like this:
\begin{lstlisting}
Haxe code here
\end{lstlisting}
Occasionally, we demonstrate how Haxe code is generated, for which we usually show the \target{Javascript} target.
Furthermore, we define a set of terms in this document. Predominantly, this is done when introducing a new type or when a term is specific to Haxe. We do not define every new aspect we introduce, e.g. what a class is, to avoid cluttering the text. A definition looks like this:
\define{Definition name}{define-definition}{Definition description}
In a few places, this document has \emph{trivia}-boxes. These include off-the-record information such as why certain decisions were made during Haxe's development or how a particular feature has been changed in past Haxe versions. This information is generally not important and can be skipped as it is only meant to convey trivia:
\trivia{About Trivia}{This is trivia.}
\subsection{Authors and contributions}
\label{introduction-authors-and-contributions}
Most of this document's content was written by Simon Krajewski while working for the Haxe Foundation. We would like to thank these people for their contributions:
\begin{itemize}
\item Dan Korostelev: Additional content and editing
\item Caleb Harper: Additional content and editing
\item Josefiene Pertosa: Editing
\item Miha Lunar: Editing
\item Nicolas Cannasse: Haxe creator
\end{itemize}
\section{Hello World}
\label{introduction-hello-world}
The following program prints ``Hello World'' after being compiled and run:
\haxe{assets/HelloWorld.hx}
This can be tested by saving the above code to a file named \ic{HelloWorld.hx} and invoking the Haxe Compiler like so: \ic{haxe -main HelloWorld --interp}. It then generates the following output: \ic{HelloWorld.hx:3: Hello world}. There are several things to learn from this:
\todo{This generates the following output: too many 'this'. You may like a passive sentence: the following output will be generated...though this is to be avoided, generally}
\begin{itemize}
\item Haxe programs are saved in files with an extension of \ic{.hx}.
\item The Haxe Compiler is a command-line tool which can be invoked with parameters such as \ic{-main HelloWorld} and \ic{--interp}.
\item Haxe programs have classes (\type{HelloWorld}, upper-case), which have functions (\expr{main}, lower-case).
\end{itemize}
\section{History}
\label{introduction-haxe-history}
\state{Reviewed}
The Haxe project was started on 22 October 2005 by French developer \emph{Nicolas Cannasse} as a successor to the popular open-source ActionScript 2 compiler \emph{MTASC} (Motion-Twin Action Script Compiler) and the in-house \emph{MTypes} language, which experimented with the application of type inference to an object oriented language. Nicolas' long-time passion for programming language design and the rise of new opportunies to mix different technologies as part of his game developer work at \emph{Motion-Twin} led to the creation of a whole new language.
Being spelled \emph{haXe} back then, its beta version was released in February 2006 with the first supported targets being AVM\footnote{Adobe Virtual Machine}-bytecode and Nicolas' own \emph{Neko} virtual machine\footnote{http://nekovm.org}.
Nicolas Cannasse, who remains leader of the Haxe project to this date, kept on designing Haxe with a clear vision, subsequently leading to the Haxe 1.0 release in May 2006. This first major release came with support for \target{Javascript} code generation and already had some of the features that define Haxe today such as type inference and structural sub-typing.
Haxe 1 saw several minor releases over the course of two years, adding the \target{Flash AVM2} target along with the \emph{haxelib}-tool in August 2006 and the \target{Actionscript 3} target in March 2007. During these months, there was a strong focus on improving stability, which resulted in several minor bug-fix releases.
Haxe 2.0 was released in July 2008, including the \target{PHP} target, courtesy of \emph{Franco Ponticelli}. A similar effort by \emph{Hugh Sanderson} lead to the addition of the \target{C++} target in July 2009 with the Haxe 2.04 release.
Just as with Haxe 1, what followed were several months of stability releases. In January 2011, Haxe 2.07 was released with the support of \emph{macros}. Around that time, \emph{Bruno Garcia} joined the team as maintainer of the \target{Javascript} target, which saw vast improvements in the subsequent 2.08 and 2.09 releases.
After the release of 2.09, \emph{Simon Krajewski} joined the team and work towards Haxe 3 began. Furthermore, \emph{Cau\^{e} Waneck}'s \target{Java} and \target{C\#} targets found their way into the Haxe builds. It was then decided to make one final Haxe 2 release, which happened in July 2012 with the release of Haxe 2.10.
In late 2012, the Haxe 3 switch was flipped and the Haxe Compiler team, now backed by the newly established \emph{Haxe Foundation}\footnote{http://haxe-foundation.org}, focused on this next major version. Haxe 3 was subsequently released in May 2013.