essence of clean code

Functions


F1: Too Many Arguments
Functions should have a small number of arguments. No argument is best, followed by
one, two, and three. More than three is very questionable and should be avoided with prejudice.
(See “Function Arguments” on page 40.)


F2: Output Arguments
Output arguments are counterintuitive. Readers expect arguments to be inputs, not outputs.
If your function must change the state of something, have it change the state of the
object it is called on. (See “Output Arguments” on page 45.)

 

F3: Flag Arguments
Boolean arguments loudly declare that the function does more than one thing. They are
confusing and should be eliminated. (See “Flag Arguments” on page 41.)

 

F4: Dead Function
Methods that are never called should be discarded. Keeping dead code around is wasteful.
Don’t be afraid to delete the function. Remember, your source code control system still
remembers it.

 

my note: in my opinion, flag isn't that beautiful, should not be used. especially those flag as function arguments.

 

Java
J1: Avoid Long Import Lists by Using Wildcards

 

J2: Don’t Inherit Constants

This is a hideous practice! The constants are hidden at the top of the inheritance hierarchy.
Ick! Don’t use inheritance as a way to cheat the scoping rules of the language. Use a static
import instead.

 

J3: Constants versus Enums

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值