I usually wrap the function call with `if false` i.e: if false { package.Function() }
This "comments out" the function call and keeps the package imported. On Thursday, February 1, 2018 at 12:00:23 PM UTC-5, Alex Buchanan wrote: > > Clever workarounds! > > These solutions don't handle the case of commenting out a function call, > which is a common need IMO. Whatever the workaround, it would still be > easier if done by vet, right? > > On Wednesday, January 31, 2018 at 6:46:40 PM UTC-8, Alex Buchanan wrote: >> >> Unused variables and imports are strictly disallowed by the Go compiler. >> Most of the time, I enjoy this benefit. These days, I've started to notice >> how often things go dead and/or unused in my python code. >> >> But, sometimes, this behavior is incredibly annoying. If I'm trying to >> debug something by commenting out lines, or if I'm hacking up an >> experimental script (meant to run with `go run`), I find this checking is >> very unwanted. For example, if I comment out one variable, it may lead to a >> new set of variables being unused, which sometimes leads back to a package >> being unused. It's not uncommon for this cycle to take 3-5 iterations, in >> my experience. >> >> Quickly hacking up Go scripts would be improved by relaxing this >> constraint, in my opinion. >> >> Is finding a better compromise at all interesting or even possible? Are >> parts of the compiler written to depend on the fact that variables are >> definitely used? >> >> My idea for a potential improvement (again, having zero knowledge of the >> compiler requirements) is to move this checking to vet. >> >> Thanks! >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.