On Thu, Jan 10, 2019 at 6:30 AM Justin Israel <[email protected]>
wrote:

> On Thu, Jan 10, 2019 at 6:04 PM 김용빈 <[email protected]> wrote:
>
>> package main
>>
>> func unused(x interface{}) {}
>>
>> func main() {
>>     a := 1
>>     unused(a)
>> }
>>
>
> The function isn't even required here. Assigning to underscore will
> prevent the error:
>
> func main() {
>     a := 1
>     _ = a
> }
>

 Both versions above have the same problem - it's possible to forgot the
bypass hack in production code.

For many years I'm using

        func use(...interface{}) {}

but defined in tests, for example in all_test.go. This enables easy
disabling of the 'unused variable' error during development/debugging, but
the code does not otherwise compile until the 'use(foo, bar') hack is
removed or commented out.

-- 

-j

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to