any news on const/invariant?

Derek Parnell derek at psych.ward
Tue Nov 27 13:25:28 PST 2007


On Tue, 27 Nov 2007 12:12:51 +0100, 0ffh wrote:

> Derek Parnell wrote:
>> On Tue, 27 Nov 2007 07:47:45 +0100, Tomas Lindquist Olsen wrote: [...] I
>> think that Walter is saying that he (currently), after much thought and 
>> deliberation, has decided that there is no benefit to any coder in 
>> implementing the head const paradigm in D. Therefore those unfortunates 
>> such as myself, that can't yet grasp why there is no benefit, may feel 
>> obliged to continue asking for an explanation or assistance about how we
>>  could implement head const without the compiler helping us.
> 
> Well, I don't quite see your problem with assert. Earlier you said:
> 
>> Okay, I get it. We don't actually need const/invariant at all. Instead
>> we just sprinkle our code with asserts to catch these compile-time
>> errors at run-time. Neat.
> 
> I think you forget (or ignore) something elemental here, which is that
> runtime not equals runtime, and that you'll use you asserts only to make
> sure at "test/debug"-runtime that you (and all of your co-workers) didn't
> fup it. 

Neither did I forget nor ignore. My 'assert' comment was a (poor) example
of sarcasm. I didn't really mean it. I just said it as an extreme statement
to highlight that I thought it was a idea not worthy of further
consideration.

> I postulate that even with head const available, you'll still have
> to test your software. Or do you go "Ah, finally it compiles! Call in the
> delivery boy!"?

And why do you assume that I think otherwise?

>  I think the difference is not so grand as you make it.

I do not think it as "so grand", whatever that means. 

My point is that any help that a compiler can give to the coder in
preventing coding errors is a worthwhile pursuit. Sure, there are
diminishing returns and maybe this is one of them. I'm not sure because I
have not analyzed any empirical statistics.

I am simply saying, and this seems to be very hard to get across, that if
there is some syntax to express the design concept of "the pointer may not
be modified but the items pointed to can be", then the compiler can detect
at compile time when the coder attempts to change the pointer, and issue
the appropriate warning.

A compiler exists to make life easier for the coder.

If this truely is a case where "Head const turned out to be an
unexplainable, incomprehensible feature." and/or is too hard to implement,
then I'll go with the flow. I haven't seen evidence of that being the case
yet, regardless of Walter's statements so far.

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell



More information about the Digitalmars-d mailing list