[Proposal] Make lock object optional #2614
Replies: 4 comments
-
How would the compiler know where that lock object should be declared? Should it be instance or static? How can you share it between multiple methods? I assume you couldn't. The clarity of the scope of the lock object is just as important as the lock itself and I don't think the compiler should hide it. |
Beta Was this translation helpful? Give feedback.
-
As I said, that would be for 90% cases where you don't need to share "lock object". How broad scope should be, and if it should be instance or static, could be adjusted to most common scenario. This is not trying to replace standard |
Beta Was this translation helpful? Give feedback.
-
What is that "common scenario"? What if that changes? At worst if you're required to declare the lock object you have to type a little extra code once. |
Beta Was this translation helpful? Give feedback.
-
@HaloFour most common is |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Background
Everytime we create
lock
block, we need to provide "lock object". It allows declaring multiplelock
blocks as related. In majority of cases we use it only for singlelock
block.Proposal
I suggest making
(_obj)
optional. If not provided, compiler will generate one for us. That will makelock
cleaner.Alternative
Now developers needs to add "lock object" in each statement:
That requires more typing and pollutes source code. It also creates possibility of bugs, if not used correctly.
Beta Was this translation helpful? Give feedback.
All reactions