[#79440] [Ruby trunk Bug#13188] Reinitialize Ruby VM. — shyouhei@...
Issue #13188 has been updated by Shyouhei Urabe.
6 messages
2017/02/06
[#79441] Re: [Ruby trunk Bug#13188] Reinitialize Ruby VM.
— SASADA Koichi <ko1@...>
2017/02/06
On 2017/02/06 10:10, shyouhei@ruby-lang.org wrote:
[#79532] Immutable Strings vs Symbols — Daniel Ferreira <subtileos@...>
Hi,
15 messages
2017/02/15
[#79541] Re: Immutable Strings vs Symbols
— Rodrigo Rosenfeld Rosas <rr.rosas@...>
2017/02/15
Em 15-02-2017 05:05, Daniel Ferreira escreveu:
[#79543] Re: Immutable Strings vs Symbols
— Daniel Ferreira <subtileos@...>
2017/02/16
Hi Rodrigo,
[#79560] Re: Immutable Strings vs Symbols
— Rodrigo Rosenfeld Rosas <rr.rosas@...>
2017/02/16
Em 15-02-2017 22:39, Daniel Ferreira escreveu:
[ruby-core:79576] [Ruby trunk Bug#13102] Confusing method name: Set#delete?
From:
kuchenbecker.k@...
Date:
2017-02-17 15:34:30 UTC
List:
ruby-core #79576
Issue #13102 has been updated by Kai Kuchenbecker. Stefan Schテシテ殕er wrote: > Not really, `Set#delete` also modifies the receiver. > > The actual difference is that `Set#delete` always returns `self`, whereas `Set#delete?` only returns `self` if the element existed in the set, and `nil` otherwise. > > > it is the duality we all know from methods such as Array's #uniq and #uniq!, [...] > > Not quite. If a class has a method with and without `!` (e.g. `uniq` / `uniq!`), then the bang-method usually modifies the receiver (often returning `nil` to indicate "no changes") and and the non-bang method returns a new object. > > If we had both, `Set#delete` and `Set#delete!`, I would expect the non-bang method to return a new set and the band method to modify the receiver. > > That would be consistent but it would also break backwards compatibility. Let me point you to this explanation on the use of bang in ruby method names: https://www.ruby-forum.com/topic/176830#773946 It is perpetually misunderstood for bang to mean that it "changes the receiver", it doesn't! You will see why I chose my wording as I did when you read the linked post written by Matz back in 2009. However, you are right to point out that `Set#delete` does change the receiver, which means I wrongly stated that we have the duality we know from `Array#uniq(!)` and others. However, my main point still stands, it is weird to have `Set#delete?` delete an item from a set. ---------------------------------------- Bug #13102: Confusing method name: Set#delete? https://bugs.ruby-lang.org/issues/13102#change-63008 * Author: Kai Kuchenbecker * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: 2.4.0 * Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- Greetings, a colleague of mine who recently started to learn Ruby managed to greatly confuse me today when he used Set#delete? which he claimed would delete an item from a set. Reading the documentation I suspect the method was meant to be named delete! as it behaves similiar to Array#uniq! and such methods. If this is not a mistake, I'd still suggest to change the method name since I think it is very surprising for a method ending in a question mark to have a side effect. Best regards, Kai -- https://bugs.ruby-lang.org/ Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>