On Thursday, July 12, 2012 21:23:56 Christophe Travert wrote: > "Jonathan M Davis" , dans le message (digitalmars.D:172156), a écrit : > > On Thursday, July 12, 2012 18:25:03 David Piepgrass wrote: > >> I'm putting this in a separate thread from > >> http://forum.dlang.org/thread/uufohvapbyceuaylo...@forum.dlang.org > >> because my counterproposal brings up a new issue, which could be > >> summarized as "Constructors Considered Harmful": > >> > >> http://d.puremagic.com/issues/show_bug.cgi?id=8381 > > > > I think that adding constructors to a type from an external source is > > downright evil. It breaks encapsulation. I should be able to constrain > > exactly how you construct my type. If you want to create a free function > > (e.g. a factory function) which uses my constructors, fine. But I'm > > completely against adding constructors externally. > > The proposal is not that add constructors. It is to create a free > function (.make!Type(args)), that can called like a constructor, by > writing Type(args). That does not break encapsulation.
But it _does_ make it look like you're using a constructor when you're not, which I'm against regardless. In any case, std.container already declares a make which encapsulates constructing an object without caring whether it's a struct or class (since some containers are one and some another), which I intend to move to std.typecons and make work with all types. That seems a lot more useful to me than trying to make a function act like a constructor when it's not - though I guess that as long as you imported std.typecons, I would just be providing the free function that your little constructor faking scheme needs. - Jonathan M Davis