Overloading property vs. non-property

torhu no at spam.invalid
Thu Jul 15 08:21:02 PDT 2010


On 15.07.2010 15:16, dsimcha wrote:
> Once property syntax is fully enforced (not necessarily recommended) will it
> be possible to overload properties against non-properties?  My use case is
> that I'm thinking about API improvements for my dflplot lib and one thing that
> I would really like is to give a fluent interface to everything to further cut
> back on the amount of boilerplate needed to generate simple plots.  For example:
>
> Histogram(someData, 10)
>      .barColor(getColor(255, 0, 0))
>      .histType(HistType.Probability)
>      .toFigure.title("A Histogram")
>      .xLabel("Stuff").showAsMain();
>
> The problem is that I also want things like barColor and title to be settable
> via normal property syntax, using the equals sign.  Right now, this "just
> works" because D's current non-analness about enforcing @property-ness is
> awesome 99% of the time even if it leads to a few weird corner cases.  Will
> there be a way to express such an interface to be provided (calling a setter
> as either a member function or a property at the user's choice) once @property
> is fully implemented?
>

In case the answer is no, that example of yours is the perfect 
opportunity to dust off the almost-forgotten with statement :)

with (Histogram(someData, 10)) {
      barColor = getColor(255, 0, 0);
      histType = HistType.Probability;
      toFigure.title = "A Histogram";
      xLabel = "Stuff";
      showAsMain();
}

A bit more typing, but I'd say that it's easier to read.


More information about the Digitalmars-d mailing list