
26 Jul
2004
26 Jul
'04
11:27 a.m.
David Abrahams wrote:
"Peter Dimov" <pdimov@mmltd.net> writes:
I prefer to be able to name the lock variable 'lock' instead of 'lk'.
Suit yourself, but I think variable names should denote roles, not types.
Hm. What is it that makes 'lock' not qualify as a role?
Well, OK, it's a role at a very low level of abstraction. Something more like "access_foo" for some mutex-protected resource "foo" might be better.
Compare: lock lk( m ); // the original examples with scoped_lock lock( m ); Or the role-based variation: lock access_foo( foo_mutex ); with scoped_lock foo_lock( foo_mutex ); Same but unnamed (because you won't be touching the lock afterwards): lock access( foo_mutex ); vs scoped_lock lock( foo_mutex );