# Is -w really useful?

**URL:** <https://www.ruby-forum.com/t/is-w-really-useful/56028>\
**Category:** Ruby\
**Created:** [March 27, 2006, 1:29pm UTC](https://www.ruby-forum.com/t/is-w-really-useful/56028 "2006-03-27T13:29:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![wybodekker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f05b48/32.png) [@wybodekker](https://www.ruby-forum.com/u/wybodekker)\
**Post date:** [March 27, 2006, 1:29pm UTC](https://www.ruby-forum.com/t/is-w-really-useful/56028/1 "2006-03-27T13:29:55Z")

</div>

I would like to use the -w commandline option always, but any useful  
output is always obscured by message from the standard libraries:

For example:

/usr/local/lib/ruby/gems/1.8/gems/rio-0.3.7/lib/rio/if/grande.rb:404:  
warning: useless use of \> in void context  
/usr/local/lib/ruby/gems/1.8/gems/rio-0.3.7/lib/rio/if/grande.rb:580:  
warning: useless use of \< in void context  
/usr/local/lib/ruby/1.8/tk.rb:2313: warning: redefine encoding=  
/usr/local/lib/ruby/1.8/tk.rb:2316: warning: redefine encoding  
/usr/local/lib/ruby/1.8/tk/font.rb:718: warning: instance variable  
@compoundfont not initialized  
/usr/local/lib/ruby/1.8/tk/font.rb:671: warning: instance variable  
@compoundfont not initialized  
/usr/local/lib/ruby/1.8/tk/font.rb:718: warning: instance variable  
@compoundfont not initialized  
/usr/local/lib/ruby/1.8/tk/font.rb:671: warning: instance variable  
@compoundfont not initialized  
/usr/local/lib/ruby/gems/1.8/gems/rio-0.3.7/lib/rio/rl/uri.rb:78:  
warning: method redefined; discarding old base=  
/usr/local/lib/ruby/gems/1.8/gems/rio-0.3.7/lib/rio/cp.rb:209: warning:  
useless use of \< in void context  
/usr/local/lib/ruby/gems/1.8/gems/rio-0.3.7/lib/rio/cp.rb:309: warning:  
useless use of \> in void context

Should such messages not be banned?

---

<div class="post-metadata">

**Author:** ![wybodekker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f05b48/32.png) [@wybodekker](https://www.ruby-forum.com/u/wybodekker)\
**Post date:** [March 27, 2006, 4:01pm UTC](https://www.ruby-forum.com/t/is-w-really-useful/56028/2 "2006-03-27T16:01:30Z")

</div>

On Mar 27, 2006, at 5:29 AM, Wybo D. wrote:

> I would like to use the -w commandline option always, but any  
> useful output is always obscured by message from the standard  
> libraries:

[snip warnings]

Just to be clear, Rio is not a standard library (though TK is).

> Should such messages not be banned?

I do agree that standard libraries should not trigger warnings.

James Edward G. II

---

<div class="post-metadata">

**Author:** ![wybodekker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f05b48/32.png) [@wybodekker](https://www.ruby-forum.com/u/wybodekker)\
**Post date:** [March 27, 2006, 11:07pm UTC](https://www.ruby-forum.com/t/is-w-really-useful/56028/3 "2006-03-27T23:07:19Z")

</div>

Wybo D. wrote:

> /usr/local/lib/ruby/1.8/tk.rb:2316: warning: redefine encoding  
> /usr/local/lib/ruby/gems/1.8/gems/rio-0.3.7/lib/rio/cp.rb:209:  
> warning: useless use of \< in void context  
> /usr/local/lib/ruby/gems/1.8/gems/rio-0.3.7/lib/rio/cp.rb:309:  
> warning: useless use of \> in void context
> 
> Should such messages not be banned?

Some warnings are really just informational. For example, redefining a  
method isn’t ‘wrong,’ and it can be how your program is supposed to  
function. Or having an uninitialized instance variable might not matter

- after all, I don’t think there is a difference between that and  
setting it to nil.

However, it could be dangerous or unintentional, so you get a warning.  
As with all debugging output, you have to filter through it sometimes.

-Justin

---

<div class="post-metadata">

**Author:** ![wybodekker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f05b48/32.png) [@wybodekker](https://www.ruby-forum.com/u/wybodekker)\
**Post date:** [March 27, 2006, 11:55pm UTC](https://www.ruby-forum.com/t/is-w-really-useful/56028/4 "2006-03-27T23:55:58Z")

</div>

On Tue, 28 Mar 2006, Justin C. wrote:

> Some warnings are really just informational. For example, redefining a method  
> isn’t ‘wrong,’ and it can be how your program is supposed to function. Or  
> having an uninitialized instance variable might not matter - after all, I  
> don’t think there is a difference between that and setting it to nil.
> 
> However, it could be dangerous or unintentional, so you get a warning. As  
> with all debugging output, you have to filter through it sometimes.

Sure, that’s all true, and I want to see such messages to warn myself  
for  
possibly bad programming habits.  
But when I see lots of such message emerge from libraries that I didn’t  
write myself, I’ll easily miss the ones that really matter to me and can  
be influenced by me.

---

<div class="post-metadata">

**Author:** ![wybodekker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f05b48/32.png) [@wybodekker](https://www.ruby-forum.com/u/wybodekker)\
**Post date:** [March 29, 2006, 12:17am UTC](https://www.ruby-forum.com/t/is-w-really-useful/56028/5 "2006-03-29T00:17:33Z")

</div>

On Tue, 28 Mar 2006, Robert D. wrote:

> Wouldn’t it be nice to have a perl/ada style
> 
> pragma :warnings\_on  
> pragma :warnings\_off  
> or  
> pragma :warnings, level
> 
> at a dynamic base.

Well, you can already say: $VERBOSE = true or $VERBOSE = false.  
Isn’t that the same?

---

<div class="post-metadata">

**Author:** ![wybodekker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f05b48/32.png) [@wybodekker](https://www.ruby-forum.com/u/wybodekker)\
**Post date:** [March 28, 2006, 10:58am UTC](https://www.ruby-forum.com/t/is-w-really-useful/56028/6 "2006-03-28T10:58:19Z")

</div>

On 3/27/06, Wybo D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > [messages skipped]  
> > > don’t think there is a difference between that and setting it to nil.
> 
> –  
> Wybo
> 
> Wouldn’t it be nice to have a perl/ada style

pragma :warnings\_on  
pragma :warnings\_off  
or  
pragma :warnings, level

at a dynamic base.

Now for a given (standard) library we could just say

e.g.  
module MyModule  
pragma :warnings 0  
end

Just a thaught

Robert

–  
Deux choses sont infinies : l’univers et la bÃªtise humaine ; en ce qui  
concerne l’univers, je n’en ai pas acquis la certitude absolue.

- Albert Einstein

---

<div class="post-metadata">

**Author:** ![wybodekker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f05b48/32.png) [@wybodekker](https://www.ruby-forum.com/u/wybodekker)\
**Post date:** [March 29, 2006, 12:44am UTC](https://www.ruby-forum.com/t/is-w-really-useful/56028/7 "2006-03-29T00:44:11Z")

</div>

On Wed, 29 Mar 2006 07:17:10 +0900, Wybo D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Well, you can already say: $VERBOSE = true or $VERBOSE = false.  
> Isn’t that the same?

Actually, $VERBOSE can take on three semantic values: nil, false, true.  
Further, behaviour can differ slightly if -W0, -W1, -W2 (ie, nil, false,  
true (and -w == -W2) are set from the command line as opposed to setting  
$VERBOSE in the script (parse-time vs runtime). This means that doing  
something akin to:

module Kernel  
def no\_warn  
begin  
verbose = $VERBOSE  
$VERBOSE = nil  
yield  
ensure  
$VERBOSE = verbose  
end  
end  
end

no\_warn do  
puts (0…5)  
end

doesn’t quench the warning, but -W0 does. Strangely, changing that  
block to:

no\_warn do  
puts “foo”  
puts (0…5)  
end

results in yet different warning behaviours.

At any rate, a catchable warning system might be a good idea and  
encourage people to wrap ‘warnable’ code in blocks that don’t emit  
particular warnings – so something like:

no\_warn :method\_redefined do  
# (meta)code that redefines methods  
end

would explicitly turn off the method redefinition warning (presumably we  
are doing that on purpose here), but still emit any other warnings the  
code might generate.

Just a thought.

andrew
