Nim icon indicating copy to clipboard operation
Nim copied to clipboard

Add a new batteries module (which deprecates the prelude include)

Open AngelEzquerra opened this issue 1 year ago • 6 comments

New version of previous PR: https://github.com/nim-lang/Nim/pull/20037

This PR is implements a suggestion made as part of the discussion of https://github.com/nim-lang/Nim/pull/20022

It adds a new batteries module, which is similar to prelude but which must be imported (rather than included) and which adds a few more modules than prelude (sugar, options, strscans, algorithm and math).

AngelEzquerra avatar Jul 16 '22 11:07 AngelEzquerra

New modules should be put at std/ directory so that it enforces std prefix when importing them.

ringabout avatar Jul 16 '22 13:07 ringabout

I honestly don't like either of these modules - what modules someone views as "commonly needed" is going to change depending on the domain they're working in. Modules like these add yet another layer of indirection that users have to understand, and fulfill functionality (convenience) that is more appropriate for an IDE/editor.

Are imports really so tedious?

Varriount avatar Jul 16 '22 20:07 Varriount

New modules should be put at std/ directory so that it enforces std prefix when importing them.

I've moded batteries.nim (but not prelude) to std.

AngelEzquerra avatar Jul 17 '22 00:07 AngelEzquerra

Sorry that I'm changing my mind more frequently than my underwear about this but what is exactly the problem again? That you cannot remember include prelude? How couldn't you? It even rimes.

"Use include prelude or import std / yourmums" -- print it on a t-shirt, problem solved.

Araq avatar Jul 17 '22 09:07 Araq

Sorry that I'm changing my mind more frequently than my underwear about this but what is exactly the problem again? That you cannot remember include prelude? How couldn't you? It even rimes.

"Use include prelude or import std / yourmums" -- print it on a t-shirt, problem solved.

The main problem is, IMHO, that prelude is most useful for beginners. However beginners are the most likely to not know about nor understand the difference between importing and including. This means that in order to use prelude, which is meant to make things "easy" you first need to introduce the concept of include, which is in my opinion totally unnecessary.

I must say that I myself I've made this particular mistake multiple times, even after knowing the difference between include and import.

In addition to that it was suggested in the previous version of this PR that we could add a few more common modules (such as sugar and math) but that rather than adding them to prelude we could add them to a new importable module.

Please let me know if you do not want me to keep pushing for this. I think it would be a small improvement to the language because it would reduce its complexity (by letting most people only have to know about import).

AngelEzquerra avatar Jul 17 '22 10:07 AngelEzquerra

I would still rather just see the preclude module deprecated and no module added. Again, given the fact that what is considered "commonly needed" is rather situation-dependent, it's better for individual projects to create these kinds of modules, not the standard library.

With regards to the intended audience for this module (beginners), I would also like to point out that using the import/export mechanics like this can be as confusing as the include mechanic.

Varriount avatar Aug 01 '22 00:08 Varriount

If in doubt, leave it out. Instead the documentation shouldn't mention "include prelude" if it causes so much confusion.

Araq avatar Sep 28 '22 13:09 Araq