Skip to content

Conversation

@mrkn
Copy link
Member

@mrkn mrkn commented Dec 13, 2017

To remove BigDecimal.new from Ruby 2.6, this should be deprecated during Ruby 2.5 period.

@mrkn mrkn merged commit 5337373 into master Dec 13, 2017
@mrkn mrkn deleted the deprecate_new branch December 13, 2017 13:20
@rafaelfranca
Copy link

Do you have the ticket with the reasoning to remove this method? Is it to match Interger()?

@mrkn
Copy link
Member Author

mrkn commented Dec 14, 2017

The reason is to match core numeric classes like Integer, Float, and Rational.

I've created the issue #89 to remove BigDecimal.new at Ruby 2.6.

@rafaelfranca
Copy link

Thanks! That make a lot of sense

@baweaver
Copy link

This may be the case, but it causes a lot of downstream errors and is a breaking change done on a minor version. What would be the harm in leaving this syntax and encouraging the new syntax instead?

I feel we should be very careful in deprecations like this as the downstream impact is substantial. It creates inconsistencies in Ruby and causes a lot of confusion for newer engineers.

Consider that we have:

Kernel method Constructor
Kernel#String String.new
Kernel#Hash Hash.new
Kernel#Array Array.new

...and several others. Across Ruby this is very inconsistent, and is very confusing to me.

@mrkn
Copy link
Member Author

mrkn commented Mar 21, 2019

BigDecimal is a subclass of Numeric, and core Numeric subclasses such as Integer don’t have new class method. So removing BigDecimal.new increases the consistency.

The Kernel methods you listed up are provided for conversion. new methods are provided for just construction. They have different roles.

@baweaver
Copy link

I do not argue with the consistency, I argue with the deprecation in a minor version causing several downstream repositories to break.

The cost of leaving new in is substantially less than that of removing it for consistency.

@mrkn
Copy link
Member Author

mrkn commented Mar 21, 2019

You can select version 1.3.5 if you need BigDecimal.new.

static VALUE
BigDecimal_s_new(int argc, VALUE *argv, VALUE self)
{
rb_warning("BigDecimal.new is deprecated");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a note, maybe this should have been rb_warn, as rb_warning only warns with $VERBOSE=true / ruby -w, not the default.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bigdecimal 1.4.x always warns in BigDecimal.new.
See https://github.com/ruby/bigdecimal/blob/v1.4.x/lib/bigdecimal.rb#L10

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but in e.g. MRI 2.5.3, bigdecimal 1.3.4 is default and so:

$ ruby -rbigdecimal -e 'p BigDecimal.new "2"'
0.2e1

does not warn (without -v/-w).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants