Unofficial wish list status.(Jul 2008)

Sean Kelly sean at invisibleduck.org
Tue Jul 22 14:02:55 PDT 2008


Walter Bright wrote:
> Jason House wrote:
>> Walter Bright Wrote:
>>
>>> Jason House wrote:
>>>> By far, my biggest complaint is that the const system makes only
>>>> one of the following two methods compile.  It forces programmers
>>>> to settle for using global variables to bypass const
>>>> restrictions.  It also touches upon why the purity is required
>>>> when doing multithreading.  I can't fully embrace const until it
>>>> stops encouraging global variables and the gap between purity and
>>>> const is reduced/eliminated.
>>>>
>>>> =============
>>> logFile log; class foo{ void bar() invariant{
>>>> log.write("Hello World"); } } ============= class Foo{ logFile
>>>> log; void bar() invariant{ log.write("Hello World"); } }
>>>> =============
>>> But the bar() function is not invariant,
>>
>> That depends on which version of bar you're talking about.  The first
>> bar conforms to the current D standard for invariance.  Everything in
>> class foo remains untouched in the first example, and so bar is
>> invariant.
> 
> True, but it is not pure. Pure functions cannot change global state.

The current definition of pure goes even farther than that.  Because 
arguments to pure functions must be invariant (as far as I know), pure 
functions may not accept parameters that could be changed by another thread.

> These concepts are not simple, but there is no way to support shared 
> state in multithreaded programming without understanding those concepts. 
> C++ the language has no concept of these things, and people get into 
> endless trouble with it when misunderstanding things and screwing it up. 
> The C++ language itself is of NO help at all. With D, the idea is to 
> enable the language to help by moving things from convention to law. 
> Completely ignoring the issues, like C++ does, is no solution.

So will D have some way to require that references passed between 
threads must be either invariant or represent a transferral of 
ownership?  I think that's the crux of the issue.  Using invariance for 
non-shared data is typically more for simplifying error recovery than 
anything else.


Sean



More information about the Digitalmars-d mailing list