LTP:Crafting quality code

注:本文出自Coursera上的一门名叫“打造高质量代码”的网络课程的授课老师,是多伦多大学的CS教授,以下是他对构建代码的建议:


Paul Gries, the Senior Lecturer in the Department of Computer Science at the University of Toronto suggested some good habits in crafting quality code:

  • Plan before you type. One of my favourite quotes, from Greg Wilson (although I don't know if it's his), is "Sometimes and hour of thought can save you a week of hard work."

  • Make sure you understand the problem you're trying to solve before you try to solve it.

  • If you don't know how to write a function to do a task, do it by hand and think hard about what you're doing.

  • Test your code. You don't have to write all the tests first, but write at least a couple tests before you write a function. You do this in order to make sure you understand what the function is supposed to do.

  • If some code is broken, it's faster to figure out exactly what went wrong than it is to try things randomly until it works.

  • Top-down design has you write high-level sentences describing what you want to do. These usually make excellent comments.

  • Once you figure out something --- anything! --- make a note so that you don't have to figure it out again. Comments are usually the easiest way to do this.

  • The structure of your data is vital. Document it.

Bigger issues:

  • Learn about version control. git is the current crowd favourite:

http://git-scm.com/

Watch video tutorials, try out git, learn the ideas behind every version control system. Every company uses version control of some kind; options include git, perforce, subversion, and many more. (We teach version control at the beginning of second year here at the UofT, and it's beyong the scope of LTP2, but it's really, really important, especially when working with other programmers.)

  • If you know c-based programming languages (C, C++, Python, Ruby, Java, most others), take the time to learn a weird one. Haskell, Scheme, and Lisp are all excellent choices. Gregor Kiczales from UBC is running a Coursera course on Scheme, and I'm looking forward to following it myself:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值