CoderClark
    • Create new note
    • Create a note from template
      • 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
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me 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
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control 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
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # A0004 程式設計是有趣的堆積木遊戲 ## 程式設計很有樂趣 **「程式設計很有樂趣」**,這句話恐怕相當多人不認同。大多數人寫程式通常關心著撰寫功能、擔心著易讀與否、經歷著無盡的 Debug;這樣的經驗是辛苦的、沉重的、痛苦的,自然與樂趣是沾不上邊。那為什麼又說有樂趣呢?千萬別誤會了,這裡所說的樂趣不是指以虐待自己為樂、吃苦當吃補的那種,而是像打球、看劇、玩遊戲等等所能獲得的樂趣,是真正能享受在其中的體驗。 之所以會覺得程式設計沒樂趣,關鍵是沒接觸到**有趣的觀念**;如果能把這些觀念帶到程式設計的過程中,相信看待程式設計的方式一定會有所改變。 ## 程式設計是堆積木遊戲 要解釋為什麼有樂趣之前,我們需要新的比喻來看待程式設計。這裡不再老梗地說寫文章、種田、蓋房子等比喻,畢竟印象中作家、農夫、建築師通常都是辛苦的,用於解釋樂趣稍嫌不夠準確。這個新的比喻,就是**堆積木遊戲**。 玩遊戲應該沒有人覺得沒樂趣吧?那為什麼是**堆積木**而不是其他遊戲呢? ### 觀念就是積木 在這個比喻中,可以很直覺地將程式設計的各種觀念,看作是一個一個的積木,包括但不限於 Syntax(語法)、Compilation Rule(編譯規則)、Readability(易讀性)、Abstraction(抽象化)、Data Structure(資料結構)、Coupling(耦合性)、Dependency (依賴性)、Exception Handling(例外處理)、Object-Oriented Programming(物件導向)、Bad Smell(壞氣味)、Design Pattern(設計模式)、Test-Driven(測試驅動)、Agile(敏捷)、Refactoring(重構)、Parallel Programming(平行程式)、Microservice(微服務)、Macro Programming(巨集)、Generic Programming(泛型)、等等。 ### 積木各有特色 積木有各種不同的特色,包括長寬高、形狀、顏色、重量,也包括方便性、實用性、美觀性等等,而程式設計的觀念也是有大有小、有各自的目的與優點、有好用的程度之類的;像是: * Readability(易讀性)可以讓程式碼更容易維護、 * Abstraction(抽象化)可以更好掌控程式碼的複雜度、 * Bad Smell(壞氣味)可以發現程式碼不妥善的地方。[^1] [^1]: 僅以幾個簡單的例子做特性說明,請不要把例子作為準則。由於觀念本身並非這樣一句話就能概括,如果把例子當作準則恐怕有[見山不是山](/xiinN0T5QQ2a_V_rCFhavg)的疑慮。 程式設計師可以依據需求,採取合適的觀念進入自己的程式碼中。 ### 積木有所限制 積木也不是隨意使用的,通常會有所限制,包括形狀、平衡、鑲嵌相容性,所以想要圓柱凸起的地方不適合用長方體、想要堆疊得高就不能頭重腳輕、想要堆疊特殊造型的積木就要看銜接的格子數是否可以鑲嵌。因為有限制,所以可能會遇到遺憾的情況:即使有個積木確實很有特色、很理想,但卻不好納入使用。 同樣地,程式設計觀念在使用上也會有所限制,比方說: * 想要做Generic Programming(泛型)但 Syntax(語法)支援不佳、 * 為完成某個 Design Pattern(設計模式)可能要犧牲 Readability(易讀性)、 * 使用 Macro Programming(巨集)以獲得更好的運作效率卻產生 Bad Smell(壞氣味)、 * 想要 Refactoring(重構)讓架構更完善卻有運作效率不佳的考量。[^2] [^2]: 僅以幾個簡單的例子做限制說明,請不要把例子作為絕對的限制。。由於限制可能需要某些條件才成立,如果把例子看成絕對的,就會有[見山不是山](/xiinN0T5QQ2a_V_rCFhavg)的問題。 也就是說,沒有觀念是絕對完美合適使用的,可能會因為限制(或者說是副作用)而要有所取捨。 ### 堆疊完成目標 要完成目標主題,就要思考如何堆疊、組合手上的積木,特色與限制都是要思考的。就像是要完成一艘大航海時代的戰艦,就得考慮許多不同大小的三角形外觀積木做船身、就得考慮一定數量的長方體積木做船艙與甲板、就得考慮船桅與船槳積木、以及可以相容放置船桅與船槳的積木、等等。堆疊的概念一樣可以套用在程式設計上,那就是得思考哪些觀念是要考慮的、哪些觀念是真的能應用上、那些觀念會因限制只能採用部分或者放棄。積木考慮得越周到,成品就會越好看;觀念考慮得越周到,程式就會越完善。 ### 沒方法找方法 很多時候會發現,手上的積木是不足夠完成目標的。像是戰艦自然要有火藥庫與砲台,但如果手上沒有火藥庫的裝飾與砲台造型的積木,就得去找其他合適的零件來使用;倘若沒有直接可以使用的,就要設法找到其他替代品,像是用貼紙來完成火藥庫的裝飾、用幾個細長積木組出砲台的外型。程式設計也是一樣的,舉例來說: * 覺得有 Bad Smell(壞氣味)卻改不動程式碼,怎麼改都會有問題,可能是自己認知的觀念太少了,因此要尋求原本沒考慮過的觀念:Refactoring(重構),才有機會解決當前的難題; * 假設在C 語言平台下,需要 Object-Oriented Programming(物件導向)、Generic Programming(泛型)來完成目標程式碼,可是 C 語言 Syntax(語法)本身並不直接支援這2個概念;然而只要妥善運用既有觀念,像是 Abstraction(抽象化)、Data Structure(資料結構)、Macro Programming(巨集)等,就能組合出 Object-Oriented Programming(物件導向)與 Generic Programming(泛型)。 簡單來說,面對要解決的問題,就是**沒方法找方法**。堆積木是這樣,程式設計也是這樣。 ## 以管窺天的偏見 或許有人會問,縱使程式設計就真的是在堆積木吧,但如果觀念本身是無聊的,堆疊時怎麼能有趣呢?當然,不是每一個觀念本質上都是有趣的,就像積木有單調的簡單長方體與立方體。而事實上,在單調的積木之外,存在著許多形形色色的特色積木,它們才是讓堆積木有趣的關鍵。 同樣的,在眾多的程式設計觀念中,幾乎只有 Syntax(語法)與Compilation Rule(編譯規則)是單調的[^3]。這些單調觀念的確是不可或缺的零件,但其實只占所有觀念的很小一部分,卻常被誤解為程式設計觀念的全部,導致人們認為程式設計很無趣。可以問一個問題來類比:人們會因為只看過比賽規則,就覺得球賽很無聊嗎?肯定不會。因為真正有趣的是以規則為基礎的各種運用、技術、戰術等等的。由此可見,僅用最單調的觀念來認定程式設計不有趣,是多大的偏見呀! [^3]: 除了 Syntax(語法)與 Compilation Rule(編譯規則)規則之外,Readability(易讀性)因為著重程式碼本身的組織,所以也有人會覺得單調無趣。 總結來說,**如果堆積木是有趣的,寫程式也會是有趣的!** 要進入有趣的世界,就要接觸有趣的積木,而不是以管窺天,用少少的認知就下如此絕對的結論! ## 延伸閱讀 A0005 第一個有趣的積木:抽象化 (撰寫中) B0005 用堆積木方式思考程式設計 (撰寫中)

    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