Indexing access for Lists and Maps considered harmful?
Joshua Bloch
jjb at google.com
Tue Jun 23 11:29:58 PDT 2009
Folks,
Hi. Sorry I'm late to the party; I'm just recovering from a pretty bad
cold.
I agree that this is not a showstopper.
I think it's *critical* that the behavior be defined to match the "expected"
behavior. These *must* function identically:
myArray[i] = myArray[j] = val;
myList[i] = myList[j] = val;
When extending a language, it's critical to enable reasoning by analogy; to
do otherwise *will* cause bugs and ill-will. (See this 20-year-old paper
for my take on the topic:
http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=37945 .)
Josh
On Mon, Jun 22, 2009 at 12:33 PM, Tim Peierls <tim at peierls.net> wrote:
> 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