On Thu, Apr 2, 2009 at 2:38 PM, David MacIver
<david.maciver@...> wrote:
2009/4/2 martin odersky <martin.odersky@...>:
> On Tue, Mar 24, 2009 at 1:16 AM, Raoul Duke <
raould@...> wrote:
>>>> Summary: Make it easy to switch from constructors to factories after
>>>> the fact by adding a mechanism where "new Foo(stuff)" can translate to
>>>> an invocation of a user defined method on the companion object.
>>
>> could we instead just try to do away with 'new' pretty please perhaps?
>>
> I also think that would be the nicer generalization. I have not
> thought about this or the SIP too much recently. So I'm not quite sure
> what to think of it.
I'd be totally ok with doing away with new in lieu of this SIP if
someone can come up with a decent proposal for doing so. :-)
Gilad's musings on constructors/factories may be relevant (and also a mixed bag)
http://gbracha.blogspot.com/2007/08/object-initialization-and-construction.html
"Because an instance is created by sending a message to an object, and
not by some special construct like a constructor invocation, we can
replace the receiver of that message with any object that responds to
that message. It can be another class (say, an implementation based on
polar coordinates), or it can be a factory object that isn’t a class at
all."
Structural typing to replace constructors? I'd actually prefer something along the lines of having implicit factories in scope (with defaults to class constructors) and injecting implicits via your (rejected) import
SIP. One can always hope! ;)
alex