[phobos] Time to get ready for the next release

David Simcha dsimcha at gmail.com
Thu Apr 21 16:36:02 PDT 2011


The fluent interface is my biggest concern.  Enforcing @property with strict
semantics makes it impossible to use a fluent interface and property syntax
for the same field.  Again, in Plot2kill, the following pieces of code are
equivalent and IMHO should be:

// Code piece 1
auto hist = Histogram(someArray, 100);
hist.barColor = getColor(255, 0, 0);
auto fig = hist.toFigure;
fig.title = "A histogram";
fig.xLabel = "XXX";

// Code piece 2:
auto fig = Histogram(someArray, 100)
    .barColor(getColor(255, 0, 0))
    .toFigure
    .title("A histogram")
    .xLabel("XXX");

I consider this a very nice API.  The with statement isn't a good
substitute.  I think it's ridiculous to break things like this in the name
of ultra-rigid consistency or to solve a few weird corner cases w.r.t.
functions that return zero-argument delegates, especially when the
zero-argument delegate corner case can be solved by enforcing @property with
loose semantics.

On Thu, Apr 21, 2011 at 6:02 PM, Robert Jacques <sandford at jhu.edu> wrote:

> On Thu, 21 Apr 2011 17:54:34 -0400, Jonathan M Davis <jmdavisProg at gmx.com>
> wrote:
>
>  > On Thu, 21 Apr 2011 16:14:22 -0400, Jonathan M Davis
>>> > <jmdavisProg at gmx.com>
>>> >
>>> > wrote:
>>> > >> On Thu, 21 Apr 2011 15:57:57 -0400, Jonathan M Davis
>>> > >> <jmdavisProg at gmx.com>
>>> > >>
>>> > >> wrote:
>>> > >> >> How about the amount of existing code it breaks? How about the
>>> fact
>>> > >> >> that
>>> > >> >> it breaks using the same function for both method chaining and
>>> with
>>> > >> >> property syntax?
>>> > >> >
>>> > >> > Something like
>>> > >> >
>>> > >> > auto b = a.prop1.prop2.prop3;
>>> > >> >
>>> > >> > should work. I doesn't at present, but it should. There's a bug
>>> > >> > report on it.
>>> > >>
>>> > >> What about auto b = a.prop1(5).prop2(6).prop3(7); ?
>>> > >
>>> > > I'd consider that to be the same. It should work, but it doesn't.
>>> > > There's a
>>> > > bug report for it.
>>> >
>>> > Ahem, so you'd consider auto b = a.prop1(7); valid code under strict
>>> > property rules?
>>>
>>> Oh wait. You're right. I didn't read that right. No, that wouldn't be
>>> legal. That would be both getting and setting. Why would you even try and
>>> do that with a property, let alone with several chained together?
>>>
>>
>> Oh. I suppose that that could be legal if the value of the property was
>> callable with a single integer and that function returned a value. If so,
>> that
>> should be legal. But other than that, I can't think of why it would be
>> legal
>> to do that, or make any sense to for that matter.
>>
>> - Jonathan M Davis
>>
>
> See: http://en.wikipedia.org/wiki/Method_chaining and specifically,
> http://en.wikipedia.org/wiki/Fluent_interface
>
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20110421/84367c91/attachment-0001.html>


More information about the phobos mailing list