-
Notifications
You must be signed in to change notification settings - Fork 39
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
Comments
I like that. There should also be room in that |
There's also #47 to think about how to hide all those methods in It doesn't help that VSCode's Intellisense sorts all underscore methods to the top 😓 . |
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. |
Symbols are an idea, but IIRC they are very slow, either with a polyfill or with native support. |
Resolved with #98. |
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.
The text was updated successfully, but these errors were encountered: