Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Math::Round::Var::round() takes no action when a number is not supplied

by metaperl (Curate)
on Aug 31, 2011 at 02:25 UTC ( #923333=note: print w/replies, xml ) Need Help??


in reply to Re: Math::Round::Var::round() takes no action when a number is not supplied
in thread Math::Round::Var::round() takes no action when a number is not supplied

It seems to raise a perfectly valid exception for me
Well, a Perl-generated warning is not the same as a program-generated exception, and here we have only a Perl-generated warning.
  • Comment on Re^2: Math::Round::Var::round() takes no action when a number is not supplied

Replies are listed 'Best First'.
Re^3: Math::Round::Var::round() takes no action when a number is not supplied
by BrowserUk (Pope) on Aug 31, 2011 at 02:34 UTC
    a Perl-generated warning is not the same as a program-generated exception,

    Really? So how do you handle them differently?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
        In my eyes, the number argument is required and not passing it should throw an exception.

        But you are still dodging my question.

        The point is, what difference would it make to how you handle the situation -- in your calling code -- whereby your code passes a non-numeric value to be numerically formatted.

        If instead of concentrating upon some wholly artificial and academic value judgement of what (in your opinion), the module should or should not do, and instead think about what action your code would take when this situation arises, then you'd probably arrive at the conclusion that there are only two possibilities:

        1. You prevent the situation by ensuring that it cannot happen.
        2. You log an error if it does.

        If the values are coming in from an unreliable (external) source, then you should be checking that they comply with your input criteria at source, and rejecting them if they fail to so comply. If you have done that, then an additional check at some later point when you are using them -- for example, inside a round() function -- are completely redundant.

        If however, the values are being generated internally by your code, then it again falls to you to ensure that your code cannot generate non-numeric values where numeric values are required. Expecting a library routine to check your values for you is ridiculous.

        The bottom line is that if you call a library routine to round() a numeric value, it falls to you to ensure that you only pass it numeric values. Expecting every other user of that module to bear the cost of the redundant check, just so you can avoid performing that check when required, is selfish. You (should) know where and when (in your code) it is necessary to validate values.

        Look up design by contract.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://923333]
help
Chatterbox?
[marioroy]: ... including MCE 1.830. Finally, reached the finish line. All is well.
[marioroy]: The issue on the Windows platform is many workers loading "required" modules simultaneously, more so with XS modules.
[marioroy]: ... at runtime.
[marioroy]: The other problem is if a module isn't thread or multi-process safe, there's no posix_exit equivalent on the Windows platform without exiting the entire script.
[Discipulus]: and the workaround you proposed works better? ie load them once and then copy them for threads?
[Discipulus]: ah this is another interesting point: how to know if a module is or is not thread safe?
[Discipulus]: .. sorry mario if i'm bothering you at 5:46
[choroba]: Some modules mention their thread safety in the documentation
[choroba]: if they don't, it's safer to asume they aren't safe

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2017-09-22 09:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (260 votes). Check out past polls.

    Notices?