C++ Coding Standards
前言: 本文為分享Coding standards的相關資訊,為筆者整理學習過程的筆記與其他資料來源。 Coding standards 原則上 follow Google 的 Coding standards。 Coding Standards C++ code should be readable. Good Comments: Comments should tell you what’s being done from a high-level. Comments are important. 一個好的 Comments 必須要經常維護。 如果沒有 Comments,可能面臨幾種問題: 難以了解 programmer 的主要目的。 如果發現 code 有怪異之處。這是 bug?還是故意這樣寫? 如果我要 rewriting,我是否要保留這段奇怪的部分? 沒有 Comments 將會讓下一個 programmer 難以接手。 Understanding how a function is implemented when reading the code is done by: Choosing good variable names. Don’t skimp on names. Make them meaningful. Using concise code that’s easy to read (also means reasonably size for functions, lambdas, if-blocks, loops, etc). Using standard library implementations when available. Memory & Performance Basics Explicitly delete copy constructors and assignment operators from your class when you first write it unless you know you need them. Having them often lead to copies without knowing it, impacting memory and performance. Expli...