Prev | Current Page 88 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

When choosing the type to
use for your numerical data, you should use an Int if your value will always be less than 1073741823,
more than  1073741824, and will always be a whole number. Otherwise, use a Float .
Booleans
Bool eans represent one of two states: true or false . They are often used as a return value of an
expression or to store the state of an argument where there can be only two possible outcomes. For
example, you might decide that a flag can be kept depicting whether or not debug information should be
printed while your program is running. To do this, you could create a variable of type Bool called
displayDebugInfo and initialize it as false . Then, when you want all debug information to be
displayed in the console, you could simply change the value of this variable to true .
Unlike many other languages, booleans in haXe are identifiers only and do not have a numerical
representation. Therefore, the following is not acceptable in haXe:
var state : Int = 1;
var valid : Bool = state;
This restriction to the usage of booleans in haXe should be seen as a benefit, as this kind of cross - type
assignment in a statically typed language can lead to errors that statically typing is supposed to alleviate.


Pages:
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