« Return to Thread: Naming collection operations

Re: Naming collection operations

by Rob Dickens-2 :: Rate this Message:

Reply to Author | View in Thread

fadd, fremove

2009/5/11 Viktor Klang <viktor.klang@...>
gain / lose ?


On Mon, May 11, 2009 at 10:18 AM, martin odersky <martin.odersky@...> wrote:
I have a question concerning an alternative naming for the + and -
methods on sets and maps.
We need a good letter-based name for the purely functional version of
these methods. `with` and `withOut` would have worked except that
`with` is a reserved word.

There are basically two reasons why we need the alternate names. One
is callability from Java. The other is that we are moving away from a
design where + and - mean different things for different collections.
Currently, they are side-effecting for mutable collections and create
new ones for immutable collections. The idea is to use +=, -= for the
side-effecting versions of + and -, and to reserve + and - for
operations that always create a new collection. To help users migrate,
+ and - will stay side-effecting on mutable collections for the time
being but will be deprecated there. The deprecation comment will say,
if you want to keep the same meaning in the future, use +=,
respectively -=, but if you really want a new collection, then use
<insert name> here to make the deprecation warning go away.

Therefore, one desiderata for the letter-based names is that they make
it clear that a new collection is created and the old collection is
left as it is. That's why I hesitate to use `add`, `remove`, for
example.

So, if you have a proposal, I'm interested!

Thanks

 -- Martin



--
Viktor Klang
Senior Systems Analyst



--
Rob, Lafros.com

 « Return to Thread: Naming collection operations