Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

Not repeating what 1201ProgramAlarm reported.


std::mutex m_lock; // reader writer lock, multiple getters are allowed

I see a regular exclusive lock, not a reader/writer lock.

std::lock_guard<std::mutex> gaurd(m_lock);

Not taking advantage of class template argument deduction? This is a case where I really want it. (If not, use an alias for the lock type so it can be easily changed.)

std::lock_guard guard(m_lock);

 m_lruList{},
 m_lruMap{},
 m_lock{}

Just adds noise — is that a thing someone actually recommends? I would say don’t list all the things that are taken care of on their own.

 for (const auto &node : m_lruList)
 std::cout << node._key << std::endl;

The style in C++ is to put the * or & with the type, not the identifier. This is called out specifically near the beginning of Stroustrup’s first book, and is an intentional difference from C style.

Some people criticize the leading underscore of identifiers as a style. I point out that it is easy to clash with compiler-supplied identifiers and you must remember to never use a capital letter after the score, so it is a hazard.


#Update

Update

#ifndef LRUCache_h__

Any name containing a double underscore is reserved for use by the implementation.


/***
 * Method: objcache::LRUCache::LRUCache
 * Access: public 
 * Description: This creates a cache of given size. 
 */

Banner comments like this just get in the way of reading the code. Repeating the function name in a comment just before its definition does what exactly? (Oh, and a point of nomenclature: C++ does not have "methods".) Nobody comments each function as being public or private. For the description, don’t prefix it with "Description:"; just describe it.

Since I can see name of the argument is size and see how it’s used on the on the following line

LRUCache(size_t size) :
 m_cacheSize{ size },

a comment saying

// This creates a cache of given size

is useless. It only repeats what is in the signature: A constructor creates an instance of this class, and this one takes a size.

See (⧺P.1). You might also find this useful (Comments starts on page 17; material originally published in 1992).

Not repeating what 1201ProgramAlarm reported.


std::mutex m_lock; // reader writer lock, multiple getters are allowed

I see a regular exclusive lock, not a reader/writer lock.

std::lock_guard<std::mutex> gaurd(m_lock);

Not taking advantage of class template argument deduction? This is a case where I really want it. (If not, use an alias for the lock type so it can be easily changed.)

std::lock_guard guard(m_lock);

 m_lruList{},
 m_lruMap{},
 m_lock{}

Just adds noise — is that a thing someone actually recommends? I would say don’t list all the things that are taken care of on their own.

 for (const auto &node : m_lruList)
 std::cout << node._key << std::endl;

The style in C++ is to put the * or & with the type, not the identifier. This is called out specifically near the beginning of Stroustrup’s first book, and is an intentional difference from C style.

Some people criticize the leading underscore of identifiers as a style. I point out that it is easy to clash with compiler-supplied identifiers and you must remember to never use a capital letter after the score, so it is a hazard.


#Update

#ifndef LRUCache_h__

Any name containing a double underscore is reserved for use by the implementation.


/***
 * Method: objcache::LRUCache::LRUCache
 * Access: public 
 * Description: This creates a cache of given size. 
 */

Banner comments like this just get in the way of reading the code. Repeating the function name in a comment just before its definition does what exactly? (Oh, and a point of nomenclature: C++ does not have "methods".) Nobody comments each function as being public or private. For the description, don’t prefix it with "Description:"; just describe it.

Since I can see name of the argument is size and see how it’s used on the on the following line

LRUCache(size_t size) :
 m_cacheSize{ size },

a comment saying

// This creates a cache of given size

is useless. It only repeats what is in the signature: A constructor creates an instance of this class, and this one takes a size.

See (⧺P.1). You might also find this useful (Comments starts on page 17; material originally published in 1992).

Not repeating what 1201ProgramAlarm reported.


std::mutex m_lock; // reader writer lock, multiple getters are allowed

I see a regular exclusive lock, not a reader/writer lock.

std::lock_guard<std::mutex> gaurd(m_lock);

Not taking advantage of class template argument deduction? This is a case where I really want it. (If not, use an alias for the lock type so it can be easily changed.)

std::lock_guard guard(m_lock);

 m_lruList{},
 m_lruMap{},
 m_lock{}

Just adds noise — is that a thing someone actually recommends? I would say don’t list all the things that are taken care of on their own.

 for (const auto &node : m_lruList)
 std::cout << node._key << std::endl;

The style in C++ is to put the * or & with the type, not the identifier. This is called out specifically near the beginning of Stroustrup’s first book, and is an intentional difference from C style.

