I wrote universal object storage for Smalltalk (very dynamic language) as my hobby project and I just thinking, if it’s possible in Crystal.
For example in Smalltalk, when I need to load object (of any class) from data store (database), I just instantiate empty object of target class (from stored class name string) and then create a forward proxy object which targets this prepared empty object instance. My data model is then full of such forward proxies instead of real data objects.
Now, real object instvar loading in my Smalltalk project - when the first method call (method send) is made on a forward proxy (forward proxy knows OID of target object in the data store), doesNotUnderstand (something like method_missing) is called on my forward proxy, then I can load all instvars from data store to the empty proxy target object and then I can forward method call/send to the (now fully loaded) target object. So, whole data model object tree is loaded lazily from the data store just after first method call/send on forward proxies. I am pretty happy with it and everything works perfectly.
I hope it’s clear.
I am learning all the macros and metaprogramming things in Crystal right now - what do you think, is something similar possible in Crystal, or it’s rather not possible in statically compiled languages (even with macro tricks)? Thanks for your opinions!