1
0
forked from Mirror/wren
Files
wren/doc/implicit fields.txt

30 lines
989 B
Plaintext
Raw Permalink Normal View History

2013-11-14 20:57:56 -08:00
Q: Can fields be implicitly declared?
The idea is that just using a name starting with "_" somewhere in a class
automatically defines a field with that name. Implicit fields are particularly
nice because it means they don't have to be defined all before methods. (Since
we have a single-pass compiler, we would have to otherwise a method could
only refer to previously defined fields.)
One potential problem is with nested classes. This is more important if we
consider a module effectively a class. Consider:
class Outer {
foo {
_blah = "value"
}
class Inner {
IO.write(_blah) // Does this declare field in Inner, or access Outer?
2013-11-14 20:57:56 -08:00
}
}
Looking at this, though, I think there's already a question how referring to an
outer field would work. Having an instance of Inner doesn't imply you also have
an instance of Outer. We definitely don't want to recapitulate inner classes
in Java.
Q: What about static fields?
A: Different naming convention? __foo?