Disable unused X warnings?

121 views
Skip to first unread message

Han-Wen Nienhuys

unread,
Dec 23, 2010, 1:44:59 PM12/23/10
to golan...@googlegroups.com
Hi there,

When debugging code, I occasionally comment out bits of code, which
leads to various errors of unused imports and variables.

Is there a way to make the [568]g compilers treat this as warnings
rather than errors? If not, is this is a reasonable feature request?

--
Han-Wen Nienhuys
Google Engineering Belo Horizonte
han...@google.com

Ian Lance Taylor

unread,
Dec 23, 2010, 2:32:07 PM12/23/10
to Han-Wen Nienhuys, golan...@googlegroups.com
Han-Wen Nienhuys <han...@google.com> writes:

> When debugging code, I occasionally comment out bits of code, which
> leads to various errors of unused imports and variables.
>
> Is there a way to make the [568]g compilers treat this as warnings
> rather than errors? If not, is this is a reasonable feature request?

For import:

import _ "package"

For variables, at the end of the function:

_ = v

There isn't any option to change the compiler behaviour.

Ian

Erwin

unread,
Dec 23, 2010, 2:32:47 PM12/23/10
to Han-Wen Nienhuys, golan...@googlegroups.com
that irritates me too, an error is an overreaction i find... 

Rob 'Commander' Pike

unread,
Dec 23, 2010, 2:35:55 PM12/23/10
to Han-Wen Nienhuys, golan...@googlegroups.com
On Thu, Dec 23, 2010 at 10:44 AM, Han-Wen Nienhuys <han...@google.com> wrote:
> Hi there,
>
> When debugging code, I occasionally comment out bits of code, which
> leads to various errors of unused imports and variables.
>
> Is there a way to make the [568]g compilers treat this as warnings
> rather than errors? If not, is this is a reasonable feature request?

No, and it's a reasonable feature request but one that will not be
satisfied. Perhaps it's a Procrustean decision but we deliberately
decided that the gc compilers will not issue warnings. If something
is worth complaining about, it's worth fixing. Along the same lines,
a flag that disables a class of error makes the language's
specification flag-dependent, and that way lies madness (which is not
to say that many other languages are willing to go insane).

When debugging, it's easy to circumvent the errors using the blank
identifier. For instance, if you need fmt for debugging but not
always, you can say

var _ = fmt.Printf // delete before submitting

and that will identify that the fmt package is used. If you forget to
delete the declaration, or even just decide to leave it there for
future convenience, no real harm is done.

The simple ways the language makes it possible to avoid the errors
supports our position that compiler flags are not the solution.

-rob

andrey mirtchovski

unread,
Dec 23, 2010, 2:37:01 PM12/23/10
to Ian Lance Taylor, Han-Wen Nienhuys, golan...@googlegroups.com
> import _ "package"

but this makes the package unusable. for trying out stuff that rapidly
switches between packages i prefer to define a toplevel nonce so i can
move in and out of that package without tripping the compiler:

var _ = fmt.Println

Chris Wedgwood

unread,
Dec 23, 2010, 5:55:04 PM12/23/10
to Rob 'Commander' Pike, Han-Wen Nienhuys, golan...@googlegroups.com
On Thu, Dec 23, 2010 at 11:35:55AM -0800, Rob 'Commander' Pike wrote:

> var _ = fmt.Printf // delete before submitting

Something I do are comments like:

var _ = foo // XXX

and

v b:= bytes.Buffer{} // FIXME(cw): should really frobnicate the thromdimbulator


and even non-comment code like:

fmt.Printf("XXX foo=%v\n", foo)

I have my editor highlight[1] XXX in read as a giant offensive warning
of something that has to be dealt with, and sometimes I have commit
and merge scripts abort when it sees those tokens.

FIXME is dealt with in a lesser manner, code might get committed and
merged, but it's something I can easily grep out later on.


[1] font-lock-add-keywords mode, there might be a better way

Reply all
Reply to author
Forward
0 new messages