There is no const
keyword in Haxe to define constants like in ActionScript.
So never
keyword can be used to define constants/read-only variables as shown below.
If you try to set the value of MAX_COUNT, compiler will throw an error saying “Cannot access field or identifier MAX_COUNT for writing”.
For static variables and functions inline
keyword can be used as a powerful optimization tool.
The following is a way to define static constant/read-only variables using “inline”.
inline
should be carefully used with functions as not all functions will be ideal candidates for optimization.
At run-time the function call
will be translated to the following by eliminating the function call.
As per the official documentation,
It is not always easy to judge if a function is ideal for inline. Short functions that have no writing expressions (such as
a = value
) are usually a good choice, but even more complex functions can be candidates. However, in some cases inlining can actually be detrimental to performance, e.g. because the compiler has to create temporary variables for complex expressions.
Note that inline
can be totally disabled by passing compiler argument --no-inline
.