i am working on a framework to give twinbasic an 'everything is an object' type…
- User
i am working on a framework to give twinbasic an 'everything is an object' type object(called val). when you declare an object of it, it gives you various things:
- automatic or manual recasting of itself to subtypes like str which offers easy tools for string processing right there on the objectm, same for int which it can cast itself too, which then handles integer types, offering like math functions, a special index subversion for indexing purposes, conversion to hex, etc. same goes for bool which offers tools to return something alongside a boolean, etc. the whole thing will also offer 'contracts' which are settable invariant conditions alongside a desired response to the breaching of that contract, lets say printing a warning if an int exceeds a certain size, or clamping a string to a set max length when something tries to exceed it, or raising an error when some other condition occurs, etc. It can also control mutabolity that way by setting a contract for a value to only allow for one value. Also you can achieve type immutability like that by setting a contract that recasting from one domain to another (say str to bool) is not allowed
However, i am wondering: Right now in order to get the object to be able to cast itself in twinbasic i need a metaclass and a manager for it that handle those(through a collection). thats fine, kinda like python. The idea is that every objval when it gets created gets created inside a 'metaval' which holds the objval, and a collection of possible metavals (that would be out different subclasses like int, bool etc). I dont instantiate those right away, only when needed. And I guess that only like up to 4 would normally exist concurrently (say val->num->int->index) and typically it'd be only 2.
But that is still like 5 complex objects for one variable (our objval)
So im thinking....would it be smarter to drop the subtypes...and instead just change the interacting interface/facade? Imagine if the val type itself is quite light, and everytime it wants to do something, it goes through external objects that temporarily take its state....so we wanna do string ops...we dont cast change the userfacing val from within metaval, instead we change thhe routiinng of the setter and getter function, exposing an aleady existing string handler object, which just works on our value?
that way i coudl still have things like, say we have an object bla of type val/str...we could still do val.capitalize to capotalize the string value....but instead of housing those funcitons from within the object, the object interacts with an external item already existing in memory which temporarily gets used by val to byref change its internal value.
As a hald way house, it could also be that the val obj does do the reassignment of itself (thus emulating casting and needing th metaval and manager), but the classes themselves follow the same principle, where they just hook onto a global object with functions that they can borrow.
what wouuld be faster and/or more memory efficient?
- Assistant