From ee38941a0ba32160018abe07c9d27a41534ca2ec Mon Sep 17 00:00:00 2001 From: Justin Donaldson Date: Mon, 19 Aug 2013 11:55:01 -0700 Subject: first draft of learn haxe 3 in 15 minutes --- haxe.html.markdown | 419 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 419 insertions(+) create mode 100644 haxe.html.markdown (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown new file mode 100644 index 00000000..c51ae7ce --- /dev/null +++ b/haxe.html.markdown @@ -0,0 +1,419 @@ +--- +language: haxe +filename: LearnHaxe3.hx +contributors: + - ["Justin Donaldson", "https://github.com/jdonaldson/"] +--- + +Haxe is a web-oriented language that provides platform support for C++, C#, +Swf/ActionScript, Javascript, Java, and Neko byte code (also written by the +Haxe author). Note that this guide is for Haxe version 3. Some of the guide +may be applicable to older versions, but it is recommended to use other +references. + +```haxe +// Welcome to Learn Haxe 3 in 15 minutes. http://www.haxe.org +// This is an executable tutorial. You can compile and run it using the haxe +// compiler, while in the same directory as LearnHaxe.hx: +// haxe -main LearnHaxe3 -x + +// Let's start with comments... this is a single line comment + +/* + And this is multiline +*/ + +// A package declaration isn't necessary, but it's useful if you want to +// organize your code into modules later on. Also worth mentioning, all +// expressions in Haxe must end in a semicolon: +package; // empty package, no namespace. + +// if you import code from other files, it must be declared before the rest of +// the code. +import haxe.ds.ArraySort; + +// you can import many classes/modules at once with "*" +import haxe.ds.*; + +// you can also import classes in a special way, enabling them to extend the +// functionality of other classes. More on this later. +using StringTools; + +// Haxe files typically define classes, although they can also define other +// types of code... more on that later. + + +class LearnHaxe3{ + /* + If you want certain code to run automatically, you need to put it in + a static main function, and specify the class in the compiler arguments. + In this case, we've specified the "LearnHaxe3" class in the compiler + arguments above. + */ + static function main(){ + /* + Trace is the default method of printing haxe expressions to the + screen. Different targets will have different methods of + accomplishing this. E.g., java, c++, c#, etc. will print to std + out. Javascript will print to console.log, and flash will print to + an embedded TextField. All traces come with a default newline. + Finally, It's possible to prevent traces from showing by using the + "--no-traces" argument on the compiler. + */ + + + trace("Hello World, with trace()!"); + + /* + Trace can handle any type of value or object. It will try to print + a representation of the expression as best it can: + */ + trace( + " Integer: " + 10 + + " Float: " + 3.14 + + " Boolean: " + true); + + + /* + Remember what I said about expressions needing semicolons? You + can put more than one expression on a line if you want. + */ + trace('two expressions..'); trace('one line'); + + + ////////////////////////////////////////////////////////////////// + // Types & Variables + ////////////////////////////////////////////////////////////////// + trace("***Types & Variables***"); + + /* + You can save values and references to data structures using the + "var" keyword: + */ + + var an_integer:Int = 1; + trace(an_integer + " is the value for an_integer"); + + + /* + Haxe is statically typed, so "an_integer" is declared to have an + "Int" type, and the rest of the expression assigns the value "1" to + it. It's not necessary to declare the type in many cases. Here, + the haxe compiler is inferring that the type of another_integer + should be "Int". + */ + + var another_integer = 2; + trace(another_integer + " is the value for another_integer"); + + // The $type() method prints the type that the compiler assigns: + $type(another_integer); + + // You can also represent integers with hexadecimal: + var hex_integer = 0xffffff; + + /* + Haxe uses platform precision for Int and Float sizes. It also + uses the platform behavior for overflow. + (Other numeric types and behavior are possible using special + libraries) + */ + + /* + In addition to simple values like Integers, Floats, and Booleans, + Haxe provides standard library implementations for common data + structures like strings, arrays, lists, and maps: + */ + + var a_string = "some_string"; // strings can have double or single quotes + trace(a_string + " is the value for a_string"); + + /* + Strings are immutable, instance methods will return a copy of + parts or all of the string. + (See also the StringBuf class). + */ + var a_sub_string = a_string.substr(0,4); + trace(a_sub_string + " is the value for a_sub_string"); + + /* + Arrays are zero-indexed, dynamic, and mutable. Missing values are + defined as null. + */ + var a = new Array(); // an array that contains Strings + a[0] = 'foo'; + trace(a.length + " is the value for a.length"); + a[9] = 'bar'; + trace(a.length + " is the value for a.length (after modification)"); + trace(a[3] + " is the value for a[3]"); //null + + /* + Arrays are *generic*, so you can indicate which values they contain + with a type parameter: + */ + var a2 = new Array(); // an array of Ints + var a3 = new Array>(); // an Array of Arrays (of Strings). + + /* + Maps are simple key/value data structures. The key and the value + can be of any type. + */ + var m = new Map(); // The keys are strings, the values are Ints. + m.set('foo', 4); + // You can also use array notation; + m['bar'] = 5; + trace(m.exists('bar') + " is the value for m.exists('bar')"); + trace(m.get('bar') + " is the value for m.get('bar')"); + trace(m['bar'] + " is the value for m['bar']"); + + var m2 = ['foo' => 4, 'baz' => 6]; // Alternative map syntax + trace(m2 + " is the value for m2"); + + /* + Remember, you can use type inference. The Haxe compiler will + decide the type of the variable the first time you pass an + argument that sets a type parameter. + */ + var m3 = new Map(); + m3.set(6, 'baz'); // m2 is now a Map + trace(m3 + " is the value for m3"); + + /* + Haxe has many more common datastructures in the haxe.ds module, such as + List, Stack, and BalancedTree + */ + + + ////////////////////////////////////////////////////////////////// + // Operators + ////////////////////////////////////////////////////////////////// + + trace("***OPERATORS***"); + + // basic arithmetic + trace((4 + 3) + " is the value for (4 + 3)"); + trace((5 - 1) + " is the value for (5 - 1)"); + trace((2 * 4) + " is the value for (2 * 4)"); + trace((8 / 4) + " is the value for (8 / 3) (division always produces Floats)"); + trace((12 % 4) + " is the value for (12 % 4)"); + + + //basic comparison + trace(3 == 2 + " is the value for 3 == 2"); + trace(3 != 2 + " is the value for 3 != 2"); + trace(3 > 2 + " is the value for 3 > 2"); + trace(3 < 2 + " is the value for 3 < 2"); + trace(3 >= 2 + " is the value for 3 >= 2"); + trace(3 <= 2 + " is the value for 3 <= 2"); + + //bitwise operators + /* + ~ Unary bitwise complement + << Signed left shift + >> Signed right shift + >>> Unsigned right shift + & Bitwise AND + ^ Bitwise exclusive OR + | Bitwise inclusive OR + */ + + //increments + var i = 0; + trace("Increments and decrements"); + trace(i++); //i = 1. Post-Incrementation + trace(++i); //i = 2. Pre-Incrementation + trace(i--); //i = 1. Post-Decrementation + trace(--i); //i = 0. Pre-Decrementation + + ////////////////////////////////////////////////////////////////// + // Control Structures + ////////////////////////////////////////////////////////////////// + trace("***CONTROL STRUCTURES***"); + + // if statements + var j = 10; + if (j == 10){ + trace("this is printed"); + } else if (j > 10){ + trace("not greater than 10, so not printed"); + } else { + trace("also not printed."); + } + + trace("Looping and Iteration"); + + // while loop + var k = 0; + while(k < 100){ + // trace(counter); // will print out numbers 0-99 + counter++; + } + + // do-while loop + var l = 0; + do{ + trace("do statement always runs at least once"); + } while (i > 0); + + // for loop + /* + There is no c-style for loop in Haxe, because they are prone + to error, and not necessary. Instead, Haxe has a much simpler + and safer version that uses Iterators (more on those later). + */ + var m = [1,2,3]; + for (val in m){ + trace(val + " is the value for val in the m array"); + } + + // Note that you can iterate on an index using a range + // (more on ranges later as well) + var n = ['foo', 'bar', 'baz']; + for (val in 0...n.length){ + trace(val + " is the value for val (an index for m)"); + } + + + trace("Array Comprehensions"); + + // Array comprehensions give you the ability to iterate over arrays + // while also creating filters and modifications. + var filtered_n = [for (val in n) if (n != "foo")]; + trace(filtered_n + " is the value for filtered_n"); + var modified_n = [for (val in n) n += '!']; + trace(modified_n + " is the value for modified_n"); + var filtered_and_modified_n [for (val in n) if (n != "foo") n += "!"]; + trace(filtered_and_modified_n + " is the value for filtered_and_modified_n"); + + + ////////////////////////////////////////////////////////////////// + // Switch Statements (Value Type) + ////////////////////////////////////////////////////////////////// + trace("***SWITCH STATEMENTS (VALUE TYPES)***"); + + /* + Switch statements in Haxe are very powerful. In addition to working + on basic values like strings and ints, they can also work on the + generalized algebraic data types in enums (more on enums later). + Here's some basic value examples for now: + */ + var my_dog_name = 'fido'; + var favorite_thing = ''; + switch(my_dog_name){ + case "fido" : favorite_thing = 'bone'; + case "rex" : favorite_thing = 'shoe'; + case "spot" : favorite_thing = 'tennis ball'; + case _ : favorite_thing = 'some unknown treat'; + } + // The "_" case above is a "wildcard" value + // that will match anything. + + trace("My dog's name is" + my_dog_name + + ", and his favorite thing is a: " + + favorite_thing); + + ////////////////////////////////////////////////////////////////// + // Converting Value Types + ////////////////////////////////////////////////////////////////// + + // You can convert strings to ints fairly easily. + + // string to integer + Std.parseInt("0"); // returns 0 + Std.parseFloat("0.4"); // returns 0.4; + + // integer to string + Std.toString(0); // returns "0"; + // concatenation with strings will auto-convert to string. + 0 + ""; // returns "0"; + true + ""; // returns "true"; + // See documentation for parsing in Std for more details. + + ////////////////////////////////////////////////////////////////// + // Basic Object Oriented Design + ////////////////////////////////////////////////////////////////// + trace("***BASIC OBJECT ORIENTED DESIGN***"); + + + var instance = new FooClass(3); + // read the public variable normally + trace(instance.public_any + " is the value for instance.public_any"); + + // we can read this variable + trace(instance.public_read + " is the value for instance.public_read"); + // but not write it, this will throw an error if uncommented: + //trace(instance.public_write + " is the value for instance.public_write"); + // trace(instance.public_write); // vice-versa for public write, etc. + + trace(instance + " is the value for instance"); // calls the toString method + + + // we can successfully pass the FooInstance to the BaseFooClass method, + // since it was extended from that. + BaseFooClass.acceptBaseFoo(instance); + } + +} + +/* + This is the "child class" of the main LearnHaxe3 Class + */ +class FooClass extends BaseFooClass implements BaseFooInterface{ + public var public_any:Int; // public variables are accessible anywhere + public var public_read (default,null): Int; // use this style to only enable public read + public var public_write (null, default): Int; // or public write + public var getter_setter (getValue, setValue): Int; // use this style to enable getters/setters + + // private variables are not available outside the class. + // see @:allow for ways around this. + var _private:Int; // variables are private if they are not marked public + + // a public constructor + public function new(arg:Int){ + super(); // call the constructor of the parent object, since we extended BaseFooClass + + this.public_any= 0; + this._private = arg; + + } + + // getter for _private + function getValue() : Int { + return _private; + } + + // setter for _private + function setValue(val:Int) : Void{ + _private = val; + } + + // special function that is called whenever an instance is cast to a string. + public function toString(){ + return _private + " with toString() method!"; + } + + // this class needs to have this function defined, since it implements + // the BaseFooInterface interface. + public function baseFunction(x: Int) : String{ + // convert the int to string automatically + return x + " was passed into baseFunction!"; + } +} + +class BaseFooClass { + var base_variable:Int; + public function new(){ + base_variable = 4; + } + public static function acceptBaseFoo(b:BaseFooClass){ + } + +} + +interface BaseFooInterface{ + public function baseFunction(x:Int):String; +} + + +``` + -- cgit v1.2.3 From 343c20b4e8f2bd71ade87ed70ee63c39e82c5154 Mon Sep 17 00:00:00 2001 From: Justin Donaldson Date: Mon, 19 Aug 2013 12:01:55 -0700 Subject: minor tweak to compiler args --- haxe.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index c51ae7ce..94b4ea82 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -15,7 +15,7 @@ references. // Welcome to Learn Haxe 3 in 15 minutes. http://www.haxe.org // This is an executable tutorial. You can compile and run it using the haxe // compiler, while in the same directory as LearnHaxe.hx: -// haxe -main LearnHaxe3 -x +// haxe -main LearnHaxe3 -x out // Let's start with comments... this is a single line comment -- cgit v1.2.3 From 1a9107e43d25bcf06cefc701dbf6784d33898b1a Mon Sep 17 00:00:00 2001 From: Simon Richardson Date: Mon, 19 Aug 2013 20:24:18 +0100 Subject: Update haxe.html.markdown I think one of Haxes strong point is the fact that control structures are expressions as well. We should point this out. --- haxe.html.markdown | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index 94b4ea82..0b3c614d 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -284,8 +284,7 @@ class LearnHaxe3{ trace(modified_n + " is the value for modified_n"); var filtered_and_modified_n [for (val in n) if (n != "foo") n += "!"]; trace(filtered_and_modified_n + " is the value for filtered_and_modified_n"); - - + ////////////////////////////////////////////////////////////////// // Switch Statements (Value Type) ////////////////////////////////////////////////////////////////// @@ -311,7 +310,37 @@ class LearnHaxe3{ trace("My dog's name is" + my_dog_name + ", and his favorite thing is a: " + favorite_thing); - + + ////////////////////////////////////////////////////////////////// + // Expression Statements + ////////////////////////////////////////////////////////////////// + trace("***EXPRESSION STATEMENTS***"); + + /* + Haxe control statements are very powerful because every statement + is also an expression, consider: + */ + + // if statements + var k = if (true){ + 10; + } else { + 20; + } + + trace("K equals ", k); // outputs 10 + + var other_favorite_thing = switch(my_dog_name) { + case "fido" : 'teddy'; + case "rex" : 'stick'; + case "spot" : 'football'; + case _ : 'some unknown treat'; + } + + trace("My dog's name is" + my_dog_name + + ", and his other favorite thing is a: " + + other_favorite_thing); + ////////////////////////////////////////////////////////////////// // Converting Value Types ////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From 3b278c3e59926a117dc00c50585045c7e932397a Mon Sep 17 00:00:00 2001 From: Justin Donaldson Date: Mon, 19 Aug 2013 13:56:01 -0700 Subject: fix getter/setter styles --- haxe.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index 0b3c614d..8dd8ba81 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -391,7 +391,7 @@ class FooClass extends BaseFooClass implements BaseFooInterface{ public var public_any:Int; // public variables are accessible anywhere public var public_read (default,null): Int; // use this style to only enable public read public var public_write (null, default): Int; // or public write - public var getter_setter (getValue, setValue): Int; // use this style to enable getters/setters + public var property (get, set): Int; // use this style to enable getters/setters // private variables are not available outside the class. // see @:allow for ways around this. @@ -407,12 +407,12 @@ class FooClass extends BaseFooClass implements BaseFooInterface{ } // getter for _private - function getValue() : Int { + function get_property() : Int { return _private; } // setter for _private - function setValue(val:Int) : Void{ + function set_property(val:Int) : Void{ _private = val; } -- cgit v1.2.3 From 64e889d011a6f0e9968b68b1a982bbe714525cb8 Mon Sep 17 00:00:00 2001 From: Justin Donaldson Date: Mon, 19 Aug 2013 14:09:18 -0700 Subject: fix the other lazy syntax errors --- haxe.html.markdown | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index 8dd8ba81..9288fc87 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -199,12 +199,12 @@ class LearnHaxe3{ //basic comparison - trace(3 == 2 + " is the value for 3 == 2"); - trace(3 != 2 + " is the value for 3 != 2"); - trace(3 > 2 + " is the value for 3 > 2"); - trace(3 < 2 + " is the value for 3 < 2"); - trace(3 >= 2 + " is the value for 3 >= 2"); - trace(3 <= 2 + " is the value for 3 <= 2"); + trace((3 == 2) + " is the value for 3 == 2"); + trace((3 != 2) + " is the value for 3 != 2"); + trace((3 > 2) + " is the value for 3 > 2"); + trace((3 < 2) + " is the value for 3 < 2"); + trace((3 >= 2) + " is the value for 3 >= 2"); + trace((3 <= 2) + " is the value for 3 <= 2"); //bitwise operators /* @@ -246,7 +246,7 @@ class LearnHaxe3{ var k = 0; while(k < 100){ // trace(counter); // will print out numbers 0-99 - counter++; + k++; } // do-while loop @@ -278,11 +278,11 @@ class LearnHaxe3{ // Array comprehensions give you the ability to iterate over arrays // while also creating filters and modifications. - var filtered_n = [for (val in n) if (n != "foo")]; + var filtered_n = [for (val in n) if (val != "foo") val]; trace(filtered_n + " is the value for filtered_n"); - var modified_n = [for (val in n) n += '!']; + var modified_n = [for (val in n) val += '!']; trace(modified_n + " is the value for modified_n"); - var filtered_and_modified_n [for (val in n) if (n != "foo") n += "!"]; + var filtered_and_modified_n = [for (val in n) if (val != "foo") val += "!"]; trace(filtered_and_modified_n + " is the value for filtered_and_modified_n"); ////////////////////////////////////////////////////////////////// @@ -352,7 +352,7 @@ class LearnHaxe3{ Std.parseFloat("0.4"); // returns 0.4; // integer to string - Std.toString(0); // returns "0"; + Std.string(0); // returns "0"; // concatenation with strings will auto-convert to string. 0 + ""; // returns "0"; true + ""; // returns "true"; @@ -412,8 +412,9 @@ class FooClass extends BaseFooClass implements BaseFooInterface{ } // setter for _private - function set_property(val:Int) : Void{ + function set_property(val:Int) : Int { _private = val; + return val; } // special function that is called whenever an instance is cast to a string. @@ -443,6 +444,5 @@ interface BaseFooInterface{ public function baseFunction(x:Int):String; } - ``` -- cgit v1.2.3 From c39c3680cf18be14fdda3740e8b3b6d348d54f34 Mon Sep 17 00:00:00 2001 From: Justin Donaldson Date: Mon, 19 Aug 2013 14:10:48 -0700 Subject: fix comment typo --- haxe.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index 9288fc87..82031291 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -175,7 +175,7 @@ class LearnHaxe3{ argument that sets a type parameter. */ var m3 = new Map(); - m3.set(6, 'baz'); // m2 is now a Map + m3.set(6, 'baz'); // m3 is now a Map trace(m3 + " is the value for m3"); /* -- cgit v1.2.3 From 78133a784f65c32f5904f57b6d665167b026cd4f Mon Sep 17 00:00:00 2001 From: Justin Donaldson Date: Mon, 19 Aug 2013 21:54:38 -0700 Subject: misc reformat, and some small details --- haxe.html.markdown | 98 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 61 insertions(+), 37 deletions(-) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index 82031291..90b2e250 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -12,22 +12,29 @@ may be applicable to older versions, but it is recommended to use other references. ```haxe -// Welcome to Learn Haxe 3 in 15 minutes. http://www.haxe.org -// This is an executable tutorial. You can compile and run it using the haxe -// compiler, while in the same directory as LearnHaxe.hx: -// haxe -main LearnHaxe3 -x out +/* + Welcome to Learn Haxe 3 in 15 minutes. http://www.haxe.org + This is an executable tutorial. You can compile and run it using the haxe + compiler, while in the same directory as LearnHaxe.hx: + haxe -main LearnHaxe3 -x out + */ // Let's start with comments... this is a single line comment /* - And this is multiline -*/ + And this is multiline. Multiline comments are also used to generate + javadoc-style documentation for haxedoc. They will be used if they precede + a class, class function, or class variable. + */ -// A package declaration isn't necessary, but it's useful if you want to -// organize your code into modules later on. Also worth mentioning, all -// expressions in Haxe must end in a semicolon: +/* + A package declaration isn't necessary, but it's useful if you want to + organize your code into modules later on. Also worth mentioning, all + expressions in Haxe must end in a semicolon: + */ package; // empty package, no namespace. + // if you import code from other files, it must be declared before the rest of // the code. import haxe.ds.ArraySort; @@ -66,12 +73,14 @@ class LearnHaxe3{ /* Trace can handle any type of value or object. It will try to print - a representation of the expression as best it can: + a representation of the expression as best it can. You can also + concatenate strings with the "+" operator: */ trace( " Integer: " + 10 + " Float: " + 3.14 + - " Boolean: " + true); + " Boolean: " + true + ); /* @@ -113,9 +122,9 @@ class LearnHaxe3{ var hex_integer = 0xffffff; /* - Haxe uses platform precision for Int and Float sizes. It also - uses the platform behavior for overflow. - (Other numeric types and behavior are possible using special + Haxe uses platform precision for Int and Float sizes. It also + uses the platform behavior for overflow. + (Other numeric types and behavior are possible using special libraries) */ @@ -125,9 +134,12 @@ class LearnHaxe3{ structures like strings, arrays, lists, and maps: */ - var a_string = "some_string"; // strings can have double or single quotes + var a_string = "some" + 'string'; // strings can have double or single quotes trace(a_string + " is the value for a_string"); + var x = 1; + var an_interpolated_string = 'the value of x is $x'; + /* Strings are immutable, instance methods will return a copy of parts or all of the string. @@ -280,11 +292,13 @@ class LearnHaxe3{ // while also creating filters and modifications. var filtered_n = [for (val in n) if (val != "foo") val]; trace(filtered_n + " is the value for filtered_n"); + var modified_n = [for (val in n) val += '!']; trace(modified_n + " is the value for modified_n"); + var filtered_and_modified_n = [for (val in n) if (val != "foo") val += "!"]; trace(filtered_and_modified_n + " is the value for filtered_and_modified_n"); - + ////////////////////////////////////////////////////////////////// // Switch Statements (Value Type) ////////////////////////////////////////////////////////////////// @@ -310,41 +324,41 @@ class LearnHaxe3{ trace("My dog's name is" + my_dog_name + ", and his favorite thing is a: " + favorite_thing); - + ////////////////////////////////////////////////////////////////// // Expression Statements ////////////////////////////////////////////////////////////////// trace("***EXPRESSION STATEMENTS***"); - + /* Haxe control statements are very powerful because every statement is also an expression, consider: */ - + // if statements var k = if (true){ 10; } else { 20; } - + trace("K equals ", k); // outputs 10 - + var other_favorite_thing = switch(my_dog_name) { case "fido" : 'teddy'; case "rex" : 'stick'; case "spot" : 'football'; - case _ : 'some unknown treat'; + case _ : 'some unknown treat'; } - + trace("My dog's name is" + my_dog_name + ", and his other favorite thing is a: " + other_favorite_thing); - + ////////////////////////////////////////////////////////////////// // Converting Value Types ////////////////////////////////////////////////////////////////// - + // You can convert strings to ints fairly easily. // string to integer @@ -359,26 +373,31 @@ class LearnHaxe3{ // See documentation for parsing in Std for more details. ////////////////////////////////////////////////////////////////// - // Basic Object Oriented Design + // Basic Object Oriented Programming ////////////////////////////////////////////////////////////////// - trace("***BASIC OBJECT ORIENTED DESIGN***"); + trace("***BASIC OBJECT ORIENTED PROGRAMMING***"); + // create an instance of FooClass. The classes for this are at the + // end of the file. var instance = new FooClass(3); + // read the public variable normally trace(instance.public_any + " is the value for instance.public_any"); // we can read this variable trace(instance.public_read + " is the value for instance.public_read"); - // but not write it, this will throw an error if uncommented: - //trace(instance.public_write + " is the value for instance.public_write"); - // trace(instance.public_write); // vice-versa for public write, etc. + // but not write it + // instance.public_write = 4; // this will throw an error if uncommented: + // trace(instance.public_write); // as will this. trace(instance + " is the value for instance"); // calls the toString method + trace(instance.toString() + " is the value for instance.toString()"); // same thing - // we can successfully pass the FooInstance to the BaseFooClass method, - // since it was extended from that. + // instance has the "FooClass" type, while acceptBaseFoo has the + // BaseFooClass type. However, since FooClass extends BaseFooClass, + // it is accepted. BaseFooClass.acceptBaseFoo(instance); } @@ -389,12 +408,12 @@ class LearnHaxe3{ */ class FooClass extends BaseFooClass implements BaseFooInterface{ public var public_any:Int; // public variables are accessible anywhere - public var public_read (default,null): Int; // use this style to only enable public read + public var public_read (default,null): Int; // use this style to only enable public read public var public_write (null, default): Int; // or public write public var property (get, set): Int; // use this style to enable getters/setters // private variables are not available outside the class. - // see @:allow for ways around this. + // see @:allow for ways around this. var _private:Int; // variables are private if they are not marked public // a public constructor @@ -416,13 +435,13 @@ class FooClass extends BaseFooClass implements BaseFooInterface{ _private = val; return val; } - + // special function that is called whenever an instance is cast to a string. public function toString(){ return _private + " with toString() method!"; } - // this class needs to have this function defined, since it implements + // this class needs to have this function defined, since it implements // the BaseFooInterface interface. public function baseFunction(x: Int) : String{ // convert the int to string automatically @@ -430,6 +449,9 @@ class FooClass extends BaseFooClass implements BaseFooInterface{ } } +/* + A simple class to extend +*/ class BaseFooClass { var base_variable:Int; public function new(){ @@ -437,9 +459,11 @@ class BaseFooClass { } public static function acceptBaseFoo(b:BaseFooClass){ } - } +/* + A simple interface to implement +*/ interface BaseFooInterface{ public function baseFunction(x:Int):String; } -- cgit v1.2.3 From 12bbb737f6417cb39a1f5ef3cf5d50f1bccc34a4 Mon Sep 17 00:00:00 2001 From: Justin Donaldson Date: Tue, 20 Aug 2013 21:25:34 -0700 Subject: added ternary, some reformatting and fixes --- haxe.html.markdown | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index 90b2e250..e6c2b49c 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -29,8 +29,8 @@ references. /* A package declaration isn't necessary, but it's useful if you want to - organize your code into modules later on. Also worth mentioning, all - expressions in Haxe must end in a semicolon: + organize your code into modules later on. Also worth mentioning, if you use + more than one expression in a code block, it must end in a semicolon: */ package; // empty package, no namespace. @@ -252,6 +252,9 @@ class LearnHaxe3{ trace("also not printed."); } + // there is also a "ternary" if: + (j == 10) ? trace("equals 10") : trace("not equals 10"); + trace("Looping and Iteration"); // while loop @@ -310,13 +313,14 @@ class LearnHaxe3{ generalized algebraic data types in enums (more on enums later). Here's some basic value examples for now: */ - var my_dog_name = 'fido'; - var favorite_thing = ''; + var my_dog_name = "fido"; + var favorite_thing = ""; switch(my_dog_name){ - case "fido" : favorite_thing = 'bone'; - case "rex" : favorite_thing = 'shoe'; - case "spot" : favorite_thing = 'tennis ball'; - case _ : favorite_thing = 'some unknown treat'; + case "fido" : favorite_thing = "bone"; + case "rex" : favorite_thing = "shoe"; + case "spot" : favorite_thing = "tennis ball"; + default : favorite_thing = "some unknown treat"; + // case _ : "some unknown treat"; // same as default } // The "_" case above is a "wildcard" value // that will match anything. @@ -345,10 +349,10 @@ class LearnHaxe3{ trace("K equals ", k); // outputs 10 var other_favorite_thing = switch(my_dog_name) { - case "fido" : 'teddy'; - case "rex" : 'stick'; - case "spot" : 'football'; - case _ : 'some unknown treat'; + case "fido" : "teddy"; + case "rex" : "stick"; + case "spot" : "football"; + default : "some unknown treat"; } trace("My dog's name is" + my_dog_name -- cgit v1.2.3 From 98278338e76fb6fbdacf44142777891f238bc984 Mon Sep 17 00:00:00 2001 From: Justin Donaldson Date: Wed, 21 Aug 2013 20:33:55 -0700 Subject: reformatting. Add details on swtiches and gadt enums --- haxe.html.markdown | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 103 insertions(+), 6 deletions(-) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index e6c2b49c..60f374d8 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -199,7 +199,6 @@ class LearnHaxe3{ ////////////////////////////////////////////////////////////////// // Operators ////////////////////////////////////////////////////////////////// - trace("***OPERATORS***"); // basic arithmetic @@ -376,14 +375,20 @@ class LearnHaxe3{ true + ""; // returns "true"; // See documentation for parsing in Std for more details. + + + ////////////////////////////////////////////////////////////////// // Basic Object Oriented Programming ////////////////////////////////////////////////////////////////// trace("***BASIC OBJECT ORIENTED PROGRAMMING***"); - // create an instance of FooClass. The classes for this are at the - // end of the file. + /* + Create an instance of FooClass. The classes for this are at the + end of the file. + */ + var instance = new FooClass(3); // read the public variable normally @@ -399,9 +404,11 @@ class LearnHaxe3{ trace(instance.toString() + " is the value for instance.toString()"); // same thing - // instance has the "FooClass" type, while acceptBaseFoo has the - // BaseFooClass type. However, since FooClass extends BaseFooClass, - // it is accepted. + /* + Instance has the "FooClass" type, while acceptBaseFoo has the + BaseFooClass type. However, since FooClass extends BaseFooClass, + it is accepted. + */ BaseFooClass.acceptBaseFoo(instance); } @@ -472,5 +479,95 @@ interface BaseFooInterface{ public function baseFunction(x:Int):String; } +////////////////////////////////////////////////////////////////// +// Enums and Switch Statements +////////////////////////////////////////////////////////////////// + +/* + Enums in Haxe are very powerful. In their simplest form, enums + are a type with a limited number of states: + */ + +enum SimpleEnum { + Foo; + Bar; + Baz; +} + +// Here's a class that uses it: + +class SimpleEnumTest{ + public static function example(){ + var e_explicit:SimpleEnum = SimpleEnum.Foo; // you can specify the "full" name + var e = Foo; // but inference will work as well. + switch(e){ + case Foo: trace("e was Foo"); + case Bar: trace("e was Bar"); + case Baz: trace("e was Baz"); // comment this line to throw an error. + } + + /* + This doesn't seem so different from simple value switches on strings. + However, if we don't include *all* of the states, the compiler will + complain. You can try it by commenting out a line above. + + You can also specify a default for enum switches as well: + */ + switch(e){ + case Foo: trace("e was Foo again"); + default : trace("default works here too"); + } + } +} + +/* + Enums go much further than simple states, we can also enumerate + *constructors*, but we'll need a more complex enum example + */ +enum ComplexEnum{ + IntEnum(i:Int); + MultiEnum(i:Int, j:String, k:Float); + SimpleEnumEnum(s:SimpleEnum); + ComplexEnumEnum(c:ComplexEnum); +} + +/* + Note: The enum above can include *other* enums as well. + */ + + +class ComplexEnumTest{ + public static function example(){ + var e1:ComplexEnum = IntEnum(4); // specifying the enum parameter + /* + Now we can switch on the enum, as well as extract any parameters + it might of had. + */ + switch(e1){ + case IntEnum(x) : trace("x was the parameter passed to e1"); + default: trace("Shouldn't be printed"); + } + + var e2 = SimpleEnumEnum(Foo); // another parameter here that is itself an enum... an enum enum? + switch(e2){ + case SimpleEnumEnum(s): trace('$s was the parameter passed to e2'); + default: trace("Shouldn't be printed"); + } + + var e3 = ComplexEnumEnum(ComplexEnumEnum(MultiEnum(4, 'hi', 4.3))); // enums all the way down + switch(e3){ + // You can look for certain nested enums by specifying them explicitly: + case ComplexEnumEnum(ComplexEnumEnum(MultiEnum(i,j,k)) : { + trace('$i, $j, and $k were passed into this nested monster'); + } + default: trace("Shouldn't be printed"); + } + /* + Check out generalized algebraic data types (GADT) for more details + on why these are so great. + */ + } +} + ``` -- cgit v1.2.3 From 27b3ab01e4b132a428a7fc2b26e8848f390dc179 Mon Sep 17 00:00:00 2001 From: Justin Donaldson Date: Wed, 21 Aug 2013 20:37:32 -0700 Subject: missing paren --- haxe.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index 60f374d8..0c5fdf5d 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -557,7 +557,7 @@ class ComplexEnumTest{ var e3 = ComplexEnumEnum(ComplexEnumEnum(MultiEnum(4, 'hi', 4.3))); // enums all the way down switch(e3){ // You can look for certain nested enums by specifying them explicitly: - case ComplexEnumEnum(ComplexEnumEnum(MultiEnum(i,j,k)) : { + case ComplexEnumEnum(ComplexEnumEnum(MultiEnum(i,j,k))) : { trace('$i, $j, and $k were passed into this nested monster'); } default: trace("Shouldn't be printed"); -- cgit v1.2.3 From d9d57ee1a1c3e5239251efdd8aeb0a320cfbea49 Mon Sep 17 00:00:00 2001 From: Justin Donaldson Date: Wed, 21 Aug 2013 22:07:32 -0700 Subject: add examples for using, typedefs, and conditional comp. more refmt. --- haxe.html.markdown | 175 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 155 insertions(+), 20 deletions(-) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index 0c5fdf5d..319c6902 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -28,27 +28,35 @@ references. */ /* - A package declaration isn't necessary, but it's useful if you want to - organize your code into modules later on. Also worth mentioning, if you use - more than one expression in a code block, it must end in a semicolon: + This is your first actual haxe code, it's declaring an empty package. A + package isn't necessary, but it's useful if you want to create a namespace + for your code (e.g. org.module.ClassName). */ package; // empty package, no namespace. - -// if you import code from other files, it must be declared before the rest of -// the code. +/* + if you import code from other files, it must be declared before the rest of + the code. + */ import haxe.ds.ArraySort; // you can import many classes/modules at once with "*" import haxe.ds.*; -// you can also import classes in a special way, enabling them to extend the -// functionality of other classes. More on this later. +/* + you can also import classes in a special way, enabling them to extend the + functionality of other classes. More on 'using' later. + */ using StringTools; -// Haxe files typically define classes, although they can also define other -// types of code... more on that later. +/* + Typedefs are like variables... for types. They must be declared before any + code. More on this later. + */ +typedef FooString = String; +// Typedefs can also use "structural" types, more on that later as well! +typedef FooObject = { foo: String }; class LearnHaxe3{ /* @@ -254,6 +262,24 @@ class LearnHaxe3{ // there is also a "ternary" if: (j == 10) ? trace("equals 10") : trace("not equals 10"); + /* + Finally, there is another form of control structures that operates + at compile time: conditional compilation. + */ +#if neko + trace('hello from neko'); +#elseif js + trace('hello from js'); +#else + trace('hello from another platform!'); +#end + /* + The compiled code will change depending on the platform target. + Since we're compiling for neko (-x or -neko), we only get the neko + greeting. + */ + + trace("Looping and Iteration"); // while loop @@ -410,6 +436,15 @@ class LearnHaxe3{ it is accepted. */ BaseFooClass.acceptBaseFoo(instance); + + /* + The classes below have some more advanced examples, the "example()" + method will just run them here. + */ + SimpleEnumTest.example(); + ComplexEnumTest.example(); + TypedefsAndStructuralTypes.example(); + } } @@ -530,11 +565,7 @@ enum ComplexEnum{ SimpleEnumEnum(s:SimpleEnum); ComplexEnumEnum(c:ComplexEnum); } - -/* - Note: The enum above can include *other* enums as well. - */ - +// Note: The enum above can include *other* enums as well, including itself! class ComplexEnumTest{ public static function example(){ @@ -544,17 +575,19 @@ class ComplexEnumTest{ it might of had. */ switch(e1){ - case IntEnum(x) : trace("x was the parameter passed to e1"); + case IntEnum(x) : trace('$x was the parameter passed to e1'); default: trace("Shouldn't be printed"); } - var e2 = SimpleEnumEnum(Foo); // another parameter here that is itself an enum... an enum enum? + // another parameter here that is itself an enum... an enum enum? + var e2 = SimpleEnumEnum(Foo); switch(e2){ case SimpleEnumEnum(s): trace('$s was the parameter passed to e2'); default: trace("Shouldn't be printed"); } - var e3 = ComplexEnumEnum(ComplexEnumEnum(MultiEnum(4, 'hi', 4.3))); // enums all the way down + // enums all the way down + var e3 = ComplexEnumEnum(ComplexEnumEnum(MultiEnum(4, 'hi', 4.3))); switch(e3){ // You can look for certain nested enums by specifying them explicitly: case ComplexEnumEnum(ComplexEnumEnum(MultiEnum(i,j,k))) : { @@ -562,12 +595,114 @@ class ComplexEnumTest{ } default: trace("Shouldn't be printed"); } - /* - Check out generalized algebraic data types (GADT) for more details + /* + Check out "generalized algebraic data types" (GADT) for more details on why these are so great. */ } } +class TypedefsAndStructuralTypes { + public static function example(){ + // Here we're going to use typedef types, instead of base types. + var t1:FooString = "some string"; + + /* + We can use typedefs for "structural types". These types are defined + by their field structure, not by class inheritance. Here's an + anonymous object with a String field named "foo": + */ + + var fooObj = { foo: 'hi' }; + + /* + Remember back at the top where we declared the FooObj typedef? + Since fooObj matches that structure, we can use it anywhere that + a "FooObject" is expected. + */ + + var f = function(fo:FooObj){ trace('$fo was passed in to this function')}; + f(fooObj); // call the FooObject signature function with fooObj. + + /* + Note that typedefs can have optional fields as well, marked with "?" + + typedef OptionalFooObj = { + ?optionalString: String, + requiredInt: Int + } + */ + + /* + Typedefs work well with conditional compilation. For instance, + we could have included this at the top of the file: + +#if( js ) + typedef Surface = js.html.CanvasRenderingContext2D; +#elseif( nme ) + typedef Surface = nme.display.Graphics; +#elseif( !flash9 ) + typedef Surface = flash8.MovieClip; +#elseif( java ) + typedef Surface = java.awt.geom.GeneralPath; +#end + + That would give us a single "Surface" type to work with across + all of those platforms. + */ + } +} + +class UsingExample { + public static function example() { + + /* + The "using" import keyword is a special type of class import that + alters the behavior of any static methods in the class. + + In this file, we've applied "using" to "StringTools", which contains + a number of static methods for dealing with String types. + */ + trace(StringTools.endsWith("foobar", "bar") + " should be true!"); + + /* + With a "using" import, the first argument type is extended with the + method. What does that mean? Well, since "endsWith" has a first + argument type of "String", that means all String types now have the + "endsWith" method: + */ + trace("foobar".endsWith("bar") + " should be true!"); + + /* + This technique enables a good deal of expression for certain types, + while limiting the scope of modifications to a single file. + + Note that the String instance is *not* modified in the run time. + The newly attached method is not really part of the attached + instance, and the compiler still generates code equivalent to a + static method. + */ + } + +} + ``` +We're still only scratching the surface here of what Haxe can do. For a formal +overiew of all Haxe features, checkout the [online +manual](http://haxe.org/manual), the [online api](http://api.haxe.org/), and +"haxelib", the [haxe library repo] (http://lib.haxe.org/). + +For more advanced topics, consider checking out: + +* [Abstract types](http://haxe.org/manual/abstracts) +* [Macros](http://haxe.org/manual/macros), and [Compiler Macros](http://haxe.org/manual/macros_compiler) +* [Tips and Tricks](http://haxe.org/manual/tips_and_tricks) + + +Finally, please join us on [the mailing +list](http://haxe.org/manual/tips_and_tricks), on IRC [#haxe on +freenode](http://webchat.freenode.net/), or on +[Google+](https://plus.google.com/communities/103302587329918132234). + + -- cgit v1.2.3 From 92a6c9164440d60ecf549c9211312b069abab1e7 Mon Sep 17 00:00:00 2001 From: Justin Donaldson Date: Wed, 21 Aug 2013 22:11:01 -0700 Subject: type typo --- haxe.html.markdown | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index 319c6902..e1ab645c 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -621,7 +621,9 @@ class TypedefsAndStructuralTypes { a "FooObject" is expected. */ - var f = function(fo:FooObj){ trace('$fo was passed in to this function')}; + var f = function(fo:FooObject){ + trace('$fo was passed in to this function'); + } f(fooObj); // call the FooObject signature function with fooObj. /* -- cgit v1.2.3 From 580f1a4fe0df112b89cf29d74e3cc765cd660cd9 Mon Sep 17 00:00:00 2001 From: Justin Donaldson Date: Wed, 21 Aug 2013 22:29:31 -0700 Subject: add note about untyped/Dynamic --- haxe.html.markdown | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index e1ab645c..293cb2a0 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -387,6 +387,7 @@ class LearnHaxe3{ ////////////////////////////////////////////////////////////////// // Converting Value Types ////////////////////////////////////////////////////////////////// + trace("***CONVERTING VALUE TYPES***"); // You can convert strings to ints fairly easily. @@ -402,7 +403,51 @@ class LearnHaxe3{ // See documentation for parsing in Std for more details. + ////////////////////////////////////////////////////////////////// + // Dealing with Types + ////////////////////////////////////////////////////////////////// + + /* + + As mentioned before, Haxe is a statically typed language. All in + all, static typing is a wonderful thing. It enables + autocompletions, and can be used to check the correctness of a + program in very thorough ways. Plus, the Haxe compiler is super fast. + You probably won't be waiting on it very much. + *HOWEVER*, there are times when you just wish the compiler would let + something slide, and not throw a type error in a limited case. + + To do this, Haxe has two separate keywords. The first is the + "Dynamic" type: + */ + var dyn: Dynamic = "any type of variable, such as this string"; + + /* + All that you know for certain with a Dynamic variable is that the + compiler will no longer worry about what type it is. It is like a + wildcard variable: You can pass it instead of any variable type, + and you can assign any variable type you want. + + The other more extreme option is the "untyped" keyword + */ + + untyped { + var x:Int = 'foo'; + var y:String = 4; + } + + /* + The untyped keyword operates on entire *blocks* of code, skipping + any type checks that might be otherwise required. This keyword should + be used very sparingly, such as in limited conditionally-compiled + situations where type checking is a hinderance. + + In general, skipping type checks is *not* recommended. Use the + enum, inheritance, or structural type models in order to verify the + correctness of your program. Only when you're certain that none of + the type models work should you resort to "Dynamic" or "untyped". + */ ////////////////////////////////////////////////////////////////// // Basic Object Oriented Programming -- cgit v1.2.3 From 93adb27cc6e1adab29c3f7af98e25ef727ee9369 Mon Sep 17 00:00:00 2001 From: Justin Donaldson Date: Wed, 21 Aug 2013 22:36:45 -0700 Subject: invoke the using example method --- haxe.html.markdown | 1 + 1 file changed, 1 insertion(+) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index 293cb2a0..ba6c464a 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -489,6 +489,7 @@ class LearnHaxe3{ SimpleEnumTest.example(); ComplexEnumTest.example(); TypedefsAndStructuralTypes.example(); + UsingExample.example(); } -- cgit v1.2.3 From 078cbd3299e4f17f67473bf099258a7a5d26c4bd Mon Sep 17 00:00:00 2001 From: Justin Donaldson Date: Thu, 22 Aug 2013 10:54:51 -0700 Subject: fix mailing list link --- haxe.html.markdown | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index ba6c464a..5c488b30 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -748,8 +748,7 @@ For more advanced topics, consider checking out: * [Tips and Tricks](http://haxe.org/manual/tips_and_tricks) -Finally, please join us on [the mailing -list](http://haxe.org/manual/tips_and_tricks), on IRC [#haxe on +Finally, please join us on [the mailing list](https://groups.google.com/forum/#!forum/haxelang), on IRC [#haxe on freenode](http://webchat.freenode.net/), or on [Google+](https://plus.google.com/communities/103302587329918132234). -- cgit v1.2.3 From cd723d1245282e33dd0fd0c0f52222c7f91bc3bd Mon Sep 17 00:00:00 2001 From: Justin Donaldson Date: Thu, 22 Aug 2013 10:58:46 -0700 Subject: more doc/example tweaks --- haxe.html.markdown | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index 5c488b30..9ef69c64 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -418,16 +418,16 @@ class LearnHaxe3{ *HOWEVER*, there are times when you just wish the compiler would let something slide, and not throw a type error in a limited case. - To do this, Haxe has two separate keywords. The first is the + To do this, Haxe has two separate keywords. The first is the "Dynamic" type: */ var dyn: Dynamic = "any type of variable, such as this string"; /* - All that you know for certain with a Dynamic variable is that the - compiler will no longer worry about what type it is. It is like a + All that you know for certain with a Dynamic variable is that the + compiler will no longer worry about what type it is. It is like a wildcard variable: You can pass it instead of any variable type, - and you can assign any variable type you want. + and you can assign any variable type you want. The other more extreme option is the "untyped" keyword */ @@ -438,12 +438,12 @@ class LearnHaxe3{ } /* - The untyped keyword operates on entire *blocks* of code, skipping + The untyped keyword operates on entire *blocks* of code, skipping any type checks that might be otherwise required. This keyword should be used very sparingly, such as in limited conditionally-compiled situations where type checking is a hinderance. - In general, skipping type checks is *not* recommended. Use the + In general, skipping type checks is *not* recommended. Use the enum, inheritance, or structural type models in order to verify the correctness of your program. Only when you're certain that none of the type models work should you resort to "Dynamic" or "untyped". @@ -650,27 +650,32 @@ class ComplexEnumTest{ class TypedefsAndStructuralTypes { public static function example(){ - // Here we're going to use typedef types, instead of base types. + /* + Here we're going to use typedef types, instead of base types. + At the top we've declared the type "FooString" to mean a "String" type. + */ var t1:FooString = "some string"; /* - We can use typedefs for "structural types". These types are defined - by their field structure, not by class inheritance. Here's an - anonymous object with a String field named "foo": + We can use typedefs for "structural types" as well. These types are + defined by their field structure, not by class inheritance. Here's + an anonymous object with a String field named "foo": */ - var fooObj = { foo: 'hi' }; + var anon_obj = { foo: 'hi' }; /* - Remember back at the top where we declared the FooObj typedef? - Since fooObj matches that structure, we can use it anywhere that - a "FooObject" is expected. + The anon_obj variable doesn't have a type declared, and is an + anonymous object according to the compiler. However, remember back at + the top where we declared the FooObj typedef? Since anon_obj matches + that structure, we can use it anywhere that a "FooObject" type is + expected. */ var f = function(fo:FooObject){ trace('$fo was passed in to this function'); } - f(fooObj); // call the FooObject signature function with fooObj. + f(anon_obj); // call the FooObject signature function with anon_obj. /* Note that typedefs can have optional fields as well, marked with "?" -- cgit v1.2.3 From f11d5cf90c69d7777d5c022e01921fe3bd5961b6 Mon Sep 17 00:00:00 2001 From: Justin Donaldson Date: Thu, 22 Aug 2013 16:38:07 -0700 Subject: add more doc details, some more examples --- haxe.html.markdown | 90 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 40 deletions(-) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index 9ef69c64..1fa84a6d 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -16,27 +16,37 @@ references. Welcome to Learn Haxe 3 in 15 minutes. http://www.haxe.org This is an executable tutorial. You can compile and run it using the haxe compiler, while in the same directory as LearnHaxe.hx: - haxe -main LearnHaxe3 -x out - */ + $> haxe -main LearnHaxe3 -x out -// Let's start with comments... this is a single line comment + Look for the slash-star marks surrounding these paragraphs. We are inside + a "Multiline comment". We can leave some notes here that will get ignored + by the compiler. + + Multiline comments are also used to generate javadoc-style documentation for + haxedoc. They will be used for haxedoc if they immediately precede a class, + class function, or class variable. -/* - And this is multiline. Multiline comments are also used to generate - javadoc-style documentation for haxedoc. They will be used if they precede - a class, class function, or class variable. */ +// Double slashes like this will give a single-line comment + + /* - This is your first actual haxe code, it's declaring an empty package. A - package isn't necessary, but it's useful if you want to create a namespace - for your code (e.g. org.module.ClassName). + This is your first actual haxe code coming up, it's declaring an empty + package. A package isn't necessary, but it's useful if you want to create a + namespace for your code (e.g. org.module.ClassName). */ package; // empty package, no namespace. /* - if you import code from other files, it must be declared before the rest of - the code. + Packages define modules for your code. Each module (e.g. org.module) must + be lower case, and should exist as a folder structure containing the class. + Class (and type) names must be capitalized. E.g, the class "org.module.Foo" + should have the folder structure org/module/Foo.hx, as accessible from the + compiler's working directory or class path. + + If you import code from other files, it must be declared before the rest of + the code. Haxe provides a lot of common default classes to get you started: */ import haxe.ds.ArraySort; @@ -44,8 +54,8 @@ import haxe.ds.ArraySort; import haxe.ds.*; /* - you can also import classes in a special way, enabling them to extend the - functionality of other classes. More on 'using' later. + You can also import classes in a special way, enabling them to extend the + functionality of other classes like a "mixin". More on 'using' later. */ using StringTools; @@ -55,9 +65,13 @@ using StringTools; */ typedef FooString = String; -// Typedefs can also use "structural" types, more on that later as well! +// Typedefs can also reference "structural" types, more on that later as well. typedef FooObject = { foo: String }; +/* + Here's the class definition. It's the main class for the file, since it has + the same name (LearnHaxe3). + */ class LearnHaxe3{ /* If you want certain code to run automatically, you need to put it in @@ -66,6 +80,7 @@ class LearnHaxe3{ arguments above. */ static function main(){ + /* Trace is the default method of printing haxe expressions to the screen. Different targets will have different methods of @@ -75,8 +90,6 @@ class LearnHaxe3{ Finally, It's possible to prevent traces from showing by using the "--no-traces" argument on the compiler. */ - - trace("Hello World, with trace()!"); /* @@ -84,16 +97,11 @@ class LearnHaxe3{ a representation of the expression as best it can. You can also concatenate strings with the "+" operator: */ - trace( - " Integer: " + 10 + - " Float: " + 3.14 + - " Boolean: " + true - ); - + trace( " Integer: " + 10 + " Float: " + 3.14 + " Boolean: " + true); /* - Remember what I said about expressions needing semicolons? You - can put more than one expression on a line if you want. + In Haxe, it's required to separate expressions in the same block with + semicolons. But, you can put two expressions on one line: */ trace('two expressions..'); trace('one line'); @@ -107,7 +115,6 @@ class LearnHaxe3{ You can save values and references to data structures using the "var" keyword: */ - var an_integer:Int = 1; trace(an_integer + " is the value for an_integer"); @@ -119,7 +126,6 @@ class LearnHaxe3{ the haxe compiler is inferring that the type of another_integer should be "Int". */ - var another_integer = 2; trace(another_integer + " is the value for another_integer"); @@ -156,6 +162,12 @@ class LearnHaxe3{ var a_sub_string = a_string.substr(0,4); trace(a_sub_string + " is the value for a_sub_string"); + /* + Regexes are also supported, but there's not enough space to go into + much detail. + */ + trace((~/foobar/.match('foo')) + " is the value for (~/foobar/.match('foo')))"); + /* Arrays are zero-indexed, dynamic, and mutable. Missing values are defined as null. @@ -199,7 +211,7 @@ class LearnHaxe3{ trace(m3 + " is the value for m3"); /* - Haxe has many more common datastructures in the haxe.ds module, such as + Haxe has some more common datastructures in the haxe.ds module, such as List, Stack, and BalancedTree */ @@ -225,7 +237,7 @@ class LearnHaxe3{ trace((3 >= 2) + " is the value for 3 >= 2"); trace((3 <= 2) + " is the value for 3 <= 2"); - //bitwise operators + // standard bitwise operators /* ~ Unary bitwise complement << Signed left shift @@ -411,12 +423,11 @@ class LearnHaxe3{ As mentioned before, Haxe is a statically typed language. All in all, static typing is a wonderful thing. It enables - autocompletions, and can be used to check the correctness of a - program in very thorough ways. Plus, the Haxe compiler is super fast. - You probably won't be waiting on it very much. + precise autocompletions, and can be used to thoroughly check the + correctness of a program. Plus, the Haxe compiler is super fast. *HOWEVER*, there are times when you just wish the compiler would let - something slide, and not throw a type error in a limited case. + something slide, and not throw a type error in a given case. To do this, Haxe has two separate keywords. The first is the "Dynamic" type: @@ -429,12 +440,12 @@ class LearnHaxe3{ wildcard variable: You can pass it instead of any variable type, and you can assign any variable type you want. - The other more extreme option is the "untyped" keyword + The other more extreme option is the "untyped" keyword: */ untyped { - var x:Int = 'foo'; - var y:String = 4; + var x:Int = 'foo'; // this can't be right! + var y:String = 4; // madness! } /* @@ -444,9 +455,9 @@ class LearnHaxe3{ situations where type checking is a hinderance. In general, skipping type checks is *not* recommended. Use the - enum, inheritance, or structural type models in order to verify the - correctness of your program. Only when you're certain that none of - the type models work should you resort to "Dynamic" or "untyped". + enum, inheritance, or structural type models in order to help ensure + the correctness of your program. Only when you're certain that none + of the type models work should you resort to "Dynamic" or "untyped". */ ////////////////////////////////////////////////////////////////// @@ -459,7 +470,6 @@ class LearnHaxe3{ Create an instance of FooClass. The classes for this are at the end of the file. */ - var instance = new FooClass(3); // read the public variable normally -- cgit v1.2.3 From 0f82b183493a1f6142a6e7335d37891aae67c3dc Mon Sep 17 00:00:00 2001 From: Justin Donaldson Date: Fri, 23 Aug 2013 16:24:35 -0700 Subject: add more details on interpolated strings, clean up the naming for oop section --- haxe.html.markdown | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index 1fa84a6d..f4694fcb 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -151,8 +151,14 @@ class LearnHaxe3{ var a_string = "some" + 'string'; // strings can have double or single quotes trace(a_string + " is the value for a_string"); + /* + Strings can be "interpolated" by inserting variables into specific + positions. The string must be single quoted, and the variable must + be preceded with "$". Expressions can be enclosed in ${...}. + */ var x = 1; var an_interpolated_string = 'the value of x is $x'; + var another_interpolated_string = 'the value of x + 1 is ${x + 1}'; /* Strings are immutable, instance methods will return a copy of @@ -470,27 +476,27 @@ class LearnHaxe3{ Create an instance of FooClass. The classes for this are at the end of the file. */ - var instance = new FooClass(3); + var foo_instance = new FooClass(3); // read the public variable normally - trace(instance.public_any + " is the value for instance.public_any"); + trace(foo_instance.public_any + " is the value for foo_instance.public_any"); // we can read this variable - trace(instance.public_read + " is the value for instance.public_read"); + trace(foo_instance.public_read + " is the value for foo_instance.public_read"); // but not write it - // instance.public_write = 4; // this will throw an error if uncommented: - // trace(instance.public_write); // as will this. + // foo_instance.public_write = 4; // this will throw an error if uncommented: + // trace(foo_instance.public_write); // as will this. - trace(instance + " is the value for instance"); // calls the toString method - trace(instance.toString() + " is the value for instance.toString()"); // same thing + trace(foo_instance + " is the value for foo_instance"); // calls the toString method + trace(foo_instance.toString() + " is the value for foo_instance.toString()"); // same thing /* - Instance has the "FooClass" type, while acceptBaseFoo has the - BaseFooClass type. However, since FooClass extends BaseFooClass, - it is accepted. + The foo_instance has the "FooClass" type, while acceptBarInstance + has the BarClass type. However, since FooClass extends BarClass, it + is accepted. */ - BaseFooClass.acceptBaseFoo(instance); + BarClass.acceptBarInstance(foo_instance); /* The classes below have some more advanced examples, the "example()" @@ -508,7 +514,7 @@ class LearnHaxe3{ /* This is the "child class" of the main LearnHaxe3 Class */ -class FooClass extends BaseFooClass implements BaseFooInterface{ +class FooClass extends BarClass implements BarInterface{ public var public_any:Int; // public variables are accessible anywhere public var public_read (default,null): Int; // use this style to only enable public read public var public_write (null, default): Int; // or public write @@ -520,7 +526,7 @@ class FooClass extends BaseFooClass implements BaseFooInterface{ // a public constructor public function new(arg:Int){ - super(); // call the constructor of the parent object, since we extended BaseFooClass + super(); // call the constructor of the parent object, since we extended BarClass this.public_any= 0; this._private = arg; @@ -544,7 +550,7 @@ class FooClass extends BaseFooClass implements BaseFooInterface{ } // this class needs to have this function defined, since it implements - // the BaseFooInterface interface. + // the BarInterface interface. public function baseFunction(x: Int) : String{ // convert the int to string automatically return x + " was passed into baseFunction!"; @@ -554,19 +560,19 @@ class FooClass extends BaseFooClass implements BaseFooInterface{ /* A simple class to extend */ -class BaseFooClass { +class BarClass { var base_variable:Int; public function new(){ base_variable = 4; } - public static function acceptBaseFoo(b:BaseFooClass){ + public static function acceptBarInstance(b:BarClass){ } } /* A simple interface to implement */ -interface BaseFooInterface{ +interface BarInterface{ public function baseFunction(x:Int):String; } -- cgit v1.2.3 From c7a1136772588e57a3f9c20be9102a80a6f7f3e8 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 27 Aug 2013 21:23:09 -0700 Subject: Edits --- haxe.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index f4694fcb..eb39834e 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -11,7 +11,7 @@ Haxe author). Note that this guide is for Haxe version 3. Some of the guide may be applicable to older versions, but it is recommended to use other references. -```haxe +```csharp /* Welcome to Learn Haxe 3 in 15 minutes. http://www.haxe.org This is an executable tutorial. You can compile and run it using the haxe -- cgit v1.2.3 From 1c1dda235b6808f50eb0f8685477299fba785625 Mon Sep 17 00:00:00 2001 From: ryzed Date: Sat, 15 Feb 2014 23:10:35 +0300 Subject: Update haxe.html.markdown fixed typo --- haxe.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index eb39834e..6a868f09 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -231,7 +231,7 @@ class LearnHaxe3{ trace((4 + 3) + " is the value for (4 + 3)"); trace((5 - 1) + " is the value for (5 - 1)"); trace((2 * 4) + " is the value for (2 * 4)"); - trace((8 / 4) + " is the value for (8 / 3) (division always produces Floats)"); + trace((8 / 3) + " is the value for (8 / 3) (division always produces Floats)"); trace((12 % 4) + " is the value for (12 % 4)"); -- cgit v1.2.3 From 228cc6ec5ae0d20a94292c66cf43e44755d3758b Mon Sep 17 00:00:00 2001 From: Cameron Steele Date: Mon, 29 Dec 2014 15:00:12 -0800 Subject: typo in Haxe documentation --- haxe.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index 6a868f09..8599de8d 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -484,7 +484,7 @@ class LearnHaxe3{ // we can read this variable trace(foo_instance.public_read + " is the value for foo_instance.public_read"); // but not write it - // foo_instance.public_write = 4; // this will throw an error if uncommented: + // foo_instance.public_read = 4; // this will throw an error if uncommented: // trace(foo_instance.public_write); // as will this. trace(foo_instance + " is the value for foo_instance"); // calls the toString method -- cgit v1.2.3 From f1159951711a45c6f52b78ec247634c18f7de0b5 Mon Sep 17 00:00:00 2001 From: Dan Korostelev Date: Tue, 24 Mar 2015 01:19:13 +0300 Subject: Use "haxe" highlighting instead of C# --- haxe.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index 8599de8d..b8e6a265 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -11,7 +11,7 @@ Haxe author). Note that this guide is for Haxe version 3. Some of the guide may be applicable to older versions, but it is recommended to use other references. -```csharp +```haxe /* Welcome to Learn Haxe 3 in 15 minutes. http://www.haxe.org This is an executable tutorial. You can compile and run it using the haxe -- cgit v1.2.3 From 0e118934db0c6813482cee606ce15cec681a9ae0 Mon Sep 17 00:00:00 2001 From: Dan Korostelev Date: Tue, 24 Mar 2015 01:21:28 +0300 Subject: [haxe] some additions and fixes (closes #489) --- haxe.html.markdown | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index b8e6a265..e57c46a8 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -3,6 +3,7 @@ language: haxe filename: LearnHaxe3.hx contributors: - ["Justin Donaldson", "https://github.com/jdonaldson/"] + - ["Dan Korostelev", "https://github.com/nadako/"] --- Haxe is a web-oriented language that provides platform support for C++, C#, @@ -34,16 +35,20 @@ references. /* This is your first actual haxe code coming up, it's declaring an empty package. A package isn't necessary, but it's useful if you want to create a - namespace for your code (e.g. org.module.ClassName). + namespace for your code (e.g. org.yourapp.ClassName). + + Omitting package declaration is the same as declaring empty package. */ package; // empty package, no namespace. /* - Packages define modules for your code. Each module (e.g. org.module) must - be lower case, and should exist as a folder structure containing the class. - Class (and type) names must be capitalized. E.g, the class "org.module.Foo" - should have the folder structure org/module/Foo.hx, as accessible from the - compiler's working directory or class path. + Packages are directories that contain modules. Each module is a .hx file + that contains types defined in a package. Package names (e.g. org.yourapp) + must be lower case while module names are capitalized. A module contain one + or more types whose names are also capitalized. + + E.g, the class "org.yourapp.Foo" should have the folder structure org/module/Foo.hx, + as accessible from the compiler's working directory or class path. If you import code from other files, it must be declared before the rest of the code. Haxe provides a lot of common default classes to get you started: @@ -53,6 +58,12 @@ import haxe.ds.ArraySort; // you can import many classes/modules at once with "*" import haxe.ds.*; +// you can import static fields +import Lambda.array; + +// you can also use "*" to import all static fields +import Math.*; + /* You can also import classes in a special way, enabling them to extend the functionality of other classes like a "mixin". More on 'using' later. @@ -172,7 +183,8 @@ class LearnHaxe3{ Regexes are also supported, but there's not enough space to go into much detail. */ - trace((~/foobar/.match('foo')) + " is the value for (~/foobar/.match('foo')))"); + var re = ~/foobar/; + trace(re.match('foo') + " is the value for (~/foobar/.match('foo')))"); /* Arrays are zero-indexed, dynamic, and mutable. Missing values are @@ -383,11 +395,7 @@ class LearnHaxe3{ */ // if statements - var k = if (true){ - 10; - } else { - 20; - } + var k = if (true) 10 else 20; trace("K equals ", k); // outputs 10 @@ -628,6 +636,7 @@ enum ComplexEnum{ ComplexEnumEnum(c:ComplexEnum); } // Note: The enum above can include *other* enums as well, including itself! +// Note: This is what called *Algebraic data type* in some other languages. class ComplexEnumTest{ public static function example(){ -- cgit v1.2.3 From 03398877482f08c017e6774665f2c3b6e206ed34 Mon Sep 17 00:00:00 2001 From: Dan Korostelev Date: Tue, 24 Mar 2015 12:37:49 +0300 Subject: [haxe] polishing --- haxe.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index e57c46a8..c807d2d7 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -12,7 +12,7 @@ Haxe author). Note that this guide is for Haxe version 3. Some of the guide may be applicable to older versions, but it is recommended to use other references. -```haxe +```csharp /* Welcome to Learn Haxe 3 in 15 minutes. http://www.haxe.org This is an executable tutorial. You can compile and run it using the haxe @@ -37,7 +37,7 @@ references. package. A package isn't necessary, but it's useful if you want to create a namespace for your code (e.g. org.yourapp.ClassName). - Omitting package declaration is the same as declaring empty package. + Omitting package declaration is the same as declaring an empty package. */ package; // empty package, no namespace. @@ -636,7 +636,7 @@ enum ComplexEnum{ ComplexEnumEnum(c:ComplexEnum); } // Note: The enum above can include *other* enums as well, including itself! -// Note: This is what called *Algebraic data type* in some other languages. +// Note: This is what's called *Algebraic data type* in some other languages. class ComplexEnumTest{ public static function example(){ -- cgit v1.2.3 From f9032e0eca3c780870127c410edf5ec85db01560 Mon Sep 17 00:00:00 2001 From: sm4rk0 Date: Tue, 19 May 2015 18:17:35 +0200 Subject: Update haxe.html.markdown Correct the condition variable for "do statement always runs at least once" section --- haxe.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index c807d2d7..9b84a435 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -323,7 +323,7 @@ class LearnHaxe3{ var l = 0; do{ trace("do statement always runs at least once"); - } while (i > 0); + } while (l > 0); // for loop /* -- cgit v1.2.3 From 982b98468467c7a85f790fdcea2ff8d425b173de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Stankovi=C4=87?= Date: Wed, 20 May 2015 14:06:05 +0200 Subject: [haxe/en] Few cosmetic fixes * correct the array name in a for loop iterating on an index * add an assignment for "case _" in first switch example * fix case of variable name in trace for control statement returning as an expression * move some inline comments to a separate line above the statement to prevent text overflow --- haxe.html.markdown | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index 9b84a435..bbe51c79 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -340,7 +340,7 @@ class LearnHaxe3{ // (more on ranges later as well) var n = ['foo', 'bar', 'baz']; for (val in 0...n.length){ - trace(val + " is the value for val (an index for m)"); + trace(val + " is the value for val (an index for n)"); } @@ -375,7 +375,7 @@ class LearnHaxe3{ case "rex" : favorite_thing = "shoe"; case "spot" : favorite_thing = "tennis ball"; default : favorite_thing = "some unknown treat"; - // case _ : "some unknown treat"; // same as default + // case _ : favorite_thing = "some unknown treat"; // same as default } // The "_" case above is a "wildcard" value // that will match anything. @@ -397,7 +397,7 @@ class LearnHaxe3{ // if statements var k = if (true) 10 else 20; - trace("K equals ", k); // outputs 10 + trace("k equals ", k); // outputs 10 var other_favorite_thing = switch(my_dog_name) { case "fido" : "teddy"; @@ -495,8 +495,10 @@ class LearnHaxe3{ // foo_instance.public_read = 4; // this will throw an error if uncommented: // trace(foo_instance.public_write); // as will this. - trace(foo_instance + " is the value for foo_instance"); // calls the toString method - trace(foo_instance.toString() + " is the value for foo_instance.toString()"); // same thing + // calls the toString method + trace(foo_instance + " is the value for foo_instance"); + // same thing + trace(foo_instance.toString() + " is the value for foo_instance.toString()"); /* @@ -524,8 +526,8 @@ class LearnHaxe3{ */ class FooClass extends BarClass implements BarInterface{ public var public_any:Int; // public variables are accessible anywhere - public var public_read (default,null): Int; // use this style to only enable public read - public var public_write (null, default): Int; // or public write + public var public_read (default, null): Int; // enable only public read + public var public_write (null, default): Int; // or only public write public var property (get, set): Int; // use this style to enable getters/setters // private variables are not available outside the class. @@ -534,9 +536,10 @@ class FooClass extends BarClass implements BarInterface{ // a public constructor public function new(arg:Int){ - super(); // call the constructor of the parent object, since we extended BarClass + // call the constructor of the parent object, since we extended BarClass + super(); - this.public_any= 0; + this.public_any = 0; this._private = arg; } -- cgit v1.2.3 From 5816b59be65d47e6377cdad4c72b89f683bd0632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Stankovi=C4=87?= Date: Wed, 20 May 2015 14:29:05 +0200 Subject: [haxe/en] Adding colon after comments ...as per @vendethiel's advice --- haxe.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'haxe.html.markdown') diff --git a/haxe.html.markdown b/haxe.html.markdown index bbe51c79..ee214540 100644 --- a/haxe.html.markdown +++ b/haxe.html.markdown @@ -495,9 +495,9 @@ class LearnHaxe3{ // foo_instance.public_read = 4; // this will throw an error if uncommented: // trace(foo_instance.public_write); // as will this. - // calls the toString method + // calls the toString method: trace(foo_instance + " is the value for foo_instance"); - // same thing + // same thing: trace(foo_instance.toString() + " is the value for foo_instance.toString()"); @@ -536,7 +536,7 @@ class FooClass extends BarClass implements BarInterface{ // a public constructor public function new(arg:Int){ - // call the constructor of the parent object, since we extended BarClass + // call the constructor of the parent object, since we extended BarClass: super(); this.public_any = 0; -- cgit v1.2.3