Transitive const sucks
Walter Bright
newshound1 at digitalmars.com
Wed Sep 12 11:39:27 PDT 2007
Steven Schveighoffer wrote:
> "Walter Bright" <newshound1 at digitalmars.com> wrote in message
>> 1) Make functional style programming possible, which will become extremely
>> important as people will start using all those lovely cores.
>
> How does making const transitive allow for functional programming? From
> what I understand (and that's not much) about functional programming, it's
> programming without side effects. Consider:
Although const is necessary for f.p., it is not sufficient for f.p., as
your example illustrates.
> I think in order to allow functional programming, you need to introduce a
> new type of const, for example fconst. If a function is declared fconst, it
> is not allowed to change any data that is not local to the function, or call
> a non-fconst function, or to read non-fconst data. If a piece of data is
> declared fconst, it cannot be changed.
The thought is to declare a function as 'pure'.
>> 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.
>> 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
More information about the Digitalmars-d
mailing list