Indexing access for Lists and Maps considered harmful?

Tim Peierls tim at peierls.net
Mon Jun 22 12:33:33 PDT 2009


Cool way to do swap and cyclic shift without temporaries:
  m[a] = m[b] = m[c] = m[a];

I love it! Can I have it, can I, huh? :-)

Seriously, I don't think this is a showstopper.

--tim

On Mon, Jun 22, 2009 at 3:19 PM, Joseph D. Darcy <Joe.Darcy at sun.com> wrote:

> Hello.
>
> A recent blog post cited in Alex Miller's handy "Java 7 Links"
> (http://java7.tumblr.com) claims that adding indexing support for Lists
> and Maps would be harmful because of an arguably surprising behavior on
> compound assignment.  After
>
> map["a"] = map["b"] = "c";
>
> the new value for key "a" would be the old mapping of "b" and not
> necessarily "c" because a call to the put method returns the old value.
>
> I'm not too concerned about this interaction because compound assignment
> is relatively infrequent; however, I think a lint warning from the
> compiler would be appropriate in this case.  Also, an IDE could color
> the non-array uses of "[]" differently to highlight any potential
> differences in semantics.
>
> As a meta-comment, I find it odd that if someone wanted to inform the
> coin discussion he or she would not directly email the coin list in
> addition to or instead of posting a blog entry.
>
> -Joe
>
>



More information about the coin-dev mailing list