-
Notifications
You must be signed in to change notification settings - Fork 556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Adding const
versions of Object
s.
#1156
Comments
Well, of the built-in classes, several are immutable already and, to my mind, the only other ones where it might be useful to have
So I think I'd be very much in the 'do nothing' camp here and leave it to library writers or other users to create Sealing classes is, of course, a different matter to immutability and most of the built-in classes are implicitly sealed for good reason. In general, though, I'd be against sealing user defined classes as my experience with other languages which allow this is that it can be a nuisance in practice and people will try to find ways around it. I didn't follow your point about controlling mutation of static variables as they aren't inheritable (at present anyway) and you can control access to them by just having a |
While I understand your points, a
As of today, the static variables ( |
I'm just throwing ideas around here but one answer to this would be to have a |
If interface become a concrete thing, most functionality could go in there, but that would not solve hierarchy either. |
One solution from some java developer: using attributes is to create an |
That's a possibility though currently attributes in Wren are just user-defined so we'd need to extend that to allow built-in ones. Javascript has an |
Seems there is also prior art in Pharo Smalltalk with In practice, it should only need to be checked for primitives/foreign, and for static methods (because of implementation details). We can automatically intercept writes to instances in |
Made a basic implementation. I still have to add test to ensure it works properly before I can publish something more seriously. Thought the initial penalty is quite "low".
That said, I made a quick check about
|
Better than I expected. Might be a viable approach after all :) |
Hi,
For reasons, some
const
versions of objects are required from time to time. I can think of at least 3 strategies:attribute with
Object.constify()` (or `isSealed` with `seal()`). It would forbid write access inside the VM of `ObjInstance`s (aka all the regular objects).It can also be used in `Class` to forbid subclassing after the hierarchy is created(I remember proposing something similar with `final` but that ones make somehow more sense).It would have the drawback to be best effort in other cases.edit: Removed the part of using it for controlling subclassing. It would make more sense if it was controlling mutation of static variables. But due to implementation details, it is not possible without heavy change in the
Class
implementation.The text was updated successfully, but these errors were encountered: