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) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2011年8月>
          31123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 东港市| 东至县| 昭平县| 贡觉县| 德江县| 名山县| 舒兰市| 延长县| 买车| 绍兴市| 红原县| 黎平县| 手游| 大埔区| 娱乐| 曲周县| 顺义区| 嘉义市| 临武县| 县级市| 宣汉县| 普兰县| 浦县| 邓州市| 余干县| 外汇| 冷水江市| 徐州市| 景东| 长沙县| 志丹县| 永新县| 罗平县| 长海县| 蓬安县| 文安县| 洞头县| 南昌县| 旺苍县| 沙田区| 尤溪县|