Stick a fork in it
janderson
askme at me.com
Wed May 9 21:31:13 PDT 2007
Bill Baxter wrote:
> Chris Miller wrote:
>> On Wed, 09 May 2007 14:56:14 -0400, Walter Bright
>> <newshound1 at digitalmars.com> wrote:
>>
>>> I'm currently working on implementing const/invariant. It's becoming
>>> clear that this is a pervasive change, and will cause binary
>>> incompatibility with existing code. I'm trying to minimize any source
>>> incompatibilities.
>>>
>>> The first few iterations of const support probably will have lots of
>>> problems before it gets usable.
>>>
>>> This means that dmd will have to fork into a 1.x maintenance version
>>> and a 2.x beta.
>>
>>
>> Well, hooray...
>>
>> But I wonder about this const stuff. I remember a song similar to
>> "here a const, there a final, everywhere an invariant final" ;)
>
>
> That't the observation that leads one to start thinking about making
> const the default in places where it makes sense. Like on reference
> parameters to functions. Rather than having to explicitly declare "hey
> I'm not going to modify this data" you only have to explicitly declare
> the "hey I AM going to modify this data" case.
>
> I really don't know if it would end up being a net gain. But it seems
> appealing. The nice thing is that with C++ const arguments, if you
> write a function foo() that doesn't modify its arguments, but forget to
> mark the args as const, it's often some OTHER programmer who discovers
> that fact, because you might never try to call foo with a const param in
> your program. But the poor other programmer who discovers it has to
> figure out whether to modify your code, or try to get you to fix it, or
> submit a patch or whatever, or const cast.
>
> But with const default, if you forget to specify foo's arguments as
> mutable and you start trying to modify them in the function you're going
> to find out right away, when you're writing foo, not some time later
> when you try to call foo.
>
> --bb
I think that's a good idea.
More information about the Digitalmars-d-announce
mailing list