Synchronized classes have no public members

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Fri Oct 16 14:54:09 PDT 2015


On Friday, 16 October 2015 at 18:50:20 UTC, Jacob Carlborg wrote:
> On 2015-10-16 16:07, Dicebot wrote:
>
>> That would be really bold thing to do, I don't think anyone
>> realistically proposes that. At most I'd suggest to explicitly 
>> mark it
>> in spec / documentation as legacy and unidiomatic feature with 
>> no
>> deprecation. Removing it does no benefit at this point (even 
>> if I
>> believe it shouldn't have been there from the very start)
>
> Ok, cool. DWT doesn't use synchronized classes so I don't 
> really care :)

Well, you probably will at some point, even if you don't know. 
According to TDPL, there's not supposed to be any such thing as a 
class with some functions which are synchronized and some not. 
The entire class is synchronized or none of it is, and if the 
class is synchronized then the member variables of the class are 
not accessible outside of the class. But that hasn't been 
implemented yet. Instead, we have synchronized functions like in 
Java. The PR that this thread is about makes it so that the 
member variables aren't accessible outside of the class, which 
probably won't cause DWT any problems, since public member 
variables are generally a bad idea. However, if this PR (or a 
future PR) actually finishes implementing synchronized classes (I 
don't know how far this PR actually goes), then any classes that 
DWT has which have any synchronized functions would then have to 
be synchronized classes. So, while the current PR may not break 
DWT, odds are that at some point in the future, synchronized 
classes will be finished, and DWT will probably break. It 
wouldn't surprise me if fixing it were fairly easy - particularly 
if DWT tends to synchronize all of the functions in a class when 
it synchronizes any of them - but at bare minimum, you're 
probably going to have to move the synchronized keyword from the 
function declarations to the class declaration, and it's possible 
that some of the implementation will have to change to cope with 
the fact that it's then not legal to have some functions in a 
class synchronized while others aren't.

- Jonathan M Davis


More information about the Digitalmars-d mailing list