The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Structured Warnings

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Daniel Berger

Posts: 1383
Nickname: djberg96
Registered: Sep, 2004

Daniel Berger is a Ruby Programmer who also dabbles in C and Perl
Structured Warnings Posted: Oct 26, 2005 12:38 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Daniel Berger.
Original Post: Structured Warnings
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Daniel Berger
Latest Posts From Testing 1,2,3...

Advertisement
One of the things that has come up in the past on IRC, ruby-talk, and even during a hallway conversation at RubyConf 2005 is the notion of structured warnings.

What do I mean when I say "structured warnings"? Well, at the moment there's no warning hierarchy in the same manner as we have an Exception hierarchy, i.e there's no Warning class, with a bunch of subclasses like StandardWarning, RuntimeWarning, etc. You just call "warn 'Look out!", and a warning appears as a string.

However, there are times when you want to suppress certain warnings. Perl lets you do this via the "no warnings" pragma, where you can voluntarily suppress certain types of warnings, e.g. "no warnings 'uninitialized'" (my personal favorite). There's no such mechanism in Ruby to do this.

Based on an old thread we've come up with something like this:
# Disable 'uninitialized' warnings permanately
UninitializedWarning.disable

DeprecatedMethodWarning.disable
   foo.bar # yes, yes, I know it's deprecated, shut up.
end

That would allow you to disable a particular warning either until the end of the program, or only for the given block. It would also let you be more explicit in the types of warnings you wanted to raise in your own code. For example, say you've refactored one of your libraries, and want to replace your poorly named "foo2" method with the "foo_with_ham" method. You could then do something like this:
def foo2(*args)
   warn DeprecatedMethodWarning, "use foo_with_ham instead"
   ...
end

Then, users of your old code could suppress that warning if they so chose.

For an alternate idea, look here.

Read: Structured Warnings

Topic: Web Developer Documentation Previous Topic   Next Topic Topic: The general-purpose CMS (pipe dreams, part II)

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use