Hiding class pointers -- was it a good idea?

Jason House jason.james.house at gmail.com
Wed Aug 15 19:16:14 PDT 2007


Bill Baxter wrote:
> I'm starting to seriously wonder if it was a good idea to hide the 
> pointers to classes.  It seemed kinda neat when I was first using D that 
> I could avoid typing *s all the time.  But as time wears on it's 
> starting to seem more like a liability.


The simple distinction between reference types and value types has irked 
me from the very beginning.  As a programmer using something that 
somebody else wrote, I shouldn't have to know its storage type. 
Distinctions between the two pop up here and there throughout D code. 
For example, value_type[] and ref_type[] have completely different copy 
behaviors.


> 
> Bad points:
> - Harder to tell whether you're dealing with a pointer or not
>   (c.f. the common uninitialized 'MyObject obj;' bug)
> - To build on the stack, have to use 'scope'
> 
> Good points:
> + No need to type '*' everywhere when you use class objects
> + ??? anything else ???


I was thinking recently of an interesting syntax twist...  Always 
require & when trying to get to an address, and use the raw variable 
name and "." to refer to whatever is pointed to.  Obtaining an address 
would require &.

It's an interesting change, but would likely be too confusing to switch 
over.  Somehow I bet even suggesting the idea will mark me as a crack pot :)



More information about the Digitalmars-d mailing list