JSIDL ideas for read only (Was: RE: Figuring out easier readonly interfaces)

Forking threads since I took this on a tangent...

My preferred solution to the readonly "problem," in the pie-in-the-sky JSIDL future, would look something like this:

```jsidl
class Point {
  get number x
  get number y

  get number length
}

class MutablePoint extends Point {
   set x(ToNumber)
   set y(ToNumber)
}
```

Here the setters in MutablePoint do a brand check (similar to that at [1]), preventing you from applying them to Point.

I realize this doesn't help you until JSIDL becomes more realistic, but I am curious what the thoughts of you or others are on this list toward such a solution, as part of my ongoing gathering-pre-feedback process for JSIDL in general. I think that it strikes the right balance of expressiveness and verbosity.

---

Another idea I had, actually inspired by something Anne said, would the following. It tends more on the verbose side, but perhaps would be useful in that it exposing more primitives that can be discussed in prose.

```js
class Point {
  private [[x]], [[y]] 

  constructor(ToNumber x: [[x]], ToNumber y: [[y]])

  get number x: [[x]]
  get number y: [[y]]

  get number length
}

class MutablePoint extends Point {
  set x(ToNumber): [[x]]
  set y(ToNumber): [[y]]
}
```

Here spec algorithms (e.g. that for `length`) could refer to and manipulate the internal data properties `[[x]]` and `[[y]]`. This would desugar to manipulating the appropriately-hidden elements in the WeakMap, e.g. `[[x]]` stands in for `privates.get(this).x` in [1]. The colon syntax is just a way to perform the most-common operations on those internal properties; it has a slightly different meaning in each context I use it.

The goal, as with all of JSIDL, is to provide extremely simple desugaring to idiomatic ES. That's why I like this solution over some kind of declarative proxy creation, as nobody would use a proxy to enforce readonly-ness for this kind of simple situation.

Feedback welcomed and desired!

[1]: https://gist.github.com/domenic/6736258

Received on Thursday, 3 October 2013 00:14:56 UTC