« Return to Thread: Naming collection operations

Re: [scala-internals] Naming collection operations

by Ricky Clarkson :: Rate this Message:

Reply to Author | View in Thread

I'd like it to be an error, not a warning.  I know I personally have some deprecation warnings I ignore, because, for instance, I prefer writing List(1, 2) + 3 to List(1, 2) ++ List(3) (though I'm not writing that in any new code).  So I might not notice new ones, and I bet I'm not the only one.  Changing the meaning seems to require something stronger than deprecation, perhaps just deleting the method for a few versions.

2009/5/11 martin odersky <martin.odersky@...>
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

 « Return to Thread: Naming collection operations