Skip to main content
Code Review

Return to Revisions

3 of 3
replaced http://stackoverflow.com/ with https://stackoverflow.com/

I would like to make some suggestions on code improvements in general, if I may:

  • Prefer const or constexpr for compile time constants. The problems with macro constants are that they don't respect scope and can also be silently redefined, not to mention that they are very weakly typed.

  • Names starting with an underscore, while not wrong for a member variable of a class or struct, are reserved in some cases. I would advise agains their use because it is easy to slip such a name into the global namespace if you are accustomed with writing them in other places.

  • Make more use of const. Const is good for code self-documentation and can also help preventing programmer errors. I recommend that you read more about Const Correctness.

  • currentTime and timeInserted: These variables are referring to an amount of time, that is obvious enough, but how is someone supposed to know which time unit is being used? Without a comment or an indicative in the name, one can only guess... Seconds, milliseconds, microseconds? A comment would sure help, but also, when dealing with different units and scales, it is a very good idea to encode that information in the name. So lets assume you are using milliseconds, the variables could be renamed to currentTimeMs and timeInsertedMs, I've used the Ms suffix in this example, but you could very well use a full Milliseconds to make it cristal clear.

  • Still about the times though, you could also switch to the new <chrono> library and use the strongly typed time measurement objects instead.

  • Your code is relying too heavily on raw pointers. Just from looking at it, as an outsider to the project, it is very hard to tell which objects own which. I wouldn't be surprised if you have memory leaks going on over there. The use of standard smart pointers and standard containers would make your code a lot memory safer and easier to comprehend.

glampert
  • 17.3k
  • 4
  • 31
  • 89
default

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