mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-09 21:28:39 +01:00
30 lines
989 B
Plaintext
30 lines
989 B
Plaintext
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?
|
|
}
|
|
}
|
|
|
|
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?
|