3 ms·
> If you want to use somebody's else code, copy it verbatim into your project. Copy/paste is a code smell ;) A nice middle ground is referencing the code you
by chriswarbo 3y ago
> If you want to use somebody's else code, copy it verbatim into your project.
Copy/paste is a code smell ;)
A nice middle ground is referencing the code you want via its hash; rather than some ambiguous, made up identifier. That way:
- We retain the structure of separation, rather accumulating a big ball of mud.
- There's nothing ambiguous that needs "resolving": a hash corresponds to precisely one (known) file; assuming the algo's not been broken ;)
- Anyone using our project, anywhere in the world, at any time in the future, will get the exact same code.
- References to the same hash can be shared across projects directly (no need for e.g. deduplicating filesystems)
- We can reference multiple different copies/versions without conflict, since they'll have different hashes.
- Referenced files can be cached for as long as we like (since they won't change, there's no invalidation; although we may want to "garbage collect" to save space)
- No need for central "locations" (such as HTTP URLs): we can grab files from mirrors, P2P, other people's caches, etc. and it makes no difference to the file's hash.
- No need to trust third-parties, e.g. using HTTPS, PGP, etc. since we can verify whether the file we receive has the hash we want.
One way to do this is git submodules, although they rely on specific locations so we might want something like a magnet link for robustness and longevity.
Another is IPFS, whose addresses are content hashes.
Yet another is a tool like Nix, which has the advantage that we can calculate the contents of files; e.g. specifying our desired hashes in one place, and having them propagated/spliced/etc. as needed through the project (making it easier to update/replace in the future). We can also specify patches and arbitrary other pre-processing, to ensure we're getting precisely, and only, the code we want.
Note that these aren't mutually-exclusive: Nix and Git work very well together, for example.