const(FAQ)

Walter Bright newshound1 at digitalmars.com
Sat Mar 29 02:22:52 PDT 2008


Leandro Lucarella wrote:
> Walter Bright, el 28 de marzo a las 15:33 me escribiste:
>> The same questions about const come up repeatedly, so I decided that it was past time to put up a FAQ dedicated to const. The initial version is far from 
>> complete, but it's a start.
>>
>> http://www.digitalmars.com/d/2.0/const-faq.html
> 
> About "Why aren't function parameters const by default?":
> 
> Why aren't *all* variables const by default?

Because you'd have to throw out half of the existing D code base. It 
also doesn't buy you that much, after all, it isn't hard to get into the 
habit of:
	const x = 3;
rather than:
	int x = 3;

> It was discussed a long time ago and AFAIK most people liked it.
> 
> And about "Why not use readonly to mean read only view?":
> 
> Why not use view to mean read only view?
> 
> As discussed recently? I don't think "because it's not that clear that
> 'view' means 'read only view'" is a good enough reason for changing the
> const meaning to make it mean 'read only view'. If words are arbitrary, at
> least this scheme let you keep the old const meaning...

The D 1.0 const was just a storage class, not a type modifier. It still 
is a storage class, and:
	const int x = 3;
still work with 1.0 and 2.0.



More information about the Digitalmars-d mailing list