misc reformat, and some small details

This commit is contained in:
Justin Donaldson 2013-08-19 21:54:38 -07:00
parent c39c3680cf
commit 78133a784f

View File

@ -12,22 +12,29 @@ may be applicable to older versions, but it is recommended to use other
references. references.
```haxe ```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 Welcome to Learn Haxe 3 in 15 minutes. http://www.haxe.org
// compiler, while in the same directory as LearnHaxe.hx: This is an executable tutorial. You can compile and run it using the haxe
// haxe -main LearnHaxe3 -x out 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 // 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 A package declaration isn't necessary, but it's useful if you want to
// expressions in Haxe must end in a semicolon: organize your code into modules later on. Also worth mentioning, all
expressions in Haxe must end in a semicolon:
*/
package; // empty package, no namespace. package; // empty package, no namespace.
// if you import code from other files, it must be declared before the rest of // if you import code from other files, it must be declared before the rest of
// the code. // the code.
import haxe.ds.ArraySort; import haxe.ds.ArraySort;
@ -66,12 +73,14 @@ class LearnHaxe3{
/* /*
Trace can handle any type of value or object. It will try to print 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( trace(
" Integer: " + 10 + " Integer: " + 10 +
" Float: " + 3.14 + " Float: " + 3.14 +
" Boolean: " + true); " Boolean: " + true
);
/* /*
@ -125,9 +134,12 @@ class LearnHaxe3{
structures like strings, arrays, lists, and maps: 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"); 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 Strings are immutable, instance methods will return a copy of
parts or all of the string. parts or all of the string.
@ -280,8 +292,10 @@ class LearnHaxe3{
// while also creating filters and modifications. // while also creating filters and modifications.
var filtered_n = [for (val in n) if (val != "foo") val]; var filtered_n = [for (val in n) if (val != "foo") val];
trace(filtered_n + " is the value for filtered_n"); trace(filtered_n + " is the value for filtered_n");
var modified_n = [for (val in n) val += '!']; var modified_n = [for (val in n) val += '!'];
trace(modified_n + " is the value for modified_n"); trace(modified_n + " is the value for modified_n");
var filtered_and_modified_n = [for (val in n) if (val != "foo") val += "!"]; 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"); trace(filtered_and_modified_n + " is the value for filtered_and_modified_n");
@ -359,26 +373,31 @@ class LearnHaxe3{
// See documentation for parsing in Std for more details. // 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); var instance = new FooClass(3);
// read the public variable normally // read the public variable normally
trace(instance.public_any + " is the value for instance.public_any"); trace(instance.public_any + " is the value for instance.public_any");
// we can read this variable // we can read this variable
trace(instance.public_read + " is the value for instance.public_read"); trace(instance.public_read + " is the value for instance.public_read");
// but not write it, this will throw an error if uncommented: // but not write it
//trace(instance.public_write + " is the value for instance.public_write"); // instance.public_write = 4; // this will throw an error if uncommented:
// trace(instance.public_write); // vice-versa for public write, etc. // trace(instance.public_write); // as will this.
trace(instance + " is the value for instance"); // calls the toString method 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, // instance has the "FooClass" type, while acceptBaseFoo has the
// since it was extended from that. // BaseFooClass type. However, since FooClass extends BaseFooClass,
// it is accepted.
BaseFooClass.acceptBaseFoo(instance); BaseFooClass.acceptBaseFoo(instance);
} }
@ -430,6 +449,9 @@ class FooClass extends BaseFooClass implements BaseFooInterface{
} }
} }
/*
A simple class to extend
*/
class BaseFooClass { class BaseFooClass {
var base_variable:Int; var base_variable:Int;
public function new(){ public function new(){
@ -437,9 +459,11 @@ class BaseFooClass {
} }
public static function acceptBaseFoo(b:BaseFooClass){ public static function acceptBaseFoo(b:BaseFooClass){
} }
} }
/*
A simple interface to implement
*/
interface BaseFooInterface{ interface BaseFooInterface{
public function baseFunction(x:Int):String; public function baseFunction(x:Int):String;
} }