[#24105] [Bug #1711] Marshal Failing to Round-Trip Certain Recurisve Data Structures — Run Paint Run Run <redmine@...>

Bug #1711: Marshal Failing to Round-Trip Certain Recurisve Data Structures

9 messages 2009/07/01

[#24116] [Bug #1715] Numeric#arg for NaN is Inconsistent Across Versions — Run Paint Run Run <redmine@...>

Bug #1715: Numeric#arg for NaN is Inconsistent Across Versions

10 messages 2009/07/02

[#24240] [Bug #1755] IO#reopen Doesn't Fully Associate with Given Stream on 1.9; Ignores pos on 1.8 — Run Paint Run Run <redmine@...>

Bug #1755: IO#reopen Doesn't Fully Associate with Given Stream on 1.9; Ignores pos on 1.8

8 messages 2009/07/09

[#24321] [Bug #1773] Gem path doesn't honor user gem? — Lin Jen-Shin <redmine@...>

Bug #1773: Gem path doesn't honor user gem?

12 messages 2009/07/14

[#24390] [Feature #1784] More encoding (Big5 series) support? — Lin Jen-Shin <redmine@...>

Feature #1784: More encoding (Big5 series) support?

12 messages 2009/07/16

[#24467] Re: [ruby-cvs:31226] Ruby:r24008 (ruby_1_8_6): Removed private on to_date and to_datetime. — Urabe Shyouhei <shyouhei@...>

Hello.

10 messages 2009/07/21

[#24472] [Feature #1800] rubygems can replace system executable files — Kazuhiro NISHIYAMA <redmine@...>

Feature #1800: rubygems can replace system executable files

13 messages 2009/07/21

[#24530] [Feature #1811] Default BasicSocket.do_not_reverse_lookup to true — Roger Pack <redmine@...>

Feature #1811: Default BasicSocket.do_not_reverse_lookup to true

9 messages 2009/07/23

[#24624] [Bug #1844] Immediates Should Not Respond to :dup — Run Paint Run Run <redmine@...>

Bug #1844: Immediates Should Not Respond to :dup

15 messages 2009/07/30

[ruby-core:24131] [Bug #1708] require 'complex' Causes Unexpected Behaviour

From: Run Paint Run Run <redmine@...>
Date: 2009-07-03 20:06:46 UTC
List: ruby-core #24131
Issue #1708 has been updated by Run Paint Run Run.


> According to the fail-early principle, unexpected situation should be
> told (by raising an error) as early as possible.

I'd always considered that to apply to calculations that would ultimately fail, the logic being that you should complain about arguments that would cause failure up front, rather than attempting to perform an expensive calculation with them and then failing. In this case, we don't need to fail. We can give the right answer. 

Let's use Math.sqrt(-2) for an example. Without 'cmath' the programmer's only option would be to rescue Errno::EDOM. With 'cmath' they could achieve the same effect by inspecting the result's #real? method, or they could perform mathematical operations on the result. With Complex implementing so many Numeric methods, it's perfectly possible for their code to continue to work with complex results. The difference being that now exceptions are much rarer. Integration of 'cmath' gives the programmer more control. Put another way, one can perform many more operations with a Complex object than he can with an Exception object.

Further, Math.sqrt(-2) raising an exception seems dishonest. The answer is perfectly knowable and calculable; we'd raise an exception not because the input was exceptional but because, presumably, we wanted to protect the programmer from calling a method on the result that was allowed for reals, but disallowed for non-reals. That is, we'd want to protect the programmer from saying:

    Math.sqrt(n) > LIMIT  # Raises a NoMethodError for :> if .sqrt returns a Complex

Or:
    side = Math.sqrt(area_of_square)
    # ....
    cost = side * cost_per_side   # cost may be a complex number...

Note that a similar argument could be levied against methods that occasionally returned Floats, too. A programmer who blindly calls #odd? on the result will have the same shock as if he blindly called a Fixnum method on a result which was occasionally complex.

Lastly, if we're considering programmers who may not expect to receive complex results from Math methods, we must also consider those who, knowing that Complex is in core, have the contrary expectation... ;-)

And now I'll be quiet to give other parties a chance to participate. ;-) 
----------------------------------------
http://redmine.ruby-lang.org/issues/show/1708

----------------------------------------
http://redmine.ruby-lang.org

In This Thread