Boost logo

Boost :

From: Jake Voytko (jakevoytko_at_[hidden])
Date: 2007-05-24 10:21:33


On 5/24/07, Paul A Bristow <pbristow_at_[hidden]> wrote:
> I'm surprised by this view of beginners expectations.
> Using a set function is surely very common.
>
> Although chaining is less common,
> you don't have to chain, you can write:
>
> my_graph.line_color(black);
> my_graph.point_color(blue);
> ...
>
> whose meaning is surely quite obvious?
>
> but once you see an example of chaining, I feel it is obvious what to do to save a bit of typing - always popular!

I think I miscommunicated at some point.. I didn't mean to say that
nobody would understand what to do if they were given a modifier
method, and surely method chaining is a way to save typing. I just
feel that using the stream operator gives a user a more intuitive feel
of how to use it. If I saw a code example that said

  my_plot<<line_color(red);
  my_plot<<point_color(black);

I feel it would be a reasonable conclusion that one could write,

  my_plot<<line_color(red)<<point_color(black);

without ever having looked at the docs! However, if I saw,

  my_plot.line_color(red);
  my_plot.point_color(black);

I never would expect to be able to chain the methods together without
reading the docs. My personal view of the stream operator is that it
says that chaining is implied, and method calls do not give that
implication. However, my understanding of the C++ language is
relatively nacent compared to many people on this forum, so I could be
wrong!

> PS Your prototype code doesn't permit chaining freely - it would intolerable in real-life use. But I'm sure you will be working on
> it ;-)

Indeed I am :) ! Or rather, I will be. The prototype code was written
over the course of a weekend (the longest possible break I could take
from my studies in one stretch) during the application process, so I
was more concerned about showing that I could produce results than
getting everything working. On the Wiki, I think I list that as one of
the first things that I need to work out.

Jake


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk