#316 Construction call syntax

brian Fri 25 Jul 2008

I've implemented the shorthand, Python-style construction calling syntax based on the previous proposal. This feature is orthogonal to the construction/with-block issues, which I'm not ready to tackle since an elegant solution seems elusive.

This particular change is just for the shorthand sugar to omit explicitly calling make:

ArgErr.make("bad arg")  // longhand
ArgErr("bad arg")       // shorthand

The new syntax rocks! Since it is convention, I've updated the entire codebase to use it. I think the shorthand syntax really removes a lot of noise from the code, especially with exceptions.

The updated section in the Methods chapter:

Construction Calls

Fan supports a special syntax called construction calls with the syntax Type(args). These calls are resolved as follows:

  1. bind to Type.fromStr if there is exactly one Str argument and Type.fromStr exists (see simple literals)
  2. otherwise bind to Type.make

The construction operator works on static methods or constructors. So you can use it when make is a constructor or when make is a factory method. The method of construction call Foo(...) must return Foo.

Convention is to always prefer a construction call to using make explicitly:

ArgErr.make   // non-preferred
ArgErr()      // preferred

ArgErr.make("bad arg")   // non-preferred
ArgErr("bad arg")        // preferred

tompalmer Fri 25 Jul 2008

Great news.

alexlamsl Fri 25 Jul 2008

I think we all have concensus on this part of the discussion ;-)

Login or Signup to reply.