Some people criticize the leading underscore of identifiers as a style. I point out that it is easy to clash with compiler-supplied identifiers and you must remember to never use a capital letter after the score, so it is a hazard.


Update

#ifndef LRUCache_h__

Any name containing a double underscore is reserved for use by the implementation.


/***
 * Method: objcache::LRUCache::LRUCache
 * Access: public 
 * Description: This creates a cache of given size. 
 */

Banner comments like this just get in the way of reading the code. Repeating the function name in a comment just before its definition does what exactly? (Oh, and a point of nomenclature: C++ does not have "methods".) Nobody comments each function as being public or private. For the description, don’t prefix it with "Description:"; just describe it.

Since I can see name of the argument is size and see how it’s used on the on the following line

LRUCache(size_t size) :
 m_cacheSize{ size },

a comment saying

// This creates a cache of given size

is useless. It only repeats what is in the signature: A constructor creates an instance of this class, and this one takes a size.

See (⧺P.1). You might also find this useful (Comments starts on page 17; material originally published in 1992).

added 1259 characters in body
Source Link
JDługosz
  • 11.7k
  • 19
  • 40

Not repeating what 1201ProgramAlarm reported.


std::mutex m_lock; // reader writer lock, multiple getters are allowed

I see a regular exclusive lock, not a reader/writer lock.

std::lock_guard<std::mutex> gaurd(m_lock);

Not taking advantage of class template argument deduction? This is a case where I really want it. (If not, use an alias for the lock type so it can be easily changed.)

std::lock_guard guard(m_lock);

 m_lruList{},
 m_lruMap{},
 m_lock{}

Just adds noise — is that a thing someone actually recommends? I would say don’t list all the things that are taken care of on their own.

 for (const auto &node : m_lruList)
 std::cout << node._key << std::endl;

The style in C++ is to put the * or & with the type, not the identifier. This is called out specifically near the beginning of Stroustrup’s first book, and is an intentional difference from C style.

Some people criticize the leading underscore of identifiers as a style. I point out that it is easy to clash with compiler-supplied identifiers and you must remember to never use a capital letter after the score, so it is a hazard.


#Update

#ifndef LRUCache_h__

Any name containing a double underscore is reserved for use by the implementation.


/***
 * Method: objcache::LRUCache::LRUCache
 * Access: public 
 * Description: This creates a cache of given size. 
 */

Banner comments like this just get in the way of reading the code. Repeating the function name in a comment just before its definition does what exactly? (Oh, and a point of nomenclature: C++ does not have "methods".) Nobody comments each function as being public or private. For the description, don’t prefix it with "Description:"; just describe it.

Since I can see name of the argument is size and see how it’s used on the on the following line

LRUCache(size_t size) :
 m_cacheSize{ size },

a comment saying

// This creates a cache of given size

is useless. It only repeats what is in the signature: A constructor creates an instance of this class, and this one takes a size.

See (⧺P.1 ). You might also find this useful (Comments starts on page 17; material originally published in 1992).

Not repeating what 1201ProgramAlarm reported.


std::mutex m_lock; // reader writer lock, multiple getters are allowed

I see a regular exclusive lock, not a reader/writer lock.

std::lock_guard<std::mutex> gaurd(m_lock);

Not taking advantage of class template argument deduction? This is a case where I really want it. (If not, use an alias for the lock type so it can be easily changed.)

 m_lruList{},
 m_lruMap{},
 m_lock{}

Just adds noise — is that a thing someone actually recommends? I would say don’t list all the things that are taken care of on their own.

 for (const auto &node : m_lruList)
 std::cout << node._key << std::endl;

The style in C++ is to put the * or & with the type, not the identifier. This is called out specifically near the beginning of Stroustrup’s first book, and is an intentional difference from C style.

Some people criticize the leading underscore of identifiers as a style. I point out that it is easy to clash with compiler-supplied identifiers and you must remember to never use a capital letter after the score, so it is a hazard.


#Update

#ifndef LRUCache_h__

Any name containing a double underscore is reserved for use by the implementation.

Not repeating what 1201ProgramAlarm reported.


std::mutex m_lock; // reader writer lock, multiple getters are allowed

I see a regular exclusive lock, not a reader/writer lock.

std::lock_guard<std::mutex> gaurd(m_lock);

Not taking advantage of class template argument deduction? This is a case where I really want it. (If not, use an alias for the lock type so it can be easily changed.)

std::lock_guard guard(m_lock);

 m_lruList{},
 m_lruMap{},
 m_lock{}

