Hi there Dan.
--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.
public var x(default, null):Int;
In most language like C#, a "property" is not a variable, it is just a pair of methods made to look like a variable.
But it is starting to look like in Haxe a property is completely different. A property is actually a real variable, but it just has some extra flags on it, giving you the ability to override the "read" and "write" functionality. If that's the case it's unlike any notion of "property" I've ever used before which is part of the source of my confusion.
--
This page of the documentation should describe the specification, but also provide examples for all the combinations. This is rather important I agree.
A class field is a variable, property or method of a class which can either be static or non-static.
- Variable: A variable class field holds a value of a certain type, which can be read or written.
- Property: A property class field defines a custom access behavior for something that, outside the class, looks like a variable field.
- Method: A method is a function which can be called to execute code.
Variable fields hold values, a characteristic which they share with most (but not all) properties:
class Main {
static var member:String = "bar";
[...]
Next to variables, properties are the second option for dealing with data on a class. Unlike variables however, they offer more control of which kind of field access should be allowed and how it should be generated.
When dealing with properties, it is important to understand the two kinds of access:
A read access to a field occurs when a right-hand side field access expression is used. This includes calls in the form of
obj.field()
, wherefield
is accessed to be read.
A write access to a field occurs when a field access expression is assigned a value in the form of
obj.field = value
. It may also occur in combination with read access for special assignment operators such as+=
in expressions likeobj.field += value
.
Read access and write access are directly reflected in the syntax, as the following example shows:
class Main {
public var x(default, null):Int;
[...]
For the most part, the syntax is similar to variable syntax, and the same rules indeed apply.
The access identifiers define the behavior when the field is read (first identifier) and written (second identifier). The accepted values are:
default
: Allows normal (as in variable-like) field access if the field has public visibility, otherwise equal tonull
access.
null
: Allows access only from within the defining class.
get
/set
: Access is generated as a call to an accessor method. The compiler ensures that the accessor is available.dynamic
: Likeget
/set
access, but does not verify the existence of the accessor field.never
: Allows no access at all.
An accessor method (or short accessor) for a field namedfield
of typeT
is a getter namedget_field
of typeVoid->T
or a setter namedset_field
of typeT->T
.
Both getter and setter may access their physical field for data storage. The compiler ensures that this kind of field access does not go through the accessor method if made from within the accessor method itself, thus avoiding infinite recursion.
However, the compiler assumes that a physical field exists only if at least one of the access identifiers isdefault
ornull
.
(Thus,) A field is considered to be physical if it is either
- a variable
- a property with the read-access or write-access identifier being
default
ornull
- a property with
:isVar
metadata
function set_x(x) return x;
> - lack of usable code examples/annotations;
I agree we can have more examples. There's actually an open issue about
it [1].
> - lack of "User Contributed Notes" like in php (with voting) or better
> StackOverflow;
This was discussed before and dismissed. We actually had something like
that on the old API docs and it never took off in any notable way. I
realize many people praise the PHP documentation for it, but that is
largely because PHP's API documentation itself is garbage.
> Docs are almost dead:
> - it isn't really community driven;
> - it doesn't evolve because it's hard to maintain (tex, not md) and
> contribute;
> - doesn't get improvements from community notes/comments etc.
> - maintainers sees it as enought;
Oh please, the HaxeManual repository has 122 closed pull requests [2]
and almost 40 different people appear in the commit list [3]. There are
plans to move the sources to markdown [4] and once that is done we will
see if the contribution amount really increases.
> - as in the thread - assumes former knowledge - giving a STEEP
> LEARNING CURVE;
That's not uncommon for technical documentation. We cannot repeat all
the relevant information in every section, so the best we can do is
back-reference it properly.
> - doesn't contain links to valuable knowledge - f.e.
> http://blog.onthewings.net/2012/10/14/haxe-tips-everything-is-an-expression/
I don't mind adding some links to informative articles. Maybe a "Further
reading" box would be good for that.
If you want to help, open issues with _concrete_ suggestions of what to
do. I can't work with "We should do something somewhere/everwhere", you
have to point out specific sections and what you would like to see done.
Even better yet, send pull requests! I realize you're put off by the
sources being .tex, but adding a code example is a matter of adding a
.hx file to the the assets directory [5] and then put
`\haxe{assets/FileName.hx}` where you want it.