学习日志—给C程序员的建议

为了帮助自己区分之前学习C语言:

 

[1]在C++里几乎不需要用宏。consatenum定义明显的常量,用inline避免函数调用的额外开销,用template去刻画 families of functions of types, and namespace to avoid  name clashes.

 

[2]不要在你需要变量之前去声明它,以保证你能立即对它进行初始化。A declaration can occur anywhere  a statement can

,in for-statement initializers,and in conditions.

 

[3]Don't use malloc(). The new operator does the same job better , and instead of realloc() , try  a vector().

 

[4]Try to avoid  void* , pointer arithmetic , unions, and casts,except deep within the implementation of some function or class. In most cases,  a cast is an indication  of a  design  error .  If you must use an explicit  type coversation , try using  one  of  the "new cast" for a more precise statement of  what you are trying to do.

 

[5]Minimize the use of arrays and C-style strings. The C++ standard library string and vector classes can often be used to simplify programming compared to traditional C style.In general ,try not to build yourself what has already been provided by the standard library.

 

Most important ,try thinking of a program  as a set of interacting concepts represented as classes and objects, instead of as a bunch of data structures with functions twiddling their bits.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值