Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You then have to reimport. Every time when you comment out code.

I guess the compiler authors don't comment out code?

And it's intentionally not optional on the compiler.

So you have to modify the source and compile your own compiler to disable it. It's ridiculously sadistic to their users.



If you use goimports (which also runs gofmt) after commenting out code, you just have to save your file and it will remove any unused imports. There is no reason to go to the extreme extent of compiling your own modified version of go just for this. The tooling is already there.


The OP mentions that the reimport is the problem (in response to your tooling suggestion). If you comment out code while testing the imports are auto-removed. When you uncomment you need add the correct imports again.


goimports re-adds them when you uncomment the code. Unless it is ambiguous on which lib to import which doesn't happen very often.


I might not have used `goimports` before. I read now that it also auto-imports when you uncomment. That's neat, but it could auto-import the wrong thing, and I'm not sure how it would handle conflicts. It still seems worse than just ignoring my unused imports. Unused imports should be more of a linting thing? If the compiler knows its unused, I don't see why it can't just ignore it.


Yes, it can import the wrong thing (or version) but it doesn't happen that often in my experience. If you use the libraries in other files it can go off of what is already in your go.mod file.


Is it possible to comment out the imports?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: