+1
Brilliant!
Concise, unambiguous, and conveys the intent of the views as well as
providing hints of usage patterns.
/Morten
> Definition: A *view* of one or more objects passes all queries through to
> the backing object(s). Changes to the backing objects will be reflected in
> queries to the view. Sometimes, views support modification operations,
> which always write through to the backing object(s).
>
> Views typically have no state of their own at all -- they're not lazy, or
> thunks. They're just wrappers.
>
> Sets.difference(Set, Set), Map.keySet(), and List.subList(int, int) all
> return views. The SetView class, which implements Set, is meant to help
> with common needs -- frequently, you just want to copy them into a concrete
> set to "freeze" them, and/or to avoid incurring the overhead of the wrapper.
>
> Louis Wasserman
> wasserman.lo...@gmail.comhttp://
profiles.google.com/wasserman.louis
>
> On Sat, Apr 28, 2012 at 10:02 PM, Louis Wasserman <
wasserman.lo...@gmail.com> wrote:
> > Um...no?
>
> > A SetView is already a Set. It implements the Set interface. When you
> > change the backing sets, the SetView reflects the updates.
>
> > That's what the word "view" means, as used by the JDK docs.
>
> > On Sat, Apr 28, 2012 at 8:37 PM, Russ Abbott <
russ.abb...@gmail.com>wrote:
>
> >> That's part of the point. If you convert a SetView into a Set, you can't
> >> change the banking sets and have the computed set change. With an
> >> expression, that's exactly what one wants, i.e., something that you intend
> >> to keep around and that will change when the backing elements change.
>
> >> On Sat, Apr 28, 2012 at 5:38 PM, Colin Decker <
cgdec...@gmail.com> wrote:
>
> >>> I'm really unclear on what you mean by "static" views.
>
> >>> And SetView definitely isn't implying that one shouldn't keep a SetView
> >>> around. Note that what SetView's documentation actually says is that there
> >>> "is usually no reason to retain a reference *of the type SetView*", meaning
> >>> that if you're going to keep it around, there isn't much point using the
> >>> SetView type... just refer to it as a Set. The SetView type is primarily
> >>> there to allow stuff like "Sets.difference(a, b).immutableCopy()".
>
> >>> --
> >>> Colin
>
> >>> On Sat, Apr 28, 2012 at 8:25 PM, Russ Abbott <
russ.abb...@gmail.com>wrote:
>
> >>>> The point was to illustrate the difference between a view and an
> >>>> expression. I think I understand what the intent of a view is. I'm not sure
> >>>> you understand what I'm thinking of when I suggest calling it
> >>>> an expression. Perhaps you would never want to use it, but I'd like to know
> >>>> that you understand what I'm talking about and the distinction I'm trying
> >>>> to make.
>
> >>>> Also, regarding views in databases, my sense is that the term "view" is
> >>>> used because one is thinking about an end user and one is providing him
> >>>> with a static view of a perhaps changing data base. That's somewhat
> >>>> different from what one wants as a developer. In the documentation for
> >>>> SetView, the point is made that one doesn't keep a SetView around. With
> >>>> database views one does keep the view around. They really are intended
> >>>> differently even though they are both delayed computations.
>
> >>>> On Sat, Apr 28, 2012 at 4:46 PM, Louis Wasserman <
> >>>>
wasserman.lo...@gmail.com> wrote:
>
> >>>>> Why would you do any of that? It's more readable to just do it the
> >>>>> compositional way, by building up results from the views.
>
> >>>>> In any event, it's also noticeably inefficient to have views of views
> >>>>> of views, which means that you shouldn't be building up those sorts of
> >>>>> complex objects *anyway*.
>
> >>>>> Louis Wasserman
> >>>>>
wasserman.lo...@gmail.com
> >>>>>
http://profiles.google.com/wasserman.louis
> >>>>>>>
wasserman.lo...@gmail.com
> >>>>>>>
http://profiles.google.com/wasserman.louis
>
> >>>>>>> On Sat, Apr 28, 2012 at 9:13 AM, Colin Decker <
cgdec...@gmail.com>wrote:
>
> >>>>>>>> Have you thought of "view" in the sense it's used in databases?
> >>>>>>>> It's really very similar here. In a database, you have one or more concrete
> >>>>>>>> tables containing data and a view is something you create that _looks_ like
> >>>>>>>> a table but that actually lazily executes some query on the concrete
> >>>>>>>> table(s) when you query it, producing results that differ in some way from
> >>>>>>>> the original table(s). The view doesn't store data itself. Here, the
> >>>>>>>> backing collections are analogous to the database tables and the view
> >>>>>>>> collection is analogous to the database view... it looks like the same type
> >>>>>>>> of thing as the originals (it's a collection too) but operations on it read
> >>>>>>>> from the originals and apply some kind of transformations and/or filtering
> >>>>>>>> to produce different results.
>
> >>>>>>>> --
> >>>>>>>> Colin
>
> >>>>>>>> On Sat, Apr 28, 2012 at 3:15 AM, Russ Abbott <
russ.abb...@gmail.com
> >>>>>>>> > wrote:
>
> >>>>>>>>> If it were possible to begin again and step back from the term *
> >>>>>>>>> view*, I would say that Sets.difference, Sets.union, etc. produce
> >>>>>>>>> set *expressions*. I would distinguish between a *view *and an *expression
> >>>>>>>>> *this way. A *view *is a static window over an existing object.
> >>>>>>>>> It is allowable to change that object but only in very limited ways. An
> >>>>>>>>> *expression *is a tree structure of operations the terminals of
> >>>>>>>>> which are sets that can be changed in virtually any way one wants.
>
> >>>>>>>>> A set expression is more like a function than like an object. It
> >>>>>>>>> would be a function if one could actually replace the sets at the terminal
> >>>>>>>>> positions of the expression with other sets. That is not possible, but one
> >>>>>>>>> can rebuild the sets at the terminal positions in any way one wants and
> >>>>>>>>> then have the expression re-evaluated.
>
> >>>>>>>>> The term *view *doesn't convey that degree of flexibility -- at
> >>>>>>>>> least to me it doesn't. It is much too static a term. It seems to me that
> >>>>>>>>> the Guava developers have come up with an interesting innovation with these
> >>>>>>>>> operations. Instead of downplaying it by calling it a view, I would
> >>>>>>>>> highlight it by calling it something different from a traditional view.
> >>>>>>>>> It's like what use to be called a "thunk<
http://en.wikipedia.org/wiki/Thunk_(functional_programming)>"
> >>>>>>>>> (pass by name) when describing a mode of passing parameters.
>
> >>>>>>>>> *-- Russ *
>
> >>>>>>>>> On Fri, Apr 27, 2012 at 12:45 PM, Louis Wasserman <
> >>>>>>>>>
wasserman.lo...@gmail.com> wrote:
>
> >>>>>>>>>> Perhaps we should just {@linkplain SetView view}, just to make
> >>>>>>>>>> that documentation link clearer?
>
> >>>>>>>>>> Louis Wasserman
> >>>>>>>>>>
wasserman.lo...@gmail.com
> >>>>>>>>>>
http://profiles.google.com/wasserman.louis
>
> >>>>>>>>>> On Fri, Apr 27, 2012 at 2:28 PM, Kevin Bourrillion <
> >>>>>>>>>>
kev...@google.com> wrote:
>
> >>>>>>>>>>> Hrm.
>
> >>>>>>>>>>> The methods like Sets.union are documented like this:
>
> >>>>>>>>>>> "Returns an unmodifiable <b>view</b> of the union of two sets."
>
> >>>>>>>>>>> ... with boldfacing. And SetView says:
>
> >>>>>>>>>>> "An unmodifiable view of a set which may be backed by other
> >>>>>>>>>>> sets; this view will change as the backing sets do. Contains methods to
> >>>>>>>>>>> copy the data into a new set which will then remain stable."
>
> >>>>>>>>>>> This is seems as clear as can be already, provided that we can
> >>>>>>>>>>> assume general knowledge of the word "view". So I definitely approve of
> >>>>>>>>>>> adding "view" to our (anemic) glossary. But I wonder: to one who doesn't
> >>>>>>>>>>> know what "view" means, what other definition could they *infer* it
> >>>>>>>>>>> to mean?
>
> >>>>>>>>>>> On Fri, Apr 27, 2012 at 5:45 AM, Kevin Bourrillion <
> >>>>>>>>>>>
kev...@google.com> wrote:
>
> >>>>>>>>>>>> I will take on some javadoc rewriting for these APIs.
>
> >>>>>>>>>>>> On Thu, Apr 26, 2012 at 5:30 PM, Louis Wasserman <
> >>>>>>>>>>>>
wasserman.lo...@gmail.com> wrote:
>
> >>>>>>>>>>>>> Would folks be satisfied if I added a more specific definition
> >>>>>>>>>>>>> of view to the glossary page<
http://code.google.com/p/guava-libraries/wiki/GuavaTermsExplained>on the wiki? I'm thinking of a definition like
>
> >>>>>>>>>>>>> A *view *of one or more objects in Java is an object
> >>>>>>>>>>>>>> providing query operations that "read through" to the backing objects. In
> >>>>>>>>>>>>>> particular, views always reflect changes to the backing objects.
> >>>>>>>>>>>>>> Additionally, some views may provide update operations which "write
> >>>>>>>>>>>>>> through" to the backing objects.
>
> >>>>>>>>>>>>> Louis Wasserman
> >>>>>>>>>>>>>
wasserman.lo...@gmail.com
> >>>>>>>>>>>>>
http://profiles.google.com/wasserman.louis
>
> >>>>>>>>>>>>> On Thu, Apr 26, 2012 at 7:25 PM, Louis Wasserman <
> >>>>>>>>>>>>>
wasserman.lo...@gmail.com> wrote:
>
> >>>>>>>>>>>>>> Perhaps a better comparison would be
> >>>>>>>>>>>>>> Collections.unmodifiableCollection, which performs exactly like a view
> >>>>>>>>>>>>>> ought to -- getting the view does almost no work by itself, and returns a
> >>>>>>>>>>>>>> collection backed by the argument collection, that reflects changes made to
> >>>>>>>>>>>>>> that backing collection.
>
> >>>>>>>>>>>>>> Louis Wasserman
> >>>>>>>>>>>>>>
wasserman.lo...@gmail.com
> >>>>>>>>>>>>> To get help:
http://stackoverflow.com/questions/ask(use the