subconsciousnetwork / noosphere

Noosphere is a protocol for thought; let's discover it together!
Apache License 2.0
663 stars 40 forks source link

FFI: Roll noosphere context into sphere #272

Open jsantell opened 1 year ago

jsantell commented 1 year ago
          Future Thoughts: Wonder if we can bake the noosphere context into the sphere to simplify API in the future by removing the `noosphere` arg when a `sphere` has been provided (and "opened" via a context):
ns_sphere_t sphere = ns_sphere_fs_open(noosphere, "did:key:bob",  NULL);
ns_sphere_petname_set(sphere, "alice", "did:key:alice", NULL);

_Originally posted by @jsantell in https://github.com/subconsciousnetwork/noosphere/pull/271#discussion_r1134375356_

cdata commented 1 year ago

An ergonomic challenge here is that you still need to yield a ns_noosphere_t * to the FFI caller so that they can initialize additional spheres (or their first one) or create keys. So, you can't away from that pointer existing for APIs that work at a level above spheres.

And, if we roll it into the sphere, it would be nice to do it in a way that doesn't leave an orphaned pointer in the case that they "free" a ns_noosphere_t but still have an ns_sphere_t hanging around.

jsantell commented 1 year ago

An ergonomic challenge here is that you still need to yield a ns_noosphere_t * to the FFI caller so that they can initialize additional spheres (or their first one) or create keys. So, you can't away from that pointer existing for APIs that work at a level above spheres.

And, if we roll it into the sphere, it would be nice to do it in a way that doesn't leave an orphaned pointer in the case that they "free" a ns_noosphere_t but still have an ns_sphere_t hanging around.

Great points! Also worth clarifying that this issue isn't a suggestion, but an observation of a potential API simplification. Multispheres and multithreads could present challenges not presently worth the effort.