Function - Clean Code

          1. Small and the indent level should not be greater than one or two.
          2. Do One Thing - Functions should do one thing. They should do it well. They should do it only.
              Steps of function are one level of abstraction below the name of the function. Then the function is doing one thing.
              Another way to know function is doing more than one thing is if you can extract another function from it.
          3. One level of abstraction per function
              The stepdown rule - reading code from top to bottom.
              switch
          4. Use Descriptive Names
              Don't be afraid to make a name long.
              A long descriptive name is better than a short magic name.
              A long descriptive name is better than a long descriptive comment.
              Dont't be afraid to spend time choosing a name.
              Be consistent in your names.
          5. Function Arguments
              The ideal number of arguments for a function is zero.
              Three arguments should be avoided.
              Flag Arguments - can be split into two function.
              Aruments Objects - group the variables and abstract concept if possible.
              Verbs and keywords - function and argument should form a very nice verb/noun pair.
          6. Have no side effects
          7. Command Query Separation - Functions should either do something or answer something, but not both.
          8. Prefer Exceptions to returning error codes.
              Extract try/catch blocks, error handling is one thing.
          9. DRY - don't repeat yourself - especially the duplicated logic.

          posted on 2011-08-25 08:45 *** 閱讀(331) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          <2011年8月>
          31123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 许昌县| 桃园市| 阿城市| 博罗县| 昌都县| 竹溪县| 甘泉县| 杭州市| 淮阳县| 贡觉县| 琼结县| 墨竹工卡县| 双柏县| 武定县| 容城县| 阳原县| 孟村| 古浪县| 拉萨市| 理塘县| 巩义市| 安达市| 柳河县| 旅游| 布拖县| 农安县| 上林县| 武平县| 日喀则市| 巨野县| 中江县| 天气| 莆田市| 普洱| 余姚市| 潍坊市| 麻城市| 永平县| 周至县| 黄平县| 陆河县|