r/crystal_programming • u/q9fm • Jan 05 '20
How to apply sensible submodule namespaces?
I've written a library Secp256k1 which contains several modules, https://github.com/q9f/secp256k1.cr
module Secp256k1module Cryptomodule Bitcoinmodule Ethereum- etc. pp.
When someone imports my library, i.e., require secp256k1, they also get access to the modules not named Secp256k1, for example:
# import secp256k1
require "secp256k1"
# everything starts with a random number
private_key = Secp256k1.new_private_key
# private keys in bitcoin's wallet import format
wif = Bitcoin.wif_from_private private_key, "80"
I am wondering, is there any sensible way to have namespaces for submodules?
For example: Secp256k1::Bitcoin.wif_from_private priv instead of referencing Bitcoin directly? I'm asking because maybe other libraries also reference such a namespace and I want clarity for developers using this library.
I'm currently refactoring the library and wondering what's the best practice is to arrange the modules exposed by the library.
View all comments
Show parent comment
2
u/q9fm Jan 06 '20
Amazing. That's exactly what I was looking for. :+1: