| > Why do unused imports slow down compilation? Why would it not? It needs to check the tree imported for side-effects. Like I said this is true for C++, C, and Python at least too. > "'Include what you use' means this: for every symbol (type, function, variable, or macro) that you use in foo.cc (or foo.cpp), either foo.cc or foo.h should include a .h file that exports the declaration of that symbol." The analogy doesn't work well because "import" in Go is both a replacement for "include" and for linker flags. Needless imports is like adding needless .o files on your linker line. The linker cannot know if you meant to call those constructor sections. My comparison to C and C++ were not in the compiler (includes), but in the linker. > Isn't it what (optimising) compilers ultimately do anyway: they throw away unused stuff from the generated code etc.? Yes, and I believe linkers can trim symbols that are not referenced by any code. But they can't remove __constructor__ sections. Because they are referenced, and will run. E.g. maybe you imported a package because it defines some flags, but you stopped using the flag. But some scripts still provide it. Importing not being an error means that the flag exists. Did you mean that? Go forces you to be intentional. |