HackMD
  • Beta
    Beta  Get a sneak peek of HackMD’s new design
    Turn on the feature preview and give us feedback.
    Go → Got it
      • Create new note
      • Create a note from template
    • Beta  Get a sneak peek of HackMD’s new design
      Beta  Get a sneak peek of HackMD’s new design
      Turn on the feature preview and give us feedback.
      Go → Got it
      • Sharing Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • 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
      • More (Comment, Invitee)
      • Publishing
        Please check the box to agree to the Community Guidelines.
        Everyone on the web can find and read all notes of this public team.
        After the note is published, everyone on the web can find and read this note.
        See all published notes on profile page.
      • Commenting Enable
        Disabled Forbidden Owners Signed-in users Everyone
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Invitee
      • No invitee
      • Options
      • Versions and GitHub Sync
      • Transfer ownership
      • Delete this note
      • Template
      • Save as template
      • Insert from template
      • Export
      • Dropbox
      • Google Drive Export to Google Drive
      • Gist
      • Import
      • Dropbox
      • Google Drive Import from Google Drive
      • Gist
      • Clipboard
      • Download
      • Markdown
      • HTML
      • Raw HTML
    Menu Sharing Create Help
    Create Create new note Create a note from template
    Menu
    Options
    Versions and GitHub Sync Transfer ownership Delete this note
    Export
    Dropbox Google Drive Export to Google Drive Gist
    Import
    Dropbox Google Drive Import from Google Drive Gist Clipboard
    Download
    Markdown HTML Raw HTML
    Back
    Sharing
    Sharing Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    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
    More (Comment, Invitee)
    Publishing
    Please check the box to agree to the Community Guidelines.
    Everyone on the web can find and read all notes of this public team.
    After the note is published, everyone on the web can find and read this note.
    See all published notes on profile page.
    More (Comment, Invitee)
    Commenting Enable
    Disabled Forbidden Owners Signed-in users Everyone
    Permission
    Owners
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Invitee
    No invitee
       owned this note    owned this note      
    Published Linked with GitHub
    Like BookmarkBookmarked
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # 用 6 分鐘的時間告訴你什麼是直譯?什麼是編譯?了解程式語言的差異 ## 前言 寫程式就像是在寫劇本一樣,我們可以透過撰寫指令的方式要求電腦照著我們設計的流程來執行,這樣行為就是所謂的程式設計。 ## 程式語言的執行方式 讓電腦讀取劇本基本上就會有兩種方式,一種叫做編譯,一種叫做直譯,而透過編譯過才能執行的稱為「編譯語言」,而透過直譯才能執行的則稱為「直譯語言」。 ### 直譯 直譯語言又稱為「腳本語言」(英文叫做 Scripting language),它會經過一個叫做「直譯器」的東西將寫好的程式碼給讀取進來,然後根據程式碼的內容由上到下一行行執行。 這個行為就像是一個人在讀取腳本劇本一樣依序做著文件上所撰寫的流程,所以被稱為是腳本語言。 這樣的好處是從程式碼撰寫到直接執行這中間的時間會大幅縮短,跟編譯型語言比起來少做很多事;但缺點就是要執行某個腳本語言寫的程式(譬如說 Ruby),則那部電腦本身就必須要安裝 Ruby 直譯器,才能正確讀取並且執行,不然對電腦來說這樣的一個檔案基本上跟純文字文件沒什麼大的差異了。 當然,你可能會想到說「那把直譯器跟程式碼包在一起發佈就可以解決這問題了呀」,我必須稱讚你你很聰明,的確這件事是可行的! 像我在上一篇文章(這邊插入文章名稱與連結)有提過我曾經開發過一個 「Ruby 執行檔製作精靈」這個工具,就是在做這件事,最後會輸出一個含有 Ruby 直譯器與程式碼結合體的 Windows 執行檔,但缺點就是檔案會變得很大哦! 另外一個缺點是,如果說直譯器的效能不好,譬如像是早期的 Ruby / Python 等,它們在啟動速度與執行上面就會比編譯型語言開發出來的程式還要來得慢,不過近幾年已經開始有改善,加上電腦硬體的進步,我相信這個問題慢慢不再是主要的缺點了。 ### 編譯 透過編譯語言開發程式的時候,寫好的程式碼會經過一個叫做「編譯器」的軟體進行解析,經過解析、連結後將程式碼轉換成可以執行的執行檔,之後就可以把這個執行檔放到任何在同樣的作業系統(譬如說 Windows)的電腦(或者行動裝置)上面執行了。 編譯語言的好處就是執行的目標電腦本身不需要安裝開發環境(但可能還是會需要安裝其他第三方的函式庫之類的東西),所以可以縮小程式的檔案大小,而且編譯語言對一些細節(譬如記憶體使用量)的控制會比較大,所以執行的效能也會相對比直譯器要來得好。 不過編譯語言也不是沒有缺點: 每次修改都要編譯一次 程式撰寫比較囉唆(宣告型態) 註解: - 第三方: 以 macOS 為例,蘋果與電腦的使用者分別為第一方或第二方,而提供某個功能讓蘋果使用的公司可稱為第三方 - 函式庫: 提供給某些軟體、程式增加不同功能的工具箱 ## 代表性的語言有哪些 ### 直譯 現在其實有蠻多直譯語言的,像是我在上一篇(輸入文章名稱連結過去)提過的 Ruby / PHP / JavaScript 外,還有下面幾種 - Python - Perl - Lua - Erlang 不過當前最流行的我想應該就是 Python 了,在機器學習、大數據分析上有著不錯的表現,應用層面也跟 Ruby / Perl 一樣廣,如果有興趣也可以花點時間學習看看。 ### 編譯 我想這個最知名的絕對是 C 語言(與它的其他系列程式語言)了吧? - C / C++ - Objective-C - Java - C# - COBOL ## 總結 在這篇簡單分享了一下目前比較常見的兩種類型的程式語言,這雖然不一定對寫程式的能力有明顯的提升或幫助,但是在了解語言的型態以及它的運作原理,絕對可以幫助你更加了解你在接觸的東西是什麼! 不管是編譯語言還是直譯語言,各有各的優缺與擅長的領域,常常看到兩派語言支持者在互戰,支持編譯語言的說直譯語言執行慢、檔案肥;支持直譯語言的又說編譯語言每次寫完編譯都要去泡個咖啡,回來剛好編譯完。 我個人覺得不用這樣,這些都只是工具而已,在不同的情境善用不同的工具是可以追求的事情,交流彼此的優點、想辦法克服彼此的缺點,這樣才有辦法讓技術不斷地精進、成為更好的開發者。 ### 學習建議 不過如果你是初學程式語言,並且是採取自學的方式的話,選擇直譯語言會讓你比較快看到程式執行的結果,而且學習的成本也不會太高,資源也蠻豐富。 像是我在前面那篇提到的,你可以先嘗試接受 JavaScript / Ruby / PHP 等語言,之後再學習 C 語言或 C++ ,這都會是蠻好的選擇。 如果你是相關科系的學生的話,還是以學校所安排的課程進度來學習就好,不建議同時自修學習不同的語言,因為這樣很容易讓你在不同語言之間搞混。 我過去曾經同時自修 Visual Basic 與 C 語言,結果常常在寫 C 的時候寫 Basic 的語法、寫 Basic 的時候寫 C 的語法,然後程式一直執行失敗還看不出原因,浪費很多時間在找錯誤。 所以如果今天要學習的話,先掌握一個語言就可以了,後面再慢慢增加不同語言的能力。 希望可以幫助大家了解常見語言的兩種類別,這樣在挑選語言來學習的時候也比較不會有認知上的落差。

    Import from clipboard

    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 lost their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template is not available.


    Upgrade

    All
    • All
    • Team
    No template found.

    Create custom template


    Upgrade

    Delete template

    Do you really want to delete this template?

    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

    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

    Tutorials

    Book Mode Tutorial

    Slide Mode Tutorial

    YAML Metadata

    Contacts

    Facebook

    Twitter

    Feedback

    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

    Versions and GitHub Sync

    Sign in to link this note to GitHub Learn more
    This note is not linked with GitHub Learn more
     
    Add badge Pull Push GitHub Link Settings
    Upgrade now

    Version named by    

    More Less
    • Edit
    • Delete

    Note content is identical to the latest version.
    Compare with
      Choose a version
      No search result
      Version not found

    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. Learn more

         Sign in to GitHub

        HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.

        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
        Available push count

        Upgrade

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Upgrade

        Danger Zone

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

        Syncing

        Push failed

        Push successfully