www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18985] New: shared variable of user-defined type with

https://issues.dlang.org/show_bug.cgi?id=18985

          Issue ID: 18985
           Summary: shared variable of user-defined type with opOpAssign
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: black80 bk.ru

Created attachment 1705
  --> https://issues.dlang.org/attachment.cgi?id=1705&action=edit
for 3) point

class Some {
        static immutable Some One = new immutable Some();
        auto opOpAssign( op )( Some val ) { writefln( "Some.op" ~ op ); }
}
auto var = new shared Some();
var += Some.One;
// and we'v got here: Error: read-modify-write operations are not allowed for
`shared` variables. Use `core.atomic.atomicOp!"+="(var, One)` instead.

1) this error should be a warning only, cause not a beginners usually know what
they do. and compiler should allow  to do what they want. it shouldn't be
taboo. just say your disagreement and compile code. (and should exist
possibility disable warning)
compiler shouldn't say "no!" in negotiation with people in case when it still
can to compile fucking code

2) this error is stupid cause we can't use atomicOp for user defined type (in
most cases)

3) "shared" keyword is stupid thing in D. 
it should be used for only one thing - tell compiler to store variable NOT in
TLS.
imagine Event(R,Args...) with +=/-= ops. usually it should be shared variables
with synchronized methods(that automatically became shared. WTF?). when u try
to use this event dmd raised many errors about I can't use usual delegate for
op+= with shared variable. when one thing shared compiler tells that all things
should be shared. crazy. it's like falling dominos - compiler don't allow write
program that works in another language. 
too smart compiler is calamity.
attachment has some Event implementation try to compile
auto evt = new /*SHARED*/ Event!(void, string)();
evt += delegate void(string s) { writeln( s ); }
and hello dozen errors

4) synchronized method(became shared) differ from methods with 
auto meth(...) { synchronized( this ) { ... } }
meaning is same but behavior is not same - WTF? 
context for shared method is very different and we have many errors for
nothing.
well, it's still stupid "shared"

5) offtopic: but another stupid thing with too smart compiler
(string s) => s.length which means int function(string)
(string s) => { return s.length; } which means int delegate() function(string)
well, it looks same BUT in D this is not same
I can't imagine where I need lambda that return lambda BUT I can ask compiler
for that by myself
(string s) => { return () => s.length; } that's all! return to me delegate! I
want it!
why compiler do work that I didn't ask him?
why people should to remember when u use "=>" with "{" and "return }" u will
get another implicit lambda?

meaningless style?

image about good and bad code (well, my Event maybe too many WTF for u too, but
u ask me to fight with compiler not to friend with him)
https://i2.wp.com/commadot.com/wp-content/uploads/2009/02/wtf.png?resize=550%2C433

--
Jun 13 2018