$VERBOSE=true returns warnings from standard library

I normally write my ruby code with $VERBOSE=true. When I do this in
ruby 1.8.0 and use singleton.rb I get the following warning:

c:/ruby180/lib/ruby/1.8/singleton.rb:98: warning: redefine instance

Wouldn’t it be nice if there was an option to turn off warnings for
modules in the standard distribution?

Cheers,

Thomas

Hi,

···

In message “$VERBOSE=true returns warnings from standard library” on 03/08/19, Thomas thomass@deltadata.dk writes:

I normally write my ruby code with $VERBOSE=true. When I do this in
ruby 1.8.0 and use singleton.rb I get the following warning:

c:/ruby180/lib/ruby/1.8/singleton.rb:98: warning: redefine instance

Wouldn’t it be nice if there was an option to turn off warnings for
modules in the standard distribution?

Indeed. I will fix.

						matz.

Could we not make it a rule that stuff in the standard library has to
meet a basic standard? Rather than disable warning in the library code,
could we instead fix the warnings?

Cheers

Dave

···

On Tuesday, August 19, 2003, at 03:21 AM, Yukihiro Matsumoto wrote:

c:/ruby180/lib/ruby/1.8/singleton.rb:98: warning: redefine instance

Wouldn’t it be nice if there was an option to turn off warnings for
modules in the standard distribution?

Indeed. I will fix.

That’s a good idea, but in the specific case of “redefine …”, I
think a different approach may be needed.

Ruby allows you to redefine methods, and the Ruby community encourages
people to take advantage of that. Yes the Ruby interpreter issues a
non-negotiable warning when you do so. Perhaps a warning should not
be given (by default) in this case. It could be given when the user
asks for maximum warnings.

For instance, I consider this good style:

class Example
attr_accessor :attribute

# ...

def attribute=(x)
  # something special
end

end

It lets the reader know up front that they can use #attribute and
#attribute=, and then it changes the implementation, which the casual
reader doesn’t need to know - do they?

Running this code:
-w warns that attribute= is redefined
-W0 doesn’t
-W1 doesn’t
-W2 does (this is equivalent to -w)

The problem we have is that people commonly run with -w in order to
get real warnings. People don’t want to get bombarded with the above
kind of warning at this level, do they?

Cheers,
Gavin

···

On Wednesday, August 20, 2003, 12:02:24 AM, Dave wrote:

On Tuesday, August 19, 2003, at 03:21 AM, Yukihiro Matsumoto wrote:

c:/ruby180/lib/ruby/1.8/singleton.rb:98: warning: redefine instance

Wouldn’t it be nice if there was an option to turn off warnings for
modules in the standard distribution?

Indeed. I will fix.

Could we not make it a rule that stuff in the standard library has to
meet a basic standard? Rather than disable warning in the library code,
could we instead fix the warnings?

Could we not make it a rule that stuff in the standard library has to
meet a basic standard? Rather than disable warning in the library code,
could we instead fix the warnings?

I’d second that. Follow the standard bearer! :slight_smile:

Cheers

Dave

    Hugh
···

On Tue, 19 Aug 2003, Dave Thomas wrote:

I think you’re right, but I don’t think it changes the underlying
philosophy of my answer. If something is scary enough to generate a
warning in user code, then it should always generate it.

However, there are also times where the developer knows more than the
interpreter. For those cases, how about a standard facility to allow
warnings to be disabled for a chunk of code (a la Perl)?

···

On Tuesday, August 19, 2003, at 09:18 AM, Gavin Sinclair wrote:

Could we not make it a rule that stuff in the standard library has to
meet a basic standard? Rather than disable warning in the library
code,
could we instead fix the warnings?

That’s a good idea, but in the specific case of “redefine …”, I
think a different approach may be needed.

Hi –

Could we not make it a rule that stuff in the standard library has to
meet a basic standard? Rather than disable warning in the library code,
could we instead fix the warnings?

