4 ms·
>Why would the compiler import (that is, parse and compile) a package that's unused in the code? Parse - yes, compile - no. Compiler still needs to parse your
by konart 6y ago
>Why would the compiler import (that is, parse and compile) a package that's unused in the code?
Parse - yes, compile - no. Compiler still needs to parse your code to determine if your import is used or not.
Go team decided that compilation should take as little time as possible, so it is easier to make sure that the compiler does not have to worry about unused imports at all.
Not to mention that this keeps your code clean.
Dozen separate tools can be used effectively in your workflow (say CI\CD pipeline). Or just executed on every save. (or both)
https://golang.org/doc/faq#unused_variables_and_imports https://golang.org/doc/faq#unused_variables_and_imports
- dmitriid 6y ago> Compiler still needs to parse your code to determine if your import is used or not. Parsing is easy. And it's fast. On top of that the compiler already knows it's unused: --- start quote --- Go programs with unused imports do not compile. This is a deliberate feature of the language as importing packages slow down the compiler. --- end quote --- So, the compiler has already parsed the file, and determined that the import is unused. And refuses to compile further, because... it needs to import that package anyway? Why? > Dozen separate tools can be used effectively in your workflow Haha, no. If you need a dozen different tools, there's no question about effectiveness at all.
- deleted 6y ago[deleted]
- knorker 6y ago> And refuses to compile further, because... it needs to import that package anyway? Why? Because it may have side-effects, and the compiler doesn't know if it's the programmer's intention to import in order to get those side-effects, or if it's a mistake.
- dmitriid 6y agohttps://news.ycombinator.com/item?id=26565422 https://news.ycombinator.com/item?id=26565422