const sucks

Bill Baxter wbaxter at gmail.com
Sun Oct 19 14:00:22 PDT 2008


On Mon, Oct 20, 2008 at 5:50 AM, Derek Parnell <derek at psych.ward> wrote:
> On Sat, 18 Oct 2008 20:36:51 -0700, Walter Bright wrote:
>
>> The problem is things like:
>>
>>    void foo(int[] a)
>>    {
>>      int[] b;
>>    }
>>
>> so a is const, and b is mutable? That's very confusing. It gives the
>> appearance of D having a lot of wacky and arbitrary semantic rules.
>
> I work with the Euphoria language and this has been the case since its
> begining. No one, from newbie-coder to experienced coders of a number of
> languages have EVER thought this as weird.
>
> In Euphoria, there is NO WAY one can change a function's argument. The
> caller of a function can have complete confidence that any argument passed
> will not have its value changed by the function. However, variables local
> to the function are not immutable.
>
> Your fears may need empirical evidence before I would take them seriously.

Yeh, and on the other side, I remember way back when I was learning C
as a newbie that I found it was surprising that parameters acted just
like local variables.  When you think about it, yeh, they are
basically, but as a newbie the thought never occurred to me that they
were (or should be) the same thing.

Even now in D what you can do with them is different.  You can only
have 'in' or 'ref' on parameters, not on local variables.  So I too
think more evidence is needed that such a change will make code
confusing.

--bb



More information about the Digitalmars-d mailing list