I third this (see Hugh’s second :slight_smile:

That’s a good idea, but in the specific case of “redefine …”, I
think a different approach may be needed.

Ruby allows you to redefine methods, and the Ruby community encourages
people to take advantage of that. Yes the Ruby interpreter issues a
non-negotiable warning when you do so. Perhaps a warning should not
be given (by default) in this case. It could be given when the user
asks for maximum warnings.

The original post was about “redefine instance” in singleton.rb, not
the classic “method redefined, discarding old xxx” warning. But
on the latter subject:

For instance, I consider this good style:

class Example
attr_accessor :attribute

# ...

def attribute=(x)
  # something special
end

end

It lets the reader know up front that they can use #attribute and
#attribute=, and then it changes the implementation, which the casual
reader doesn’t need to know - do they?

I don’t know, but I think the casual reader – at least, that casual
– isn’t all that major a player in the game, at least not to the
point where attr_accessor’s documentation role outweighs its
method-defining role, which I think is happening here. It seems that
you’re defining a method you don’t need, solely for the purpose of
documenting it, which seems a bit loose.

I think the discarding method warning is potentially useful for a
case like:

class C
def x; end
def xx; end
def xx; end # whoops, meant to type xxx
end

where you accidentally trample a method. It’s a fairly marginal
scenario, but it’s probably best to have it issue a warning just in
case.

David

···

On Tue, 19 Aug 2003, Gavin Sinclair wrote:

On Wednesday, August 20, 2003, 12:02:24 AM, Dave wrote:


David Alan Black
home: dblack@superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav

Maybe. One thing that I’ve suggested to Dave for RDoc – I haven’t honestly
been reading the Rdoc source to see if it’s been done or how :slight_smile: – is that
it might be nice to have something like:

Allows access to the +foo+ attribute.

attr_reader :foo

def foo=(x) #:attr_writer foo:
end

That way, RDoc could collapse the comments from _reader and foo= as if it
were an attr_accessor. It would also make it relatively easy (IMO) to add
additional “classes” that really do create specialised (but generated)
attribute accessors. A bit more typing, but in this way, less code is
executed by the interpreter (a good thing, IMO) while keeping the intent
clear in the general flow and the documentation itself.

-austin

···

On Tue, 19 Aug 2003 23:18:38 +0900, Gavin Sinclair wrote:

For instance, I consider this good style:
class Example
attr_accessor :attribute

def attribute=(x)
# something special
end
end

It lets the reader know up front that they can use #attribute and
#attribute=, and then it changes the implementation, which the casual
reader doesn’t need to know - do they?


austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2003.08.23
* 19.13.18

What would it mean for warnings to be disabled for a chunk of code?
Would this happen at compile-time or at run-time? If I enable warnings
for a chunk of code, then would warnings be on or off for code that this
chunk happens to call?

I’d really like to see a pluggable mechanism for capturing warnings
(instead of sending all warnings to stderr). It would be really nifty
if I could write:

def warn(warning)
if warning.level < 10 or
warning.file == “a_file_I_want_to_ignore_warnings_in.rb” then
# ignore this warning
else
$stderr.puts(warning)
send_email_to_me_about(warning)
end
end

class Foo
def foo; end
def foo; end # doesn’t print anything since the warning’s level is
# too low
end

Paul

···

On Wed, Aug 20, 2003 at 12:12:47AM +0900, Dave Thomas wrote:

However, there are also times where the developer knows more than the
interpreter. For those cases, how about a standard facility to allow
warnings to be disabled for a chunk of code (a la Perl)?

Well, I tend to agree in theory… but I redefine
methods often, and find the warning annoying. And
I think the warning has never helped me, it has
only gotten in my way.

Isn’t there a way to turn warnings on and off
at runtime? Can’t think how.

Hal

···

----- Original Message -----
From: dblack@superlink.net
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Tuesday, August 19, 2003 10:43 AM
Subject: Re: $VERBOSE=true returns warnings from standard library

I think the discarding method warning is potentially useful for a
case like:

class C
def x; end
def xx; end
def xx; end # whoops, meant to type xxx
end

where you accidentally trample a method. It’s a fairly marginal
scenario, but it’s probably best to have it issue a warning just in
case.


Hal Fulton
hal9000@hypermetrics.com

However, there are also times where the developer knows more than the
interpreter. For those cases, how about a standard facility to allow
warnings to be disabled for a chunk of code (a la Perl)?

A very good solution. If warnings were channelled through a ruby
method this could perhaps be implemented in pure ruby? It would also
be nice if warnings were filtered so you wouldn’t get the same warning
10000 times inside a loop.

Cheers,

Thomas