close

chapter3

simple, just do one thing in a function.

If a paragraph of code do three things, have better seperide those three things to individual three functions.

And giving them a meanful name, it can help developer more fast to understand those functions.

 

1. switch narrative

It's not easy to let a switch narrative sample.

Even a switch narrative only has two situation, it's also against single responsibility principle and open closed principle .

In  generally  if we need to use switch narrative, we need binding special value.

If probably just use A switch narrative in a function.

 

 

2. function's parameter

In a function, best idea is use 0 parameter, until 2 parameter are fine.

Three parameter are max-limit.

Too many parameter will let a function more difficult to read.

When there are more than two parameters, it is likely that several of them will need to be combined into one category.

 

3. Do not use flag to be parameter.

Because boolean is true will do the first thing , and boolean is false will do the second thing.

It's also against singal responsibility principle.

 

4.try/catch block

Had better just one line in try/catch block. And write it in the function.
Don't use break, continue too much to keep your function efficient.
Do not use togo that it's really pain to read.

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 A&B 的頭像
    A&B

    網頁前端新手上路辛酸史

    A&B 發表在 痞客邦 留言(0) 人氣()