Declaration syntax
Ola Fosheim Grøstad" <ola.fosheim.grostad+dlang at gmail.com>
Ola Fosheim Grøstad" <ola.fosheim.grostad+dlang at gmail.com>
Wed Jan 8 08:56:03 PST 2014
On Wednesday, 8 January 2014 at 00:23:34 UTC, deed wrote:
> 1. Swap type and name. Like Go, but return type between
> function name and
> parameter list.
I find the Go swap to be less clear like "functionname(x,y,z
int)", but the swap with ":" is ok.
However, then you might as well create a separate type name space
starting with colon so that all types start with ":" and have a
single colon mean auto (kinda like Go):
x :int; // int x;
y := 2; // auto y = 2;
I think the basic advantage with the swap is to have the return
value after the the function parameter list:
add(x:int,y:int) :int
{}
sub(x:int,y:int) :int
{}
It is also more consistent with subclassing, an instance being a
special case of a type.
define :subclass:superclass{} // class subclass : superclass{}
anonclass_instance:superclass{...}(...)
etc.
This is particularly useful in a language like Beta where you can
inject code into the middle of the superclass:
define :dbaccess {
db :=dbopen();
INNER;
db.close();
}
define :dbtransaction:dbaccess{
db.begin();
INNER;
db.end();
}
define :updatedb:dbtransaction{
db.get(...);
db.put(...);
db.put(...);
INNER;
db.consistencycheck();
}
:updatedb{
db.put(...morestuff...)
}
> 2. Names come first, all other annotations after. ALWAYS.
Yep, or rather: more specific identifiers come first.
More information about the Digitalmars-d
mailing list