std.essentials

Petar Petar
Sat May 22 06:37:30 UTC 2021


On Friday, 21 May 2021 at 06:31:53 UTC, Ogi wrote:
> On Thursday, 20 May 2021 at 15:25:58 UTC, Petar Kirov 
> [ZombineDev] wrote:
>> No, we should improve the build times of `import std`, until 
>> it performs better than your proposed version of `import 
>> std.essentials` :P
> This will not solve the problem with surprise imports.

That's a good point, though this is a general problem with 
non-selective imports of large modules / packages and not 
specific to `std`. My guess is that [`import vibe.d;`][0] /  
[`import vibe.vibe;`][1] exhibits a similar problems.

IMO, certain symbols (like the aforementioned 
`std.compiler.name`) are only meant to be available via static 
imports.
Which brings me to the question: why does `static import std;` 
not work? I logged [issue 21943][2]. This prevents all possible 
accidental name collisions with non-`static` imports. Also it 
should make compilation faster, since the compiler knows the 
exact file name where to search for the given symbol, similar to 
the [self-important lookup idiom][4].
Anyway, I would expect that we can mark certain `public imports` 
in the `std` package as `static` (e.g. [this one][3]), which 
should make them available only through their FQN. Also `static 
import std.stdio : writeln;` should work by allowing to use 
`writeln` directly while `File` only via FQN - `std.stdio.File`.

Said all that, I think `std.essentials` is a good idea! (I'm just 
against deprecating `std`, as it is a sound feature, which the 
language and Phobos should fully support.)
We should provide an opinionated selection of the most commonly 
used Phobos modules, that also best represent the language (e.g. 
not things like `std.demangle`, `std.signals`, `std.system` which 
are unlikely to be used often). After checking your list again, 
the only change I would do is to add 
`std.{json,file,path,process,sumtype}` and `std.parallelism : 
parallel`, as these are things I use in almost every script.

[0]: https://github.com/vibe-d/vibe.d/blob/v0.9.3/source/vibe/d.d
[1]: 
https://github.com/vibe-d/vibe.d/blob/v0.9.3/source/vibe/vibe.d
[2]: https://issues.dlang.org/show_bug.cgi?id=21943
[3]: 
https://github.com/dlang/phobos/blob/v2.096.1/std/package.d#L39
[4]: https://dlang.org/blog/2017/02/13/a-new-import-idiom/


More information about the Digitalmars-d mailing list