-
Notifications
You must be signed in to change notification settings - Fork 23
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
Stdlib organization with re-export idiom #500
Comments
This goes into the right direction but the import/export idiom is not without its problems for discoverability, esp for newcomers. Also, I still don't know why e.g. |
Well, it shouldn't. The name Classifications like "miscellaneous string algorithms in the standard library", which to me is what |
One major problem with reexports imo is currently that the docs for reexported items don't show up, they just get listed in an "Exports" section (see here for an example). I think this should definitely be fixed before we do something like this. Apart from that, I like the idea of using submodules in the standard library, although I'm not sure about having a submodule for each macro in |
I thought the I think there is an RFC to overhaul the doc page structure that involves getting rid of the proc/template/iterator etc sections, maybe along with that we could add an "Exported" section to the bottom that shows the docs of all the exported symbols. |
Based off of #497 (comment)
A common idiom in Nimble packages is to have submodules for individual features of the package, then a main module that re-exports them all (i.e.
import foo/[a, b, c]
==import foo
). This means users both can pick only the features they need, and don't have to worry about which features they might need if they just import the main module.Applying this idiom in the standard library has already been discussed for
os
,times
,json
etc. but there might be some other existing applications that are easier to implement and less likely to cause breakages.1. Sugar
The
sugar
module currently consists of the following independent definitions:=>
and->
dump
anddumpToString
capture
dup
(depends onstd/private/underscored_calls
which is also used bystd/with
)collect
I propose these are put in their own submodules and then re-exported in sugar, with respectively the following module names:
std/sugar/arrows
orstd/sugar/lambdas
? Unsurestd/sugar/dump
std/sugar/capture
std/sugar/dup
std/sugar/collect
We could also drop the
sugar/
and just put these directly instd/
as they do not conflict with other modules. However this could be confusing, people couldimport std/[collect, dup, sugar]
and not realize.I also think the following, existing modules should be re-exported in sugar:
std/with
std/enumerate
std/decls
?std/wrapnils
?The point of "sugar" is that it's lazy/convenient, and the most convenient thing would be to have a unified import for all of these. But also we shouldn't have to import everything just for
collect
ordump
or arrows etc.2. Strings
strutils
contains a lot of important definitions for strings that aren't just "utilities", and so it is extremely popular along withstrformat
. On top of strutils, there isstrmisc
which is tiny and honestly isn't that disconnected from the rest of strutils.While it might be nice to split
strutils
for specific things people might need, it would be a huge effort and there is thenimrtl
stuff that maybe shouldn't be disturbed. However there are some minor things that could be done:allCharsInSet
could go in a separate module and get re-exported. Sometimes modules will import strutils just for these (example beingwordwrap
).parseutils
wrappers could go inparseutils
or a separate module and get re-exported/wrapped again. (alsofromHex
andparseHexInt
have the same implementation yet do not mention each other in documentation)std/formatfloat
is unrelated tostrutils.formatFloat
. We could rename the currentstd/formatfloat
tostd/floatdollar
or something, make a newstd/formatfloat
with the formatFloat procs and re-exportedfloatdollar
, then we can re-export that in strutils.formatSize
is out of place along with its enumBinaryFormatMode
. It could have its own module, and may or may not be re-exported.To make them easier to discover, we could also re-export
cstrutils
,strbasics
somewhere, and stuff likeeditdistance
,wordwrap
instrmisc
. There are also modules likeencodings
andunicode
that people aren't aware of sometimes and ask about, but these might be too big to re-export.The text was updated successfully, but these errors were encountered: