Improve Coding Quality C++/Leetcode

85 阅读1分钟

Error Handling

拿到题目后第一时间检测各个edge cases. string.size == 0; ptr == nullptr etc.

Naming Convention

Do not use single character to name variables and functions. Use one or two words.

代码缩进(空格)

cout << "Hello World" << endl ;

x = y; 
y = y+1; 
add(x, y);

if( a == b ) 
{ 
    cout << "Line 1 - a 等于 b" << endl ; 
}

tab与space不能共存,自己选择最喜欢的一个

参考资料: Google C++ Style Guide

Function

学会用function. 清晰的function更有利于看懂题目