Overloading property vs. non-property

Tomek Sowiński just at ask.me
Fri Jul 23 14:08:21 PDT 2010


Dnia 15-07-2010 o 22:55:04 torhu <no at spam.invalid> napisał(a):

> On 15.07.2010 17:42, dsimcha wrote:
>> == Quote from torhu (no at spam.invalid)'s article
>>>  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.
>>
>> But toFigure returns a Figure, not this.  The idea is that you'd set  
>> all the
>> properties for the Plot, then put toFigure somewhere in your chain,  
>> then set all
>> the properties for the Figure.
>
> Oops, guess I should have waited until after my nap with posting :)
>
> You could nest the with statements, but then it's getting more verbose.
>
> Might be better to add a convenience constructor or two to Figure that  
> takes care of the most common cases, and having toFigure forward to that.
>
> with (Histogram(someData, 10)) {
>        barColor = getColor(255, 0, 0);
>        histType = HistType.Probability;
>        toFigure("A Histogram", "Stuff").showAsMain();
> }
>
> Other options include having a factory function that returns a  
> probability histogram, or even make it a template parameter and a have a  
> ProbabilityHistogram alias, etc.  A few small changes could help a lot  
> for the common use cases.  It would never be as quite flexible as what  
> you have now, but you might get close enough.

Perhaps another with?

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

Tomek


More information about the Digitalmars-d mailing list