class instance construction
Daniel Gibson
metalcaedes at gmail.com
Thu Nov 11 09:53:56 PST 2010
Steven Schveighoffer schrieb:
> On Thu, 11 Nov 2010 12:10:42 -0500, Steven Schveighoffer
> <schveiguy at yahoo.com> wrote:
>
>> On Thu, 11 Nov 2010 11:57:40 -0500, Daniel Gibson
>> <metalcaedes at gmail.com> wrote:
>>
>>> spir schrieb:
>>>> Still, an other case when "new" annoys me is method chaining,
>>>> because it makes syntax heavier and less readable:
>>>> c = (new C(p)).do(x);
>>>> versus:
>>>> c = C(p).do(x);
>>>> Or, maybe, the parser could be clever enough to correctly decode:
>>>> c = new C(p).do(x);
>>>>
>>>
>>> Is this really a common case?
>>> Constructing an object, just to call *one* method on it and then
>>> throw it away?
>>
>> If the do method returns this, you aren't throwing it away.
Ok, this is a case I didn't think of, you're right :-)
>
> A realistic example (from dcollections):
>
> auto ll = (new LinkedList(someOtherCollection)).sort();
>
> http://www.dsource.org/projects/dcollections/browser/branches/d2/dcollections/LinkList.d#L1054
>
>
> That being said, I'm really ambivalent on whether this needs to be
> included. It's not that terrible that you have to parenthesize properly.
Also, I'm not sure if this is a common case.. although I had similar situations
as well (it was more like (new Cursor(somecollection)).where(...).select(..)
with where() and select() returning a Cursor that wrapped/used the preceding
cursor.. and also it was Java).
But I don't know if this is useful for other kinds of code that don't deal with
collections or similar stuff.
>
> -Steve
Cheers,
- Daniel
More information about the Digitalmars-d
mailing list