What purpose to const besides functional programming?

Don nospam at nospam.com.au
Wed Jul 23 08:54:36 PDT 2008


Fawzi Mohamed wrote:
> On 2008-07-23 17:30:48 +0200, Jason House <jason.james.house at gmail.com> 
> said:
> 
>> superdan Wrote:
>>
>>> Jason House Wrote:
>>>
>>>> Walter Bright Wrote:
>>>>> 5. Invariant data does not have to be synchronized to be multithread
>>>>> accessible.
>>>>
>>>> #5 is not true.  Invariant functions require synchronization because 
>>>> they can manipulate global state.  If #5 is restricted to direct 
>>>> data access without using properties or member functions, then I'd 
>>>> agree with it.  Of course, that qualification eliminates most of the 
>>>> benefit from #5. notice how walter says "data" and you say 
>>>> "function" and you'll pretty much have understood where the problem 
>>>> in your reasoning was.
>>>
>>> of course #5 is true. looks like there was and still is a basic 
>>> misunderstanding of data vs. function behavior with regard to 
>>> immutability.
>>>
>>> don't confuse data with functions. invariant data -> can't modify it 
>>> even with the sas. that means no synchronization on data necessary. 
>>> invariant function -> applies to invariant object and may or may not 
>>> require synchronization. but sure as shit invariant data does not 
>>> need synchronization.
>>
>>
>> All of my posts on this topic are about invariant functions rather 
>> than invariant data.  Walter's response focused more on invariant 
>> data, and I'm intentionally trying to draw the distinction in what 
>> we're talking about.
>>
>> I want to shift the discussion away from discussing purely invariant 
>> data and instead discuss the functions to access the data.  Proper 
>> object oriented programming requires using functions, so any proper 
>> analysis of a const system must include analyzing how functions are 
>> handled.
> 
> the functions connected to invariant data are pure functions, invariant 
> functions are just functions with an invariant argument (this), see 
> Steven's reply to you in the other thread.

But when does that happen? Seems to me that it can only happen if the 
class it is part of contains only invariant data. Which seems really 
obscure. Any _member_ which is invariant is presumably declared 
invariant anyway. Can anyone come up with a use case?




More information about the Digitalmars-d mailing list