Yefu's coding stype

From Yefu's notes
Jump to: navigation, search
  • Avoid including Windows.h directly.
  • Avoid using windows API unless absolutely necessary
  • Make unit part of the variable name.
  • No "Hungarian Notation" ref
  • All codes should be understandable within +- one screen.
  • Boolean variables should not be part of the API.
  • No pollution: Do not force the caller to include something. Always use enum class instead of enums.
  • Minimum comments: If some codes need a lot of comments to understand, the code is NOT well written.
  • Use compile-time auto UTs to preventing maintainers to make mistakes.
  • Reference UTs in the comments in the real code as examples.
  • Prefer wider codes for readability
//Not good
if(false == somecondition)
  • Prefer not using types named int, long, short, DWORD, or their unsigned versions. Use __int32 or int32_t, etc., instead.
  • Use integer values only when I mean it is a number in integer.
    typedef uint64_t ResourceConsumerID;
  • Use "auto" when, neither the writer or the reader should care about the type of a value, and when the type is long.
  • Give the user the right amount of information to read.