That does sound annoying. I guess you’re effectively forced to locally wrap fmt.Print(m) with Debug(m) that calls fmt.Print(m) if you want to avoid the hassle.
I’ve run into it in C before with certain compiler flags that complain about unused variables. I’d just wrap the code in an if (0) {} rather than commenting it out so it’s is still there according to the compiler, but it just never runs. Then once you’re done debugging, rip out the whole block.
Yeah but then you still have variable declarations and (in Go’s case, includes) that will still be there when the preprocessor rips out all of the code between #if/#endif.
That does sound annoying. I guess you’re effectively forced to locally wrap fmt.Print(m) with Debug(m) that calls fmt.Print(m) if you want to avoid the hassle.
I’ve run into it in C before with certain compiler flags that complain about unused variables. I’d just wrap the code in an
if (0) {}rather than commenting it out so it’s is still there according to the compiler, but it just never runs. Then once you’re done debugging, rip out the whole block.I’ve seen people use preprocessor conditionals in the same way, which I guess has the added advantage of not getting compiled at all.
Example:
Yeah but then you still have variable declarations and (in Go’s case, includes) that will still be there when the preprocessor rips out all of the code between #if/#endif.
Ah, I see. I misunderstood your original comment. Neat trick.