musictheory / NilScript

Objective-C-style language superset of JavaScript with a tiny, simple runtime
Other
50 stars 5 forks source link

Rethink and simplify properties #163

Open iccir opened 4 years ago

iccir commented 4 years ago

Moving forward, properties are going to be simpler. This aligns with some long term goals of better taking advantage of ES6 classes.

  1. @property will always synthesize a backing ivar with a _ prefix.
  2. @synthesize goes away.
  3. @dynamic goes away.
  4. @observe is useful, but in practice we only use a single case (change + after). We also always call a single "update" method regardless of the changes.
iccir commented 4 years ago

Overview of new property system:

  1. @property always synthesizes a backing ivar.
  2. Ivars may no longer be manually defined. For ivars without public getter/setter methods, use the private attribute.
  3. Backing ivars are accessed as an identifier of (_ + property name) when inside of a method definition.
  4. The actual implementation of backing ivars (whether or not they exist as properties on an object) is left up to the compiler. The compiler may decide to removed the property as an optimization, or it may decide that a getter/setter can be inlined for performance reasons.
  5. As a result of 3, use of ivars from a category is now prohibited.
  6. As a result of 3, use of ivars from a subclass is now prohibited.
  7. Subclasses may not redefine properties. In practice, this is rarely an issue.
iccir commented 4 years ago

The --simple-ivars flag is now always true (not a change from 2.x, but a change from previous 3.0 builds)