Forum: Ruby-core [Ruby 1.9 - Feature #5009][Open] Bang method (!) consistency in Ruby 2 API

79f9616c279f40ef953f366dcfe38dc8?d=identicon&s=25 Suraj Kurapati (sunaku)
on 2011-07-09 23:07
(Received via mailing list)
Issue #5009 has been reported by Suraj Kurapati.

----------------------------------------
Feature #5009: Bang method (!) consistency in Ruby 2 API
http://redmine.ruby-lang.org/issues/5009

Author: Suraj Kurapati
Status: Open
Priority: Normal
Assignee:
Category:
Target version: 2.0


=begin
Hello,

In Ruby 2, please use bang methods (those that end with !) consistently
in the API.  For example, the Ruby 1 API inconsistently names the
following "destructive" methods plainly (without a bang):

* Array#push
* Array#pop
* Array#shift
* Array#unshift
* Array#concat
* Array#delete
* Array#clear

Please convert these into bang methods in the Ruby 2 API.

Thanks for your consideration.
=end
86c36d71ce091a5cbc87279adf23e57e?d=identicon&s=25 Michael Edgar (Guest)
on 2011-07-09 23:13
(Received via mailing list)
Issue #5009 has been updated by Michael Edgar.


This is a common misconception about the use of bang methods in Ruby.
Bang does not indicate that a method mutates its receiver, merely that
it should be used with caution.

A good writeup on this can be found here:
http://dablog.rubypal.com/2007/8/15/bang-methods-o...

From the conclusion:

> If you let go of the notion that ! means destructive, and if you think through
the naming and pairing of dangerous and non-dangerous methods, you’ll see how
valuable a flag the ! can be.
----------------------------------------
Feature #5009: Bang method (!) consistency in Ruby 2 API
http://redmine.ruby-lang.org/issues/5009

Author: Suraj Kurapati
Status: Open
Priority: Normal
Assignee:
Category:
Target version: 2.0


=begin
Hello,

In Ruby 2, please use bang methods (those that end with !) consistently
in the API.  For example, the Ruby 1 API inconsistently names the
following "destructive" methods plainly (without a bang):

* Array#push
* Array#pop
* Array#shift
* Array#unshift
* Array#concat
* Array#delete
* Array#clear

Please convert these into bang methods in the Ruby 2 API.

Thanks for your consideration.
=end
C4e88907313843cf07f6d85ba8162120?d=identicon&s=25 Michael Klishin (Guest)
on 2011-07-09 23:21
(Received via mailing list)
Issue #5009 has been updated by Michael Klishin.


If this is a proposal for renaming aforementioned methods, it will break
a lot of existing code. If the idea is to add aliases, it will introduce
Ruby 2-specific methods that will not be used for a really long time by
developers who want to maintain compatibility with multiple Ruby
versions.
----------------------------------------
Feature #5009: Bang method (!) consistency in Ruby 2 API
http://redmine.ruby-lang.org/issues/5009

Author: Suraj Kurapati
Status: Open
Priority: Normal
Assignee:
Category:
Target version: 2.0


=begin
Hello,

In Ruby 2, please use bang methods (those that end with !) consistently
in the API.  For example, the Ruby 1 API inconsistently names the
following "destructive" methods plainly (without a bang):

* Array#push
* Array#pop
* Array#shift
* Array#unshift
* Array#concat
* Array#delete
* Array#clear

Please convert these into bang methods in the Ruby 2 API.

Thanks for your consideration.
=end
9361878d459f1709feec780518946ee5?d=identicon&s=25 Yui NARUSE (Guest)
on 2011-07-10 09:52
(Received via mailing list)
Issue #5009 has been updated by Yui NARUSE.


-1
ActiveRecord's save/save! is also a good example.
----------------------------------------
Feature #5009: Bang method (!) consistency in Ruby 2 API
http://redmine.ruby-lang.org/issues/5009

Author: Suraj Kurapati
Status: Open
Priority: Normal
Assignee:
Category:
Target version: 2.0


=begin
Hello,

In Ruby 2, please use bang methods (those that end with !) consistently
in the API.  For example, the Ruby 1 API inconsistently names the
following "destructive" methods plainly (without a bang):

* Array#push
* Array#pop
* Array#shift
* Array#unshift
* Array#concat
* Array#delete
* Array#clear

Please convert these into bang methods in the Ruby 2 API.

Thanks for your consideration.
=end
F52e87b92cafb1e8c6d155076b56ecff?d=identicon&s=25 "Martin Dürst" <duerst@it.aoyama.ac.jp> (Guest)
on 2011-07-12 08:07
(Received via mailing list)
Issue #5009 has been updated by Martin Dürst.


Just for the record, there is one method that I think we should add a
bang if we still could, and this is String#force_encoding. The reason
isn't that it changes String itself (which it does), but that I have
come across quite some places where I use string.dup.force_encoding. It
would have been best to use force_encoding! for what's now
force_encoding, and force_encoding for the copying variant. But I agree
with both Michaels and Yui that it's too late to change.
----------------------------------------
Feature #5009: Bang method (!) consistency in Ruby 2 API
http://redmine.ruby-lang.org/issues/5009

Author: Suraj Kurapati
Status: Open
Priority: Normal
Assignee:
Category:
Target version: 2.0


=begin
Hello,

In Ruby 2, please use bang methods (those that end with !) consistently
in the API.  For example, the Ruby 1 API inconsistently names the
following "destructive" methods plainly (without a bang):

* Array#push
* Array#pop
* Array#shift
* Array#unshift
* Array#concat
* Array#delete
* Array#clear

Please convert these into bang methods in the Ruby 2 API.

Thanks for your consideration.
=end
9361878d459f1709feec780518946ee5?d=identicon&s=25 Yui NARUSE (Guest)
on 2011-07-12 08:17
(Received via mailing list)
Issue #5009 has been updated by Yui NARUSE.


Martin Dürst wrote:
> Just for the record, there is one method that I think we should add a bang if we
still could, and this is String#force_encoding. The reason isn't that it changes
String itself (which it does), but that I have come across quite some places 
where
I use string.dup.force_encoding. It would have been best to use force_encoding!
for what's now force_encoding, and force_encoding for the copying variant. But I
agree with both Michaels and Yui that it's too late to change.

About String#force_encoding, I think add an alias named String#encoding=
may be good.
But it's still under consideration.
----------------------------------------
Feature #5009: Bang method (!) consistency in Ruby 2 API
http://redmine.ruby-lang.org/issues/5009

Author: Suraj Kurapati
Status: Open
Priority: Normal
Assignee:
Category:
Target version: 2.0


=begin
Hello,

In Ruby 2, please use bang methods (those that end with !) consistently
in the API.  For example, the Ruby 1 API inconsistently names the
following "destructive" methods plainly (without a bang):

* Array#push
* Array#pop
* Array#shift
* Array#unshift
* Array#concat
* Array#delete
* Array#clear

Please convert these into bang methods in the Ruby 2 API.

Thanks for your consideration.
=end
D9ebdcb66f1583378e6f72155db507e2?d=identicon&s=25 Hans Mackowiak (hanmac)
on 2011-07-12 09:40
methods should only have an ! if there exist an method without the !


or: modify the method_missig hook that "meth" called ".dup.meth!" if
meth! exist
79f9616c279f40ef953f366dcfe38dc8?d=identicon&s=25 Suraj Kurapati (sunaku)
on 2011-07-14 22:01
(Received via mailing list)
Issue #5009 has been updated by Suraj Kurapati.


Interesting, the Rails' save/save! example makes sense.

And why worry about keeping backwards compatibility?

Ruby 2 can break it, in the interest of removing cruft.
----------------------------------------
Feature #5009: Bang method (!) consistency in Ruby 2 API
http://redmine.ruby-lang.org/issues/5009

Author: Suraj Kurapati
Status: Open
Priority: Normal
Assignee:
Category:
Target version: 2.0


=begin
Hello,

In Ruby 2, please use bang methods (those that end with !) consistently
in the API.  For example, the Ruby 1 API inconsistently names the
following "destructive" methods plainly (without a bang):

* Array#push
* Array#pop
* Array#shift
* Array#unshift
* Array#concat
* Array#delete
* Array#clear

Please convert these into bang methods in the Ruby 2 API.

Thanks for your consideration.
=end
9361878d459f1709feec780518946ee5?d=identicon&s=25 Yui NARUSE (Guest)
on 2011-07-15 17:30
(Received via mailing list)
Issue #5009 has been updated by Yui NARUSE.

Status changed from Open to Closed

Close this; force_encoding is another problem.
----------------------------------------
Feature #5009: Bang method (!) consistency in Ruby 2 API
http://redmine.ruby-lang.org/issues/5009

Author: Suraj Kurapati
Status: Closed
Priority: Normal
Assignee:
Category:
Target version: 2.0


=begin
Hello,

In Ruby 2, please use bang methods (those that end with !) consistently
in the API.  For example, the Ruby 1 API inconsistently names the
following "destructive" methods plainly (without a bang):

* Array#push
* Array#pop
* Array#shift
* Array#unshift
* Array#concat
* Array#delete
* Array#clear

Please convert these into bang methods in the Ruby 2 API.

Thanks for your consideration.
=end
This topic is locked and can not be replied to.