Skip to content
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

Bundle implementation details into nested member that is better isolated #45

Closed
efokschaner opened this issue Jul 17, 2017 · 5 comments
Closed

Comments

@efokschaner
Copy link
Contributor

When hiding implementation details in accessible places (and especially a dynamic language) it definitely pays to use symbols that have low accidental collision likelihood.

Take our static member called _id for example (https://github.com/jdiaz5513/capnp-ts/blob/master/packages/capnp-ts/src/std/schema.capnp.ts#L149). I'm sure there's some other library out there somewhere that decided they'd hide _id members on class (constructor) objects, for us to collide with.

I noticed the official C++ compiler does the following: https://github.com/capnproto/capnproto/blob/master/c%2B%2B/src/capnp/schema.capnp.h#L95

Its nested bundle has two nice features IMO. 1. It's got a very project / tool specific name, so other systems are less likely to conflict. 2. Even if autocomplete / intellisense / whatever is aware of the implementation detail members it sucks them into a single ignorable entry in the list.

Therefore, I propose we take a similar approach with the implementation details that we're bundling into types.

@jdiaz5513
Copy link
Owner

I like that. There should also be room in that _capnpPrivate static member for a grab bag of extra properties for those concrete list types (https://github.com/jdiaz5513/capnp-ts/blob/master/packages/capnp-ts/src/std/schema.capnp.ts#L151-L153).

@jdiaz5513
Copy link
Owner

jdiaz5513 commented Jul 17, 2017

There's also #47 to think about how to hide all those methods in Pointer/Struct/List that really shouldn't be exposed on the object at all.

It doesn't help that VSCode's Intellisense sorts all underscore methods to the top 😓 .

@kentonv
Copy link

kentonv commented Jul 17, 2017

ES6 also has "symbols" -- special field names that are not strings, and can be kept strictly private.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol

There appear to be polyfills available that fall back to obfuscated names under ES5.

Symbols can be clunky to work with, though.

@jdiaz5513
Copy link
Owner

Symbols are an idea, but IIRC they are very slow, either with a polyfill or with native support.

@jdiaz5513
Copy link
Owner

Resolved with #98.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants