Transitive const sucks

Steven Schveighoffer schveiguy at yahoo.com
Wed Sep 12 12:14:24 PDT 2007


"Walter Bright" wrote
> Steven Schveighoffer wrote:

> Although const is necessary for f.p., it is not sufficient for f.p., as 
> your example illustrates.

>
> The thought is to declare a function as 'pure'.

OK, but why not allow BOTH logical const and transitive const?  What if 
const exists as it does, except the mutable keyword overrides it?  As long 
as pure functions can only call other pure functions and use const basic 
types, then isn't f.p. still possible?  You could even use const types that 
have mutable parts as long as you are only calling pure functions on those 
types (as those wouldn't be able to access the mutable piece).

>
>
>>> 3) Be able to treat invariant references as value types. This, for 
>>> example, makes manipulating strings as easy as manipulating ints.
>>
>> I don't understand this, perhaps someone can explain it further.  An 
>> example of how this helps would be good.
>
> Strings in, say, Perl or Basic "just work". Just like integers "just work" 
> in C. Nobody ever gives a thought to them inadvertently changing value.
>
> But strings in C, everybody worries about them changing value, and such is 
> a major source of bugs.

I understand why it is good to have strings immutable, as I've used Java 
quite a bit.
But how does transitive const guarantee that a string's value won't change? 
Don't you just need immutable strings?

What I was looking for is:

example = ???
without transitive const:
life sucks in this example because you can't do ...
with transitive const:
life is better because now I can do ...

>
>>> 4) Makes COW programming checkable and enforceable. (COW programming is 
>>> an important part of many styles of programming.) Without transitive 
>>> const, COW is overly reliant on programmer discipline.
>>
>> All I can find on the net about COW programming is the COW programming 
>> language.  I'm sure this isn't what you meant :)  can you please explain 
>> this further?
>
> copy-on-write

ok, so you are saying that with transitive const, this is enforceable, by 
the compiler I'm assuming.  Give me an example of how having transitive 
const makes COW enforceable by the compiler and doesn't rely on the 
programmer.  I understand much better with examples rather than abstract 
arguments if you notice :)

-Steve 





More information about the Digitalmars-d mailing list