Just adds noise — is that a thing someone actually recommends? I would say don’t list all the things that are taken care of on their own.

 for (const auto &node : m_lruList)
 std::cout << node._key << std::endl;

The style in C++ is to put the * or & with the type, not the identifier. This is called out specifically near the beginning of Stroustrup’s first book, and is an intentional difference from C style.

Some people criticize the leading underscore of identifiers as a style. I point out that it is easy to clash with compiler-supplied identifiers and you must remember to never use a capital letter after the score, so it is a hazard.


#Update

#ifndef LRUCache_h__

Any name containing a double underscore is reserved for use by the implementation.


/***
 * Method: objcache::LRUCache::LRUCache
 * Access: public 
 * Description: This creates a cache of given size. 
 */

Banner comments like this just get in the way of reading the code. Repeating the function name in a comment just before its definition does what exactly? (Oh, and a point of nomenclature: C++ does not have "methods".) Nobody comments each function as being public or private. For the description, don’t prefix it with "Description:"; just describe it.

Since I can see name of the argument is size and see how it’s used on the on the following line

LRUCache(size_t size) :
 m_cacheSize{ size },

a comment saying

// This creates a cache of given size

is useless. It only repeats what is in the signature: A constructor creates an instance of this class, and this one takes a size.

See (⧺P.1 ). You might also find this useful (Comments starts on page 17; material originally published in 1992).

added 147 characters in body
Source Link
JDługosz
  • 11.7k
  • 19
  • 40

Not repeating what 1201ProgramAlarm reported.


std::mutex m_lock; // reader writer lock, multiple getters are allowed

I see a regular exclusive lock, not a reader/writer lock.

std::lock_guard<std::mutex> gaurd(m_lock);

Not taking advantage of class template argument deduction? This is a case where I really want it. (If not, use an alias for the lock type so it can be easily changed.)

 m_lruList{},
 m_lruMap{},
 m_lock{}

Just adds noise — is that a thing someone actually recommends? I would say don’t list all the things that are taken care of on their own.

 for (const auto &node : m_lruList)
 std::cout << node._key << std::endl;

The style in C++ is to put the * or & with the type, not the identifier. This is called out specifically near the beginning of Stroustrup’s first book, and is an intentional difference from C style.

Some people criticize the leading underscore of identifiers as a style. I point out that it is easy to clash with compiler-supplied identifiers and you must remember to never use a capital letter after the score, so it is a hazard.


#Update

#ifndef LRUCache_h__

Any name containing a double underscore is reserved for use by the implementation.

Not repeating what 1201ProgramAlarm reported.


std::mutex m_lock; // reader writer lock, multiple getters are allowed

I see a regular exclusive lock, not a reader/writer lock.

std::lock_guard<std::mutex> gaurd(m_lock);

Not taking advantage of class template argument deduction? This is a case where I really want it. (If not, use an alias for the lock type so it can be easily changed.)

 m_lruList{},
 m_lruMap{},
 m_lock{}

Just adds noise — is that a thing someone actually recommends? I would say don’t list all the things that are taken care of on their own.

 for (const auto &node : m_lruList)
 std::cout << node._key << std::endl;

The style in C++ is to put the * or & with the type, not the identifier. This is called out specifically near the beginning of Stroustrup’s first book, and is an intentional difference from C style.

Some people criticize the leading underscore of identifiers as a style. I point out that it is easy to clash with compiler-supplied identifiers and you must remember to never use a capital letter after the score, so it is a hazard.

Not repeating what 1201ProgramAlarm reported.


std::mutex m_lock; // reader writer lock, multiple getters are allowed

I see a regular exclusive lock, not a reader/writer lock.

std::lock_guard<std::mutex> gaurd(m_lock);

Not taking advantage of class template argument deduction? This is a case where I really want it. (If not, use an alias for the lock type so it can be easily changed.)

 m_lruList{},
 m_lruMap{},
 m_lock{}

Just adds noise — is that a thing someone actually recommends? I would say don’t list all the things that are taken care of on their own.

 for (const auto &node : m_lruList)
 std::cout << node._key << std::endl;

The style in C++ is to put the * or & with the type, not the identifier. This is called out specifically near the beginning of Stroustrup’s first book, and is an intentional difference from C style.

Some people criticize the leading underscore of identifiers as a style. I point out that it is easy to clash with compiler-supplied identifiers and you must remember to never use a capital letter after the score, so it is a hazard.


#Update

#ifndef LRUCache_h__

Any name containing a double underscore is reserved for use by the implementation.

Source Link
JDługosz
  • 11.7k
  • 19
  • 40
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /