Indexing access for Lists and Maps considered harmful?

Reinier Zwitserloot reinier at zwitserloot.com
Wed Jun 24 12:25:38 PDT 2009


Neal, your conclusion that, instead of combining a set/put and a get  
call, we need a new interface / desugaring to a method you then  
statically import / extension method in / etc - which has a single  
call that takes in a value, and returns the post-conversion  
representation of that value, cannot be reconciled with  
java.util.List, nor with java.util.Map, without breaking backwards  
compatibility.

Therefore, any movement in that direction would result in non-standard  
Map and List implementations not supporting the syntax, until someone  
updates them.

Talk about inconsistency.

I'd much rather have SetIndex and GetIndex interfaces that can be  
retrofitted on top of List and Map without breaking existing code. If  
this means a[i] = x is a statement and not an expression when it  
desugars into SetIndex/GetIndex, so be it.

NB: I've said my piece, so I'll let others come up with an actual  
workable proposal. I don't really give a hoot about this proposal in  
the first place, as I use List.get(idx) and List.set(idx, v) pretty  
much never, and I can live with writing it longhand for maps. I'd rate  
map and list literals, especially literals that can easily be made  
immutable (or better: immutable by default - if you want mutable,  
stuff an immutable literal in an ArrayList/HashMap constructor), as  
seeing on the order of 100x more use at least in my code base than  
this stuff.

  -- Reinier Zwitserloot




More information about the coin-dev mailing list