写代码的规范性和严谨

似乎日本人,德国人做事严谨是一个名片,全球知晓,觉得他们做出来的东西就好品质好。

就写代码而言,倒不是说写的逻辑有多么复杂,设计模式用得有多么好写代码就一定犀利,尤其是设计模式是经过大量实践和验证后得出来的理论方法。

现在的软件很容易就越做越大,而且经常不是两三个人就能做好,所以代码一定要统一风格才方便他人backup,maintenance以及iteration。举几个例子,感觉他们真的是处女座,仅限C++编程。

  • Please use spaces instead of tabs.
  • If possible, please use API description like in ‘src\MyWrapperIF.h’. This is a more Doxygen like approach and will enable us to generate a Docu out of the source in the future. So the agreement for now is: New APIs should use the new description format. Old ones is nice to have to update but we will do this in the future.
  • Please use “new” file header format, only copyright and description is needed, author etc. is not mandatory anymore.
  • Please use “#include <….>” instead of “#include “…”” for includes that are not in the same directory. (will increase compile time a little bit. But many “littles” leading to faster overall compilation)
  • One of our basic coding guidelines says that class and function names should be CamelCase. So for example it should not be “XMLDocument”, but “XmlDocument”. I know that there are already a bunch of new classes with uppercase name parts. They should be taken care of at a later time (but they should be corrected as well).
  • Regarding the removal of C++ projects from the ***.sln, use "makefile" file instead of  "*.vcxproj" file.

总得来说,有以下几点:

1. 写代码时一定要用空格(space)而不是制表符(tab)。

在VS中可以通过设置View White Space看到代码中是否是空格还是tab。

此外,可以在选项中设置VS的tab打出为4个空格。

2. 写函数时,尤其是对外使用的接口,一般为纯虚函数,要写上使用说明,比如描述,传入参数是什么,输出参数是什么。如果传入的函数仅内部使用,多使用常函数。继承函数时多加入override,final,virtual这样的关键字,方便跟踪。

3. 每个文件都应该有个简短说明,比如文件是干嘛的。

4. 包含头文件时,如果是系统或者库目录下的,用<>括号;如果是当前目录,就用""。这样子可以加快编译。

5. 尽量都采用CamelCase骆驼命名法则。

6. 多使用makefile编写编译规则,而不是用VS工程的形式。可能这样子更便于统一编译和管理,以及跨平台。

 

先总结这么多。

 

Enjoy!

 

 

 

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值