www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: const member function synatx?

reply renoX <renosky free.fr> writes:
im Wrote:

 I read the page: http://www.digitalmars.com/d/2.0/const3.html
 under section "Const Member Functions"
 
 It didn't give any example, but following the example of 'invariant', it
 should be:
 
 const ReturnType memberFunc(param) {}
 
 I think this is really confusing: is 'const' trying to specify the
 'ReturnType' or the memberFunc?

As often, this is because C's syntax for variable or prototype declaration suck.. If D used Limbo and Scala syntax for this <function name>(<parameters>):<return value> then there would be no ambiguity: const memberFunc(param): ReturnType {} memberFunc(param): const ReturnType {} const memberFunc(param): const ReturnType {} Walter has chosen an inferior syntax in the name of programmers familiarity, this is unlikely to change.. renoX
Mar 05 2008
parent Moritz Warning <moritzwarning _nospam_web.de> writes:
On Wed, 05 Mar 2008 05:40:32 -0500, renoX wrote:

 im Wrote:

 
 If D used Limbo and Scala syntax for this <function
 name>(<parameters>):<return value> then there would be no ambiguity:
 const memberFunc(param): ReturnType {} memberFunc(param): const
 ReturnType {} const memberFunc(param): const ReturnType {}
 
 Walter has chosen an inferior syntax in the name of programmers
 familiarity, this is unlikely to change..
 
 renoX

That syntax would be nicer indeed. We may be able to omit the void return type this way: "print()" instead of "void print()" I personally prefer to move the return type into the function header, but that's another pile of issues.
Mar 07 2008