Lock statement in C#, Is there an equivalent in VB.NET?

  • Thread starter Thread starter ThunderMusic
  • Start date Start date
T

ThunderMusic

Hi,
The subject says it all. Is there an equivalent, in VB.NET, for the C#
statement Lock(Object){}

Thanks

ThunderMusic
 
Once again the VB.NET designers felt it necessary to use more letter than
necessary in their keywords. :-)
 
Peter Rilling said:
Once again the VB.NET designers felt it necessary to use more letter than
necessary in their keywords. :-)

Not really. 'Lock' is far too generic to be self-descriptive.
 
Thats a matter of taste. By using longer and almost always more descriptive
keywords and variable names, VB programs tend to require less line by line
documentation. Both languages still need docs on a program's theory of
operations, but VB requires less line by line stuff.

I also program in C++, so I do have the background to compare the BASIC and
C languages and their descendents.

Mike Ober.

Peter Rilling said:
Once again the VB.NET designers felt it necessary to use more letter than
necessary in their keywords. :-)
 
Not to mention that "Lock" was a keyword in VB.Classic (and B.A.S.I.C. going
back to the old days) as part of the "Open file For..." as well as a
standalone statement in VB.Classic (Lock #filenum) and a now function in
VB.NET.
 
Peter,
Once again the VB.NET designers felt it necessary to use more letter than
necessary in their keywords. :-)
Do you now understand why there is in VBNet less need for XML or other
documentation.

I hate to read those C# programs with for every line of code 5 lines of
documentation.

Cor
 
Michael D. Ober said:
Thats a matter of taste. By using longer and almost always more descriptive
keywords and variable names, VB programs tend to require less line by line
documentation. Both languages still need docs on a program's theory of
operations, but VB requires less line by line stuff.

If one requires line-by-line documentation in C# for the basics of the
language, the code can't be very good.

I only write documentation inside methods to give a general overview of
what's happening in a section (which often leads to refactoring of that
section into its own method) or if a statement is clear in terms of
what it's doing at a low level, but not in terms of its overall effect.

Neither of these would be reduced by using a more verbose language.
 
Do you now understand why there is in VBNet less need for XML or other
documentation.

Absolutely not. When you're calling a method, you still need to know
what it's going to do, preferrably without having to look at the method
implementation.
I hate to read those C# programs with for every line of code 5 lines of
documentation.

So would I - because that's clearly badly written code. See my response
to Mike for more details.
 
Jon Skeet said:
Absolutely not. When you're calling a method, you still need to know
what it's going to do, preferrably without having to look at the method
implementation.

I agree with you. XML documentation is especially important when selling
class libraries and writing reusable code.
So would I - because that's clearly badly written code. See my response
to Mike for more details.

ACK. However, I still think that 'SyncLock' is more self-descriptive and
thus a better choice than 'lock'.
 
Herfried K. Wagner said:
ACK. However, I still think that 'SyncLock' is more self-descriptive and
thus a better choice than 'lock'.

To be honest, I don't think there's a lot of ambiguity in either case.
One thing I have against "lock" is that it would often be my choice of
name for a variable used for locking purposes.

Then again, I'd prefer it if there were no keyword at all, and "using"
statements were used instead, giving a much more flexible framework.
See http://www.pobox.com/~skeet/csharp/miscutil/usage/locking.html for
more...
 
Back
Top