D const design rationale

Daniel Keep daniel.keep.lists at gmail.com
Fri Jun 22 08:27:29 PDT 2007



Frits van Bommel wrote:
> Leandro Lucarella wrote:
>> Walter Bright, el 22 de junio a las 01:07 me escribiste:
>>> Sean Kelly wrote:
>>>> Walter Bright wrote:
>>>>> http://www.digitalmars.com/d/const.html
>>>> So in short, 'const' protects data and 'final' freezes references. 
>>>> How do these two apply to an int declaration?
>>>>    const final int x = 5;
>>>> Is either a compiler error? are they synonyms in this case?
>>> It's not an error, it's just redundant.
>>
>> Shouldn't be better to be an error? So it's more clear that final makes
>> sense only for reference types.
> 
> Allowing it allows cleaner generic code, otherwise templates would often
> have to check whether parameters were value or reference types.

Indeed; we already need to special-case functions that return void.  "It
can't be *that* bad!"  In some cases, it means an entire template has to
be duplicated *just* for the void case.  I had to do this for a
coroutine implementation, and was not happy about it.

	-- Daniel



More information about the Digitalmars-d mailing list