Omittable parens is an evil

Nick Sabalausky a at a.a
Sat Jul 19 12:01:07 PDT 2008


"Koroskin Denis" <2korden+dmd at gmail.com> wrote in message 
news:op.uejjwmv6n8fdl4 at korden...
> Sure, it's a handy feature for properties, but it is a source of too many 
> bugs. I think that it is against the D design of avoiding features that 
> are error-prone.
>
> Today I once again came across with a problem with them and it's still 
> open:
>
> class Test
> {
>    void test() {}
> }
>
> How do I get a mangle of Test.test?
>
> writefln(Test.test.mangleof);    // Should be ok, but prints v, which is 
> not what I need
> writefln((&Test.test).mangleof); // prints PFZv, which is a pointer to 
> function
> writefln(__traits(getMember, new Test(), "test").mangleof); // prints v 
> (void, return value)
>
> If you have other suggestions, please say, I need the solution. Custom 
> mangling is not an option.
>
> The following example was shown in bugzilla and it once again proves that 
> ommitable parens lead to errors:
>
> void main()
> {
>     int run()
>     {
>         // do the stuff
>         return 0;
>     }
>
>     Thread thread = new Thread(run);  // run -> &run, this(int) is called 
> instead of this(int delegate() dg).
> }
>
> Why not have special syntax for properties, like:
>
> class Array(T)
> {
>    property T* ptr()
>    {
>       return _ptr;
>    }
>
>    property int length()
>    {
>        return _length;
>    }
>
>    void resize(int newSize)
>    {
>        // code here
>    }
>
>    int capacity()
>    {
>        // code here
>    }
>
>    private int _length;
>    private T*  _ptr;
> }
>
> Usage:
> Array!(int) array = new Array!(int);
> int len = array.length;
> array.resize = 100;       // forbidden
> int capacity = array.capacity(); // okay
>
> It is a breaking change, sure, but it solves the design flaw and fix is 
> trivial.

I'm not sure if I'm completely following you here. Are you basically saying 
that being able to call function foo by shortening "foo();" into "foo;" 
confuses the issue of whether you're referring to the function itself or 
actually trying to invoke it?

If so, then 1. I should pay more attention because I didn't realize you 
could do that ;). And 2. I agree.





More information about the Digitalmars-d mailing list