question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bundle implementation details into nested member that is better isolated

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kentonvcommented, 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.

0reactions
jdiaz5513commented, Aug 29, 2018

Resolved with #98.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Micro Frontend Architecture and Best Practices - XenonStack
Custom elements help to hide implementation details while providing a neutral interface to others. Isolate Team Code. Never share a runtime, ...
Read more >
How will react solve nested contexts? · Issue #14620 - GitHub
Ideally a multiple store solution would be implemented at different splits in the application, so nested contexts like this are much more ......
Read more >
How to handle deeply-nested nullable fields in JavaScript and ...
Option 1: Enter idx · A non-null assertion in TypeScript should be discouraged: Non-null assertion means — “I know better, compiler. Stop ...
Read more >
javascript - Is there an idiomatic way to test nested state branches ...
If I wanted to test this state, my first instinct is to create a version of this scope in my test suite, and...
Read more >
Organizing TypeScript code using namespaces
Therefore, we need to organize blocks of code using namespaces so that variables, objects, and classes are uniquely identified. In this article, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found