It would improve ZScript's safety if struct/class fields could be made “readonly”, but still be written to from code that has private-level access to the field (i.e. is part of the same struct/class). That way, code elsewhere can't mistakenly write to those fields, but they can still be given a value. As it is, non-native readonly fields appear to be completely useless, since they can never be assigned any value.
Alternatively, perhaps they should be given behavior along the lines of Java “final” fields: the Init method can write to them, but they can never be written from anywhere else.
Allow writing to readonly fields from same class/struct
Moderator: GZDoom Developers
- Chris
- Posts: 2940
- Joined: Thu Jul 17, 2003 12:07 am
- Graphics Processor: ATI/AMD with Vulkan/Metal Support
Re: Allow writing to readonly fields from same class/struct
That's basically how const class members work in C++. They can be initialized/written to in the constructor's initializer list, but anywhere else is an error.argv wrote:Alternatively, perhaps they should be given behavior along the lines of Java “final” fields: the Init method can write to them, but they can never be written from anywhere else.
Re: Allow writing to readonly fields from same class/struct
On that note, proper initializers/constructors would be nice. I'm guessing they were left out for a reason, though.
- Graf Zahl
- Lead GZDoom+Raze Developer
- Posts: 49056
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: Allow writing to readonly fields from same class/struct
'readonly' means 'readonly', not 'private'! If you want somerthing different, name it differently!