Re:Go: What We Got Right, What We Got Wrong
by cwbriscoe on Thursday January 04, 2024 @10:08PM
(#38875264)
Just run goimports on save then there would be no issue with unused imports. I would take go's error handling over try/catch any day of the week.
[ Parent
| on HN ]
Re:Go: What We Got Right, What We Got Wrong
by cangeroo on Friday January 05, 2024 @06:33AM
(#38878032)
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.
Is it possible to comment out the imports?
Re:Go: What We Got Right, What We Got Wrong
by cwbriscoe on Friday January 05, 2024 @10:13AM
(#38879886)
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.
Re:Go: What We Got Right, What We Got Wrong
by alainx277 on Friday January 05, 2024 @08:26PM
(#38887358)
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.
Re:Go: What We Got Right, What We Got Wrong
by cwbriscoe on Saturday January 06, 2024 @01:50PM
(#38894061)
goimports re-adds them when you uncomment the code. Unless it is ambiguous on which lib to import which doesn't happen very often.
Re:Go: What We Got Right, What We Got Wrong
by cangeroo on Saturday January 06, 2024 @04:28AM
(#38889925)
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.