Re: testing with a "warn"
> On 29 Apr 2016, at 21:50, Brandon Allbery wrote: > > On Fri, Apr 29, 2016 at 3:47 PM, Brandon Allbery wrote: > Oh, they are resumable exceptions? Useful but rather high cost I'd think. > (Granting that perl6 isn't one of those languages that think exceptions > should be normal control flow. But anyone who decides it should be is > probably in for a very slow slog.) > > ...also I now know that I should not use warn in many cases where I would > have otherwise. Please note that there is also “note”, which is exactly the same as “say”, but writes to $*ERR rather than $*OUT. Liz
Re: testing with a "warn"
http://doc.perl6.org/routine/warn "To simply print to $*ERR, please use note instead. warn should be reserved for use in threatening situations when you don't quite want to throw an exception." And for testing, maybe something like this: use Test; my $warning; { warn 'some warning'; CONTROL { when CX::Warn { $warning = .message; } } } is $warning, 'some warning'; On 2016-04-30 09:07:24 IRDT, rnhainsworth wrote: > Hi. Sorry to ask again, but there are two independent questions here. 1) What > is the purpose or best use of 'warn'. 2) How to test code that contains a > 'warn' used as it should be. > 1) I thought that a 'warn' would be used where sometimes the user would want > a fail but not always. I have a module that in normal use I want to continue > even if there is a bad condition which has a default action, but that I can > get to fail if I set an external flag. Maybe I'm wrong. But this is not the > question I originally asked. > 2) whatever may be the purpose of a warn, and I assume there is a good one > since its in core perl6, surely the code that contains it should be tested, > which means triggering the condition and picking up the warning. I can't work > out how to do this. Can't get Test::Output to pick up the message sent to > stderr from warn. > Regards > > > Original message ----From: Larry Wall Date: > 30/04/2016 06:45 (GMT+08:00) To: Brandon Allbery Cc: > Timo Paulssen , perl6-users Subject: > Re: testing with a "warn" > On Fri, Apr 29, 2016 at 03:50:21PM -0400, Brandon Allbery wrote: > : On Fri, Apr 29, 2016 at 3:47 PM, Brandon Allbery > : wrote: > : > Oh, they are resumable exceptions? Useful but rather high cost I'd think. > : > (Granting that perl6 isn't one of those languages that think exceptions > : > should be normal control flow. But anyone who decides it should be is > : > probably in for a very slow slog.) > > Warnings are implemented like return or next; control exceptions are > more efficient than error exceptions. (This is one of the reasons you > have to catch them with a CONTROL block rather than a CATCH block.) > > : ...also I now know that I should not use warn in many cases where I would > : have otherwise. > > If you need to produce actual warnings in hot code, something's wrong > with your design. (If you just want to print to STDERR, you can use > 'note' instead.) > > Larry
Re: testing with a "warn"
Hi. Sorry to ask again, but there are two independent questions here. 1) What is the purpose or best use of 'warn'. 2) How to test code that contains a 'warn' used as it should be. 1) I thought that a 'warn' would be used where sometimes the user would want a fail but not always. I have a module that in normal use I want to continue even if there is a bad condition which has a default action, but that I can get to fail if I set an external flag. Maybe I'm wrong. But this is not the question I originally asked. 2) whatever may be the purpose of a warn, and I assume there is a good one since its in core perl6, surely the code that contains it should be tested, which means triggering the condition and picking up the warning. I can't work out how to do this. Can't get Test::Output to pick up the message sent to stderr from warn. Regards Original message From: Larry Wall Date: 30/04/2016 06:45 (GMT+08:00) To: Brandon Allbery Cc: Timo Paulssen , perl6-users Subject: Re: testing with a "warn" On Fri, Apr 29, 2016 at 03:50:21PM -0400, Brandon Allbery wrote: : On Fri, Apr 29, 2016 at 3:47 PM, Brandon Allbery : wrote: : > Oh, they are resumable exceptions? Useful but rather high cost I'd think. : > (Granting that perl6 isn't one of those languages that think exceptions : > should be normal control flow. But anyone who decides it should be is : > probably in for a very slow slog.) Warnings are implemented like return or next; control exceptions are more efficient than error exceptions. (This is one of the reasons you have to catch them with a CONTROL block rather than a CATCH block.) : ...also I now know that I should not use warn in many cases where I would : have otherwise. If you need to produce actual warnings in hot code, something's wrong with your design. (If you just want to print to STDERR, you can use 'note' instead.) Larry
Re: testing with a "warn"
On Fri, Apr 29, 2016 at 6:45 PM, Larry Wall wrote: > If you need to produce actual warnings in hot code, something's wrong > with your design. (If you just want to print to STDERR, you can use > 'note' instead.) > The latter's more what I was getting at, yes. -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net
Re: testing with a "warn"
On Fri, Apr 29, 2016 at 03:50:21PM -0400, Brandon Allbery wrote: : On Fri, Apr 29, 2016 at 3:47 PM, Brandon Allbery : wrote: : > Oh, they are resumable exceptions? Useful but rather high cost I'd think. : > (Granting that perl6 isn't one of those languages that think exceptions : > should be normal control flow. But anyone who decides it should be is : > probably in for a very slow slog.) Warnings are implemented like return or next; control exceptions are more efficient than error exceptions. (This is one of the reasons you have to catch them with a CONTROL block rather than a CATCH block.) : ...also I now know that I should not use warn in many cases where I would : have otherwise. If you need to produce actual warnings in hot code, something's wrong with your design. (If you just want to print to STDERR, you can use 'note' instead.) Larry
Re: testing with a "warn"
On Fri, Apr 29, 2016 at 3:47 PM, Brandon Allbery wrote: > Oh, they are resumable exceptions? Useful but rather high cost I'd think. > (Granting that perl6 isn't one of those languages that think exceptions > should be normal control flow. But anyone who decides it should be is > probably in for a very slow slog.) ...also I now know that I should not use warn in many cases where I would have otherwise. -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net
Re: testing with a "warn"
On Fri, Apr 29, 2016 at 3:44 PM, Timo Paulssen wrote: > I didn't actually read the other mail in this thread yet, but you can > catch a control exception (like warn uses) with a CONTROL block. Don't > forget to .resume the exception unless you want it to break out of your > code, too. > Oh, they are resumable exceptions? Useful but rather high cost I'd think. (Granting that perl6 isn't one of those languages that think exceptions should be normal control flow. But anyone who decides it should be is probably in for a very slow slog.) -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net
Re: testing with a "warn"
I didn't actually read the other mail in this thread yet, but you can catch a control exception (like warn uses) with a CONTROL block. Don't forget to .resume the exception unless you want it to break out of your code, too. Hope to help! - Timo
Re: testing with a "warn"
On Fri, Apr 29, 2016 at 1:25 AM, Richard Hainsworth wrote: > throws-like { abc('excess') }, Exception, 'got the exception', message => > / excess recursion /; I'm confused as to why you would expect this to work. The point of warn is it is *not* an exception; an exception by definition aborts code execution, while warn continues. As such, there is no exception and nothing you can catch --- since if you could catch it, it would mean the original code stopped executing and threw it instead. I could imagine a design where the block where you used `warn` attached some kind of extra value to whatever it eventually returns, but (a) it's a horrid lot of extra complexity and slowdowns to handle such a thing, and (b) you'd usually like to see the warning even if the block *doesn't* return. If you want a side system of some kind that lets you treat *that* case like an exception, then you're throwing fake exceptions to a whole separate thread that sits there waiting for them and does something or other --- again. lots of complexity for extremely dubious gain, and if you then decide that since you got your warnings-are-exceptions you should now get the full suite of things you could do with an exception... you now have that warnings must stop until the side thread tells them what to do, or else make warnings into full exceptions with some kind of resume capability that is turned on by default. But this isn't an actual warning and now people will ask why we don't have warnings, just resumable exceptions In short: exceptions are not warnings, not practically and not conceptually; they are a completely different thing entirely. No amount of scaffolding will turn an apple into a horse. Use Test::Output. -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net