4 ms·
Yes, you missed the point where you as the programmer can choose the semantics of the language as you go, rather than the language designer doing it ahead of ti
by db48x 5y ago
Yes, you missed the point where you as the programmer can choose the semantics of the language as you go, rather than the language designer doing it ahead of time. Instead of having a language designer pick one spot in a large space of possible designs, the Metaobject Protocol gives the language user the ability to pick their own spot within that space.
You can have sparse objects in the one project where they are needed, while not bothering in projects where they aren’t. You can have version controlled objects, or database–backed objects, or objects which implement inheritance differently. If you can think of it, you can probably do it.
- brundolf 5y agoThat still sounds like getters/setters, then (which you could use to implement properties-as-a-hash-map, for example). Maybe the ergonomics are different - we're still speaking pretty abstractly here so it's hard to tell - but it sounds like the same basic idea: class TimePeriod { private double _seconds; public double Hours { get { return _seconds / 3600; } set { if (value < 0 || value > 24) throw new ArgumentOutOfRangeException( $"{nameof(value)} must be between 0 and 24."); _seconds = value * 3600; } } }
- db48x 5y agoGetters and setters are nice, but you can’t use them to write a new solution to the diamond inheritance problem.
- deleted 5y ago[deleted]
- nielsbot 5y agoOne of my favorite research papers which really changed my thinking about this stuff: “Open, Accessible Object Models” by Ian Piumarta https://www.piumarta.com/software/id-objmodel/objmodel2.pdf https://www.piumarta.com/software/id-objmodel/objmodel2.pdf He describes a minimal object model that leaves almost every aspect of the object programming open to change by the end user. I don’t know Lua well, but sounds like Lua has a similar system where you can even change, at runtime, how slots are looked up in objects.
- kaba0 5y agoWhat about smalltalk, or its recent resurrection, pharo?
- scroot 5y agoPiumarta's papers are totally underrated! There is only one thing I didn't understand from that paper (as a barely-used-c programmer), which is what does it mean to access some_array[-1]? His COLAs paper seems like it's really interesting as well, but I can only understand maybe 30% of it.
- nielsbot 5y agoHe proposes placing a value's vtable pointer in the memory word before the value's base address. Now you can pass the value around to APIs that expect, say, a C-struct. But the vtable is "secretly" attached to it so you can call methods on it from your language implementation.
- scroot 5y agoI guess I just don't know C well enough. How can it be legal to put anything at a memory address before a given array? Does the compiler magically manage this? (Also if you know of any posts about this technique I would really appreciate it)
- nielsbot 5y agoIt took me a lot of readings to really get what he's saying in this paper...
- kaba0 5y agoWhat about only providing methods named after fields for outside use? That way you can extend that class to provide either field-based access or anything else you like. E.g. in scala there is no syntactic difference between method and field access so code will compile with both person.age and person.age(), while implementation can be both “sparse and dense”.