News for hackers. Stuff that matters.
Re:Ask HN: Why won't Go compile with unused imports? by detaro on Wednesday July 06, 2016 @12:53PM (#12044331)
https://golang.org/doc/faq#unused_variables_and_imports

Keeping code clean. If you can't compile with unused imports/variables, you can't forget them.

Re:Ask HN: Why won't Go compile with unused imports? by fhood on Wednesday July 06, 2016 @01:13PM (#12044472)
I was hoping for something more fundamental. That feels like sacrificing function for form
Re:Ask HN: Why won't Go compile with unused imports? by AnimalMuppet on Wednesday July 06, 2016 @03:31PM (#12045274)
It's about very long-lived projects (and at least partly about compile time).

Fundamentally, Go was aimed at huge code bases (think ten million lines) that live for decades. C++ code of that size takes a long time to compile (45 minutes to a few hours). If you have 30 people working on a project, and they each compile a few times a day, over 20 years that adds up to a huge amount of time.

One of the issues with C++-style includes is that they slow down compile times, because you see the same file over and over, and only process it the first time, and the rest of the time you import the text but don't do anything with it. But the compiler has to wade through all that unused text. So Go said, not just that you can only have the imports that you need, but also that you can't have cycles in the imports.

Now, from where I sit, the "no cycles" is much more clearly related to compile times than "no unused" is. But I think that they both come out of the same philosophy: "We're not going to permit less-than-optimal stuff to accumulate in the imports, because over the long run of a project, it bites you". It bites you in that, as time goes on, it becomes harder and harder to fix, and because it makes the compiles slower and slower.

Re:Ask HN: Why won't Go compile with unused imports? by danwakefield on Wednesday July 06, 2016 @01:19PM (#12044523)
Switch out gofmt for goimports (https://github.com/bradfitz/goimports) to fix the errors on save with your editor / ide
Re:Ask HN: Why won't Go compile with unused imports? by jameskilton on Wednesday July 06, 2016 @01:14PM (#12044487)
I don't understand. What's being sacrificed? Of what use is a list of imports that aren't used?
Re:Ask HN: Why won't Go compile with unused imports? by fhood on Wednesday July 06, 2016 @02:51PM (#12045063)
You have never commented out a section of code that was the only place an import was used for debugging?
Re:Ask HN: Why won't Go compile with unused imports? by imauld on Wednesday July 06, 2016 @07:31PM (#12046573)
Sure. I also use Atom with gofmt installed (the Atom gofmt package allows you to use goimports as a formatter). Comment the line and hit save and the import goes away. Uncomment and hit save and it comes back. Tools exist to make dealing with this requirement painless.
Re:Ask HN: Why won't Go compile with unused imports? by jameskilton on Wednesday July 06, 2016 @04:17PM (#12045598)
Of course I have. That's not a good reason for the compiler to allow the unused imports. The benefits of Go's strict compilation rules far outweigh the periodic pain points.
Re:Ask HN: Why won't Go compile with unused imports? by kormoc on Wednesday July 06, 2016 @01:46PM (#12044692)
Efficient copypasta
Re:Ask HN: Why won't Go compile with unused imports? by brianwawok on Wednesday July 06, 2016 @01:49PM (#12044713)
You require crap all over your code that doesn't do anything?