is "import std; " a valid approach or a violation of the D programming language?

Steef Boerrigter sxmboer at gmail.com
Thu May 6 22:27:21 UTC 2021


I've been using

     import std;

at the top of my code for a while using dmd.

None of the examples in Andrei or Ali's books do this, but 
following the turtles all the way down principle they should also 
be able to go all the way up. (or no?)

Or call me lazy. I get why and how the compiler can more 
efficiently produce code using highly specific imports within 
each context, but I've tested this and it only adds about .3 s to 
my compiles, so why would I bother to try and optimize my compile 
time?

This one-import-rules-all approach saves me a bunch of time 
figuring out which import should go where, so overall, makes 
programming in D much more efficient for my purposes. Either way, 
it seems valid to me and has worked with dmd just fine.

However, gdc does not compile any code using this approach:

     chocolate>gdc ocr.d
     ocr.d:7:8: error: module std is in file 'std.d' which cannot 
be read
         7 | import std;
           |        ^
     import path[0] = 
/usr/lib64/gcc/x86_64-slackware-linux/10.2.0/include/d


My question is now, am I abusing an oversight in dmd when I 
import the entire phobos library, or is it a bug of gdc to *not* 
accept this approach?


Steef



More information about the Digitalmars-d mailing list