Re:Deadcode: Finding unreachable functions in Go
by dewey on Tuesday January 23, 2024 @04:03PM
(#39109787)
> Sometimes the code that's commented out contains the only reference to an imported package, and by commenting it out the autoformatter helpfully removes the import from the top of the file, so then uncommenting the line is not enough -- I need to go back and re-add the import.
The same tool that removes your imports also adds them so there usually isn’t an extra step.
Re:Deadcode: Finding unreachable functions in Go
by nulld3v on Tuesday January 23, 2024 @09:19PM
(#39112835)
It often breaks stuff for me when I import two packages with the same name so I use a named import:
``` import "alpha/stuff" import bstuff "beta/stuff"
stuff.buyStuff() bstuff.stuffAnimal() ```
Once the autoformatter sees the named import is unused it removes it. Then when I uncomment my code again the autoformatter doesn't remember that it's supposed to use a named import. So in my example it wouldn't know "bstuff" is actually "beta/stuff".
Sometimes the code that's commented out contains the only reference to an imported package, and by commenting it out the autoformatter helpfully removes the import from the top of the file, so then uncommenting the line is not enough -- I need to go back and re-add the import.
Or I may want to comment out this line
but that makes a and b in turn become unused as well, and I need to travel up to wherever they're defined and comment them out too, and so on with anything else that became thus unused in that chain.And this is all suboptimal because the warning is also important when debugging. I do want to get warned about the unused code! Just let me compile.