keywords "objconst" and "objimmutable" vs. const(Object) ref

Michel Fortin michel.fortin at michelf.com
Wed May 18 07:10:43 PDT 2011


On 2011-05-17 23:48:35 -0400, Andrej Mitrovic 
<andrej.mitrovich at gmail.com> said:

> So how do functions which take such a parameter look like?

What do you mean by what they'll look like? They'll look like how you 
wrote them. I'm not sure I understand the question... but I'll still 
try to answer.


> void bar(ref Foo a, const(Foo) ref b) { }
> 
> void bar(ref Foo a, ref const(Foo) b) { }

With my patch, assuming Foo is a class, the above is the same thing as:

	void bar(ref Foo ref a, const(Foo) ref b) { }

	void bar(ref Foo ref a, ref const(Foo ref) b) { }

The postfix "ref" represents the object's rebindable reference, while 
the prefix "ref" is a non-rebindable reference to that object reference.

I'm aware that using "ref" both for variable reference and object 
reference can look a little confusing at times. Changing the postfix 
"ref" for another symbol would help make things clearer. That said, 
given that most of the time you don't have to write the "ref" part -- 
as it is implicit -- I'm not sure it is worth spending a new character 
token for it either.

 - - -

Also, I usually prefer to stick the postfix "ref" to the closing 
parenthesis, no space in between, like this:

	const(Foo)ref

It does not matter at all when parsing, but I find that this way I'm 
more inclined to see the ref as part of the type rather than some kind 
of separate attribute. Of course you have to leave the space when there 
is no attribute and no parenthesis (as in "Foo ref"), but for those 
cases I just drop the "ref" because it's implicit anyway.

This is just my personal style.


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



More information about the Digitalmars-d mailing list