Why not?

dsimcha dsimcha at yahoo.com
Sun Nov 29 07:11:43 PST 2009


== Quote from Uriel (uriel at inbox.ru)'s article
> Lets consider following code:
> class Foo {
>    private Foo[] m_SomeData;
>    public this(int a, double b, string c) {}
>    public Foo append(Foo obj) {
>      m_SomeData ~= obj;
>      return this;
>    }
> }
> void foo(Foo obj) {}
> void main() {
>    foo(1, 1.0, "1");
>    Foo obj = new Foo();
>    obj.append(1, 1.0, "1").append(2, 2.0, "2");
> }
> Why not to do implicitly cast of these three parameters to new Foo
> object. We know that bar should recieve a Foo object and we have a call
> with parameters which exactly match one of Foo's constructors. It could
> be a nice syntactic sugar though not very hard to implement I think.

It's gratuitous complexity.  Anytime you add complexity to the language, it should
have to remove enough complexity from user code to justify the complication of the
language.  IMHO the amount of complexity added to the language here would be
orders of magnitude less than the amount removed from user code.



More information about the Digitalmars-d mailing list