-
Notifications
You must be signed in to change notification settings - Fork 13
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
Export all constants? #1
Comments
Hi, first of all very useful package! What's your reasoning behind supporting multiple datasets in the first place? These are constants after all and I feel we should always use the most accurate results available and not confuse the user by having to choose a dataset. At least as a default. I, for example, had never heard of CODATA2014. Regarding this issue, we could then just export a global |
For example backward compatibility: one may need to continue working with a specific dataset, without holding back the whole package. And can then switch to a different dataset just by using a different module. In addition, CODATA is the only dataset I know, but there can be different projects to measure fundamental constants |
Also astropy uses different modules for different datasets(e.g., different editions of the same project): http://docs.astropy.org/en/stable/constants/ |
-1 for exporting many small names. I don't think anything should be exported by this package. Instead it is best to do (as a user)
Such small names are typically easily already in use. So even if someone wants the speed of light, but already has bound
edit: Scratch that: I can already see that no name is exported by this package besides the |
I'm starting to like the suggestion by @crstnbr to export a single object that can be used to reference all constants. I've came up with a crazy idea on how to do this, I'll see if this works. @Datseris actually, currently all constants are exported by the CODATA submodule, this is done under the hood by the |
Would make it sense to split the datasets into separate packages and keep here only the basic infrastructure to define constants? Fox example, I'm thinking about defining astronomical constants, but they probably wouldn't fit here. In other Physics subfields people may want other constants, that are of general interest. In this way, the name of the module would be much shorter (no |
This becomes too convoluted. I don't see any reason for this complexity. Less repos = easier to handle. It's clear that this package will have 1-2 dependencies (Unitful) and only text files as a source. 100 more lines for more constants do not seem like a deal to me. I prefer 1 package with many submodules. It is not a big deal to do:
And also make all submodules export all their constants. This way you can still either only use the ones you want, with the syntax above, or you can use all of them by doing
It is kind of clear that different submodules would have different constants sets. And even if it isn't, as long as it is documented, then it is. |
Ok ok, makes sense, thank you! I've just realized that the name of the submodule is automatically exported when you load it, I thought it wasn't! So right now you can already do: julia> using PhysicalConstants.CODATA2014
julia> CODATA2014.c
Speed of light in vacuum (c)
Value = 2.99792458e8 m s^-1
Standard uncertainty = (exact)
Relative standard uncertainty = (exact)
Reference = CODATA 2014 Does it sound like a good solution? In this case I'd just have to not export the constants when defining them inside the macro. |
What my personal vote for the API is:
This is nice because it allows the following:
After this is done and published, we can make a poll of which module to be the default, i.e. inside the source we can write
which would allow |
I'm not sure whether I'm a fan of the using PhysicalConstants.Astro: a, b, c approach. I guess it's because I don't really like the fact that I'd have to tell the package what constants I would like to get on loading the package. I might not know in advance which constants I'll need. The only alternative would be to load all of them and pollute the namespace. Also, how would I get an overview of all available constants in a (sub)module from within the REPL? Regarding the categorical submodules (like Astro), this should only be used for (very) specific constants. I'd hate it to have to figure out which constant lives in which submodule. |
Documentation by
EDIT: The comment
has little strength to it: for the interactive case, if you don't know in advance which constants you need it is by far the safest approach to import them one by one than to immediatelly load 100 names which you won't even know how they are called, since you don't know in advance. For the scripting case, it has no meaning whether you know them in advance or not. You still put them in the first line of your script :D |
This would only work after To submodules: One just shouldn't over-categorize. Apart from that I agree that separating is the better choice. |
Not knowing which ones I need doesn't mean I don't know how they are called when I need them. But I also wasn't suggesting to load all of them to global namespace in this case. An alternative could be to export a container |
Yes yes this is also exactly why I suggested aaaafter this package has seen some use, then we can consider a specific dataset to be the default, or not at all.
I totally agree, although @giordano made a very strong point of backwards compatibility with the example of the
I don't see how this is different from having a module... In fact it is identical. I can't tell any difference with what you suggested and what I suggested :D Unless you mean to have one extra "global" like module, like |
I think we all agree that the base module shouldn't export anything. It's the current situation and it's documented in the @crstnbr The container can be the submodule itself, like in my example above: when you load a submodule its name is exported. This would also have the advantage of featuring auto-completion in the REPL: julia> using PhysicalConstants.CODATA2014
julia> CODATA2014.m_
m_e m_n m_p m_u
julia> CODATA2014.m_e
Electron mass (m_e)
Value = 9.10938356e-31 kg
Standard uncertainty = 1.1e-38 kg
Relative standard uncertainty = 1.2e-8
Reference = CODATA 2014 It's clear for users what constants they're referring to (electron mass from CODATA2014, rather another |
Your use case is different from what @Datseris suggested in that the submodule EDIT2: Also, I really see no use case where someone would need all constants of a submodule. EDIT: We could even control |
I'm basically thinking of the (dumb) user scenario where a user just wants to get some of the most important physical constants (speed of light, hbar and so on) as simply as possible. He wouldn't know about any dataset or category submodules that we came up with. Basically, what he wants to do is just |
I don't think that it makes sense to not export anything when a user types If users, or especially package authors are worried about cluttering their namespace, then they should |
I am user of physical constants (not this module) and there are no standard module for them due to many packages lack in function, so I implemented module for myself. In my module, # freqeuntly used constants defined in CODATA
export
AtomicMassConstant,
AvogadroConstant,
BoltzmannConstant,
ConductanceQuantum,
ElectricConstant,
ElectronMass,
ElectronVolt,
ElementaryCharge,
FaradayConstant,
FineStructureConstant,
InverseFineStructureConstant,
MagneticConstant,
MagneticFluxQuantum,
MolarGasConstant,
NewtonianConstantOfGravitation,
PlanckConstant,
PlanckConstantOver2pi,
ProtonMass,
ProtonElectronMassRatio,
RydbergConstan,
SpeedOfLightInVacuum,
StefanBoltzmannConstant I think we should export their (natural language) name and symbolic name should not be exported. Anyway I want this module to have all CODATA2014 values (https://github.com/Paalon/CODATA2014.jl/blob/master/src/allascii.csv) because this doesn't have all of them. |
I've been quite busy lately and this will last other ~15 days, after that I hope to be able to resume this discussion. I just want to quickly reply to this comment:
The rationale about this decision is that the package contains different submodules with different datasets, which can also define different values for the same physical constant (like different versions of CODATA). Users will do The discussion here is whether to export all constants in the submodules or not. I think I kind of like @Paalon's suggestion to export long names. |
My ~15 days lasted quite a long time 😅 Now that #2 is fixed, To summarise, I think we all agree that Now, my question is: what do we export from the dataset submodule? How do we name the constants: long descriptive names or (possibly very) short abbreviations? I think these questions are kind of linked, because polluting the main workspace with several short names is not going to be fun, on the other hand many users would prefer referring to the speed of light as |
IMO long descriptive names should be used for the type definition and adding short handle like |
It's not clear to me whether you're suggesting that the package or the users should define the shorthands.
I agree on this, it's quite unlikely that someone is going to frequently use all the available constants and will probably care only about a few of them. But defining a minimum set of common constants is totally arbitrary and everyone would complain "why X is shortened but not Y? I use Y all the time and I don't want X shortened". |
I meant having the shorthands in the package, but not export them. This way we don't litter other peoples namespaces and the user can still write |
So your idea would be to provide non-exported shorthand for some constants? I think I like it. |
Could be even for all, if there is a common used one. |
I've implemented in #7 the ideas suggested here. The
Note also that without explicitly importing anything, one could do also something like this: julia> using PhysicalConstants
julia> const cnst = PhysicalConstants.CODATA2014
PhysicalConstants.CODATA2014
julia> cnst.c_0
Speed of light in vacuum (c_0)
Value = 2.99792458e8 m s^-1
Standard uncertainty = (exact)
Relative standard uncertainty = (exact)
Reference = CODATA 2014
julia> cnst.G
Newtonian constant of gravitation (G)
Value = 6.67408e-11 m^3 kg^-1 s^-2
Standard uncertainty = 3.1e-15 m^3 kg^-1 s^-2
Relative standard uncertainty = 4.6e-5
Reference = CODATA 2014 |
Currently the submodule
CODATA2014
exports all constants. This definitely cluttersMain
with some short names. On the other end, without automatic exports, users would have to spell in fullPhysicalConstants.CODATA2014.c
, unless they do something likewhich may not be very convenient.
A good point of not exporting the constants is that it would be easy to load two different datasets providing different values for the same constants (e.g., other CODATA datasets) and use values from one module or another without messing things up.
I'm not sure what's the best thing to do here.
The text was updated successfully, but these errors were encountered: