EatClubPub
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    ###### tags: `CleanCode` <STYLE> p,li,oi,h3{ font-family:"微軟正黑體"; } </STYLE> # 基本觀念 特點: > 戴夫.湯馬斯(Dave Thomas);羅恩.傑佛瑞(Ron Jeffries) * ==充分表達系統設計的構思,使用有意義的名稱,增加程式的**可讀性**== * ==單一職責原則,一個類別應該只有一個職責== :::info <h2>沒有重複的程式碼!必須盡可能減少程式碼的相依性</h2> ::: --- ### 1️⃣命名 * 使用具有意義的名稱 * 選擇能反映出類別或函式的抽象層次之名稱 * 避免使用常見字詞(ex:hp、sco..) * 避免使用與變數型態無相關的相近字詞(ex:accountList) * 要區別相似功能的function,需使用能辨識其不同處的命名 * 相同概念使用同一字詞 * 單一字母或數字可用於小函式中,其餘盡量使用可被搜尋的名稱(ex:用sum取代s) * 不應該將型態編碼到名稱裡 **類別**:使用名詞or名詞片語,不該使用動詞;避免用Manager、Processor、Data、Info。 **方法**: 使用動詞or動詞片語。 > overload時,使用含參數資訊的方式。 > 例:將new Complex(23.0)改以Complex.FromRealNumber(23.0)方式產生,並考慮將後者建構子設為private --- ### 2️⃣函式 * 簡短、短小精幹,讓函式長度愈短愈好 * 每個函式都只做一件事 * *檢測方式:是否能從中提煉出另一個函式?且新函式不能只用來重新詮釋原函式的實作* * 將例外處理(try/catch)提取成一個函式 #### ※注意事項 :::info * 避免過多的參數:避免參數超過3個。 * 避免輸出型參數(在非物件導向程式設計可見):函式盡量只能修改其所屬物件的狀態。 * 避免旗標參數(Flag):表示此函式只做了不只一件事情,違反單一職責原則。 * 移除被遺棄的函式:刪除不會用到的函式(若要查找,請記住可以從原始碼管控系統查找) ::: --- ### 3️⃣註解 避免多餘的註解,會增加閱讀複雜度與誤導。 * 有益:提供函式的基本資訊、解釋某行程式之意圖、闡明參數與回傳值、待辦事項 * 有害:日誌型註解、干擾無益的註解 #### ※注意事項 :::info * 註解應該保留技術性紀錄(ex:程式或設計方面的資訊),歷史修改則不太適合放在此。 * 若發現註解過時,最好盡快更新或移除它。 * (1)如果程式碼已能表達意圖,則不需要多餘註解。(2)註解應該說明程式本身無法表達的意圖。 * 選用詞彙與正確的文法及符號,不說廢話。 * 移除被註解掉的程式碼 ::: --- ### 4️⃣程式碼編排 * 垂直空白:不同概念間使用換行區隔 * 垂直密度:避免在函式裡使用多行註解 * 垂直距離:變數宣告應盡量靠近被使用的地方/概念相似的函式首要放在一起;而相依的函式在編排上則盡量次要靠近 * 水平空白:用於突出重要的元素。避免將高度相關的元素分開(ex:函式名與參數)。 --- 肯特.貝克(Kent Beck)提出簡單設計的四原則,前三點是最為重要的守則。: * 執行完所有的測試 * 程式重構(**禁止重複的程式碼**、**程式碼具表達力**、**最小化類別與方法的數量**) #### 1. 執行完所有的測試 撰寫容易測試的程式,並且持續執行程式測試。讓程式碼保持低耦合度與高凝聚度。 #### 2. 禁止重複的程式碼 不論是完全相像或者看似相像的程式碼,都需要經過重構。甚至能將提取出來的方法移至另一個類別,遵守單一職責原則(SRP)。 #### 3. 程式碼具表達力 * 可以利用**選擇合適的名稱來命名類別或函式** * 透過**讓函式和類別簡短化**,通常較容易撰寫、命名與理解。 * 利用**標準命名法**,(使用標準化名稱,如COMMAND或VISITOR,當作實作模式的類別名稱。) #### 4.最小化類別及方法的數量 建議保持類別、函式,以及系統的簡短。

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully