# How to raise warning?

**URL:** <https://rubytalk.org/t/how-to-raise-warning/10236>\
**Category:** ruby-talk\
**Created:** [20 February 2004 07:50 UTC](https://rubytalk.org/t/how-to-raise-warning/10236 "2004-02-20T07:50:56Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gavri\_Savio\_Fernande](https://avatars.discourse-cdn.com/v4/letter/g/cc9497/32.png) [@Gavri\_Savio\_Fernande](https://rubytalk.org/u/Gavri_Savio_Fernande)\
**Post date:** [20 February 2004 07:50 UTC](https://rubytalk.org/t/how-to-raise-warning/10236/1 "2004-02-20T07:50:56Z")

</div>

> From: Hal Fulton [[mailto:hal9000@hypermetrics.com](mailto:hal9000@hypermetrics.com)]  
> Subject: Re: how to raise warning?

> > Having a variant of ‘warn’ that displays that information  
> > would be nice IMO.
> > 
> > warn “You didn’t provide such and such”, true
> 
> Mmm. I would expect that just to print ‘true’ after the warning.
> 
> The problem as I see it is that we use warnings in two ways:
> 
> 1. As Ruby does, to complain about something happening at a specific  
> place in the source – a highly source-related message. In that  
> case, I’d want to see file/line info (as Ruby does when it says I  
> need to add parens or something).
> 2. To complain about some general condition occurring at runtime that  
> doesn’t warrant bailing out of the app.
> 
> My suggestion: Two names. Call the first one “warning” (the kind of  
> warning that Ruby gives us) and the second one “warn” (a simple verb  
> that just prints to stderr).

One of the main things I like about Ruby is that the names are so intuitive.  
Once i check out a particular class or method in the reference, it is pretty much guaranteed that i won’t forget it ever. Even better, sometimes i just guess what the name of a particular entity might be, type it in and the program runs. This, for me, is a major plus for ruby.  
Even if a particular name is esoteric, it is esoteric in a way i remember and find difficult to forget.

Okay, what i’m driving at is this: Naming one method ‘warn’ (A verb. I like that) and another ‘warning’ (A noun. Don’t like it much) is quite confusing ☹  
There doesn’t seem to be any clue in their names to differentiate their functionality from each other.

Maybe there’s a better way than Gavin’s proposal (more mnemonic names like ‘warn\_with\_sourceinfo’. i know this name sucks but you get the idea) but for now i prefer it his way:  
warn “You didn’t provide such and such”  
warn “You didn’t provide such and such”, true

> Hal

gavri

---

<div class="post-metadata">

**Author:** ![Mark\_Hubbart](https://avatars.discourse-cdn.com/v4/letter/m/b77776/32.png) [@Mark\_Hubbart](https://rubytalk.org/u/Mark_Hubbart)\
**Post date:** [20 February 2004 08:25 UTC](https://rubytalk.org/t/how-to-raise-warning/10236/2 "2004-02-20T08:25:17Z")

</div>

> > From: Hal Fulton [[mailto:hal9000@hypermetrics.com](mailto:hal9000@hypermetrics.com)]  
> > Subject: Re: how to raise warning?
> > 
> > > Having a variant of ‘warn’ that displays that information would be  
> > > nice IMO.
> > > 
> > > warn “You didn’t provide such and such”, true
> > 
> > Mmm. I would expect that just to print ‘true’ after the warning.  
> > I second that. Adding an optional boolean argument to the function to  
> > get different results doesn’t quite seem rubyish to me.

> > The problem as I see it is that we use warnings in two ways:
> > 
> > 1. As Ruby does, to complain about something happening at a specific  
> > place in the source – a highly source-related message. In that  
> > case, I’d want to see file/line info (as Ruby does when it says I  
> > need to add parens or something).
> > 2. To complain about some general condition occurring at runtime that  
> > doesn’t warrant bailing out of the app.
> > 
> > My suggestion: Two names. Call the first one “warning” (the kind of  
> > warning that Ruby gives us) and the second one “warn” (a simple verb  
> > that just prints to stderr).
> 
> One of the main things I like about Ruby is that the names are so  
> intuitive.  
> Once i check out a particular class or method in the reference, it is  
> pretty much guaranteed that i won’t forget it ever. Even better,  
> sometimes i just guess what the name of a particular entity might be,  
> type it in and the program runs. This, for me, is a major plus for  
> ruby.  
> Even if a particular name is esoteric, it is esoteric in a way i  
> remember and find difficult to forget.
> 
> Okay, what i’m driving at is this: Naming one method ‘warn’ (A verb. I  
> like that) and another ‘warning’ (A noun. Don’t like it much) is quite  
> confusing ☹  
> There doesn’t seem to be any clue in their names to differentiate  
> their functionality from each other.

How about:  
warn “Server timed out. retrying.”  
warn! “That number seemed a bit high… Possible error.”

This would keep the old behavior for warn(), but add a new function  
warn!(), which would be used for more serious warnings where you want  
to include a traceback.

-Mark

> **···**
>
> On Feb 19, 2004, at 11:50 PM, Gavri Savio Fernandez wrote:

---

<div class="post-metadata">

**Author:** ![David\_A\_Black3](https://avatars.discourse-cdn.com/v4/letter/d/6a8cbe/32.png) [@David\_A\_Black3](https://rubytalk.org/u/David_A_Black3)\
**Post date:** [20 February 2004 11:54 UTC](https://rubytalk.org/t/how-to-raise-warning/10236/3 "2004-02-20T11:54:31Z")

</div>

Hi –

> > From: Hal Fulton [[mailto:hal9000@hypermetrics.com](mailto:hal9000@hypermetrics.com)]  
> > Subject: Re: how to raise warning?
> 
> > > Having a variant of ‘warn’ that displays that information  
> > > would be nice IMO.
> > > 
> > > warn “You didn’t provide such and such”, true
> > 
> > Mmm. I would expect that just to print ‘true’ after the warning.
> > 
> > The problem as I see it is that we use warnings in two ways:
> > 
> > 1. As Ruby does, to complain about something happening at a specific  
> > place in the source – a highly source-related message. In that  
> > case, I’d want to see file/line info (as Ruby does when it says I  
> > need to add parens or something).
> > 2. To complain about some general condition occurring at runtime that  
> > doesn’t warrant bailing out of the app.
> > 
> > My suggestion: Two names. Call the first one “warning” (the kind of  
> > warning that Ruby gives us) and the second one “warn” (a simple verb  
> > that just prints to stderr).
> 
> One of the main things I like about Ruby is that the names are so intuitive.  
> […]  
> Maybe there’s a better way than Gavin’s proposal (more mnemonic  
> names like ‘warn\_with\_sourceinfo’. i know this name sucks but you  
> get the idea) but for now i prefer it his way:  
> warn “You didn’t provide such and such”  
> warn “You didn’t provide such and such”, true

I would love to see every case of boolean arguments (like  
“methods(true)”) disappear from Ruby – for exactly the reason you’ve  
given, namely that they’re hard to understand and remember. I’ve  
always thought they should be split into separate methods.

David

> **···**
>
> On Fri, 20 Feb 2004, Gavri Savio Fernandez wrote:
> 
> –  
> David A. Black  
> [dblack@wobblini.net](mailto:dblack@wobblini.net)

---

<div class="post-metadata">

**Author:** ![Robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@Robert](https://rubytalk.org/u/Robert)\
**Post date:** [20 February 2004 11:56 UTC](https://rubytalk.org/t/how-to-raise-warning/10236/4 "2004-02-20T11:56:51Z")

</div>

“Mark Hubbart” [discord@mac.com](mailto:discord@mac.com) schrieb im Newsbeitrag  
[news:4A25FA2C-637E-11D8-9977-000502FDD5CC@mac.com](mailto:news:4A25FA2C-637E-11D8-9977-000502FDD5CC@mac.com)…

> > > From: Hal Fulton [[mailto:hal9000@hypermetrics.com](mailto:hal9000@hypermetrics.com)]  
> > > Subject: Re: how to raise warning?
> > > 
> > > > Having a variant of ‘warn’ that displays that information would be  
> > > > nice IMO.
> > > > 
> > > > warn “You didn’t provide such and such”, true
> > > 
> > > Mmm. I would expect that just to print ‘true’ after the warning.  
> > > I second that. Adding an optional boolean argument to the function to  
> > > get different results doesn’t quite seem rubyish to me.

It’s generally considered bad to have an interface method that changes  
it’s behavior dependend on a flag. The typical solution is to have two  
methods for the job. If they have something in common they can use a  
private method for the implementation.

> > > The problem as I see it is that we use warnings in two ways:
> > > 
> > > 1. As Ruby does, to complain about something happening at a specific  
> > > place in the source – a highly source-related message. In that  
> > > case, I’d want to see file/line info (as Ruby does when it says I  
> > > need to add parens or something).
> > > 2. To complain about some general condition occurring at runtime that  
> > > doesn’t warrant bailing out of the app.
> > > 
> > > My suggestion: Two names. Call the first one “warning” (the kind of  
> > > warning that Ruby gives us) and the second one “warn” (a simple verb  
> > > that just prints to stderr).
> > 
> > One of the main things I like about Ruby is that the names are so  
> > intuitive.  
> > Once i check out a particular class or method in the reference, it is  
> > pretty much guaranteed that i won’t forget it ever. Even better,  
> > sometimes i just guess what the name of a particular entity might be,  
> > type it in and the program runs. This, for me, is a major plus for  
> > ruby.  
> > Even if a particular name is esoteric, it is esoteric in a way i  
> > remember and find difficult to forget.
> > 
> > Okay, what i’m driving at is this: Naming one method ‘warn’ (A verb. I  
> > like that) and another ‘warning’ (A noun. Don’t like it much) is quite  
> > confusing ☹  
> > There doesn’t seem to be any clue in their names to differentiate  
> > their functionality from each other.
> 
> How about:  
> warn “Server timed out. retrying.”  
> warn! “That number seemed a bit high… Possible error.”
> 
> This would keep the old behavior for warn(), but add a new function  
> warn!(), which would be used for more serious warnings where you want  
> to include a traceback.

Ops, didn’t read your post before I send mine. Similar thoughts. 🙂

Kind regards

```
robert

```

> **···**
>
> > On Feb 19, 2004, at 11:50 PM, Gavri Savio Fernandez wrote:

---

<div class="post-metadata">

**Author:** ![HAL\_9000](https://avatars.discourse-cdn.com/v4/letter/h/90ced4/32.png) [@HAL\_9000](https://rubytalk.org/u/HAL_9000)\
**Post date:** [20 February 2004 19:09 UTC](https://rubytalk.org/t/how-to-raise-warning/10236/5 "2004-02-20T19:09:05Z")

</div>

Mark Hubbart wrote:

> > Okay, what i’m driving at is this: Naming one method ‘warn’ (A verb. I  
> > like that) and another ‘warning’ (A noun. Don’t like it much) is quite  
> > confusing ☹  
> > There doesn’t seem to be any clue in their names to differentiate  
> > their functionality from each other.

Agreed. Clear in my mind, but that probably says more about my mind  
than about the syntax. 🙂

> How about:  
> warn “Server timed out. retrying.”  
> warn! “That number seemed a bit high… Possible error.”
> 
> This would keep the old behavior for warn(), but add a new function  
> warn!(), which would be used for more serious warnings where you want to  
> include a traceback.

I like Mark’s idea better than mine.

Hal

> **···**
>
> > On Feb 19, 2004, at 11:50 PM, Gavri Savio Fernandez wrote:

---

<div class="post-metadata">

**Author:** ![Andrew\_Johnson](https://avatars.discourse-cdn.com/v4/letter/a/e9c0ed/32.png) [@Andrew\_Johnson](https://rubytalk.org/u/Andrew_Johnson)\
**Post date:** [20 February 2004 20:54 UTC](https://rubytalk.org/t/how-to-raise-warning/10236/6 "2004-02-20T20:54:51Z")

</div>

Well, it’s certainly not unprecedented in Ruby:

Range.new(start, end, exclusive=false)  
load(filename, wrap=false)  
obj.respond\_to?(symbol, include\_private=false)  
obj.private\_methods(all=true)  
obj.protected\_methods(all=true)  
obj.public\_methods(all=true)

regards,  
andrew

> **···**
>
> On Fri, 20 Feb 2004 17:25:17 +0900, Mark Hubbart [discord@mac.com](mailto:discord@mac.com) wrote:
> 
> > I second that. Adding an optional boolean argument to the function to  
> > get different results doesn’t quite seem rubyish to me.

---

<div class="post-metadata">

**Author:** ![Charles\_Comstock](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Charles\_Comstock](https://rubytalk.org/u/Charles_Comstock)\
**Post date:** [20 February 2004 23:09 UTC](https://rubytalk.org/t/how-to-raise-warning/10236/7 "2004-02-20T23:09:52Z")

</div>

Andrew Johnson wrote:

> > I second that. Adding an optional boolean argument to the function to  
> > get different results doesn’t quite seem rubyish to me.
> 
> Well, it’s certainly not unprecedented in Ruby:
> 
> Range.new(start, end, exclusive=false)  
> load(filename, wrap=false)  
> obj.respond\_to?(symbol, include\_private=false)  
> obj.private\_methods(all=true)  
> obj.protected\_methods(all=true)  
> obj.public\_methods(all=true)
> 
> regards,  
> andrew

Right but not in things that print strings, the precedent there is not  
to use a boolean argument, since often you want to print multiple  
things. I like the warn! idea though. I would however say, that this  
is the classic use of a macro. Most other uses of macro’s we can  
replace with a call to eval. But we lose the ability to do inplace code  
expansion which is so important for **LINE** and things like that. That  
and there is a way in C that you can get something to print out the name  
of the variable. So you can have a macro that say:  
v = 5

but your macro just says DEBUGV(v);

It seems like we might be able to do something like that with a symbol,  
but I haven’t figured out how.

Charlie

> **···**
>
> > On Fri, 20 Feb 2004 17:25:17 +0900, Mark Hubbart [discord@mac.com](mailto:discord@mac.com) wrote:

---

<div class="post-metadata">

**Author:** ![Mark\_Hubbart](https://avatars.discourse-cdn.com/v4/letter/m/b77776/32.png) [@Mark\_Hubbart](https://rubytalk.org/u/Mark_Hubbart)\
**Post date:** [23 February 2004 06:22 UTC](https://rubytalk.org/t/how-to-raise-warning/10236/8 "2004-02-23T06:22:31Z")

</div>

Since there were a few good responses on a Kernel.warn!() method, I  
decided to write up an RCR for it. It can be viewed here:  
[http://rcrchive.net/rcr/RCR/RCR219](http://rcrchive.net/rcr/RCR/RCR219)

Please comment on it! 🙂 Constructive criticism is very welcome.

cheers,  
Mark
