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

Jesse Phillips jessekphillips+D at gmail.com
Tue May 17 18:26:38 PDT 2011


Christopher the Magnificent Wrote:

> Greetings all.  First time poster here.
> 
> By way of introduction, my name is Christopher.  I've been fascinated 
> with D for a few years now.  My main programming language has been 
> Python, but I have used and studied many programming languages to some 
> extent.  I love to design things, like houses, pipe organs, and even 
> computer languages.

Hello, and welcome.

> Now I understand that another syntax has been nominated to do this job 
> which is the const(Object)ref syntax.  I dislike that syntax because 
> "const(Object)" means a constant variable referencing a constant data 
> structure, and "const(Object)ref" LOOKS like it should be a reference to 
> a variable of type "const(Object)" -- to me it suggests a variable 
> referencing a constant variable referencing a constant data structure. 
> "const(Object)ref" suggests TWO levels of pointers, but that is not the 
> meaning being ascribed thereunto.

Syntax has definitely been a major problem for this feature. Walter's stance has been that he has tried many times to get the semantics and syntax to work and has given up. michelf (Sorry don't know his real name) has created a branch which implements the syntax you are against. As this is a change Walter is skeptical of it will take time to review.

Now as for your distaste, I believe the intent is to make a valid declaration:

Object ref foobar;

Meaning that you are exposing the reference or address itself. However I think there might be more to it when considering generic code which would suggest these should also be valid forms:

void function(T)(const(T) ref thing);

const(int) ref foo;
const(myStruct) ref bar;
const(int*) ref bared;

But that would suggest D has a reference type, and it doesn't. So in any case, this isn't simple and I'm not really sure how well const(Object) ref stands up to this kind of question.


More information about the Digitalmars-d mailing list