Clean Code读书笔记

Meaningful Names

  1. Do not encodes the type information in the name.
  2. Avoid disinformation.
  3. Name should be self-delaractive.
  4. Use Pronouceable and Searchable Names.Makes searching for symbol easier. Makes code reusability easier.

Function

  1. Be small. Block structures should not be nested and should be 3-4 lines long. Indent level of a functions should not be greater than one or two.
  2. KISS. Keep It Simple, Stupid. One function should just do one thing, and do it well. The code in the function should be one level of abstraction below the name of the function.
  3. The Stepdown Rule: Making the code read like a top-down set of TO paragraphs is aneffective technique for keeping the abstraction level consistent.
  4. Bury switch statement under the lowest level.
  5. Give descriptive name to function. A self-explanative name is better than a long comment describing it.
  6. The less arguments, the better. Function with less arguments is easier to remember. Avoid using flag argument, it's ugly. Function should just do one thing as mentioned above.
  7. No side effects. Side effects are lies. The function promises to do one thing, but it also does other hidden things. This is evil.
  8. Use this as an output argument. Anything that forces you to check the function signature is euivalent to a double-take. So put output argument is an bad idea.
  9. Error handling is one thing. It should be put into one function.

Comments

  1. Explain yourself in code.
  2. Explanation of intent which is not clear in code.
  3. If the variable or function name is self-explanative, don't repeat it in comments.
  4. Noisy comments should be avoided because it lower the readability.
  5. Delete your commented-out code. We have SCM tools, and we can revert our code through it.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值