Operator precedence of "new"

Michel Fortin michel.fortin at michelf.com
Fri Oct 15 05:37:09 PDT 2010


On 2010-10-15 08:12:24 -0400, bearophile <bearophileHUGS at lycos.com> said:

> Currently to call a method to a newly build object/struct you need:
> 
> (new Foo).bar();
> 
> But isn't it better to change the D operator precedence rules a bit and 
> allow new to bind more closely than the method call, to allow a syntax 
> like:
> 
> new Foo.bar();
> 
> Do you see bad side effects in this D2 change?

But then, how does that work?

	new Foo.SubType.bar();

Could work like this:

	new (Foo.Subtype).bar();

which doesn't look too bad as long as .bar() is at the end. Remove it 
and you'll get this:

	new (Foo.Subtype);

Hardly interesting, and somewhat counter-intuitive. That's especially 
bad considering that all types are in reality enclosed module name 
which can be made explicit:

	new (std.stdio.File);

I much prefer that this works:

	new std.stdio.File;
	new Foo.Subtype;

Even if it means I have to do:

	(new Foo).bar();

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/



More information about the Digitalmars-d-learn mailing list