Skip to content

什么是 Code?

理解什么源 code 是, 如何它 differs 从 machine code, and 为什么我们 use programming languages.

你将学到

  • 什么源 code 是 and 什么它 looks 如
  • difference 之间源 code and machine code
  • 为什么 humans invented programming languages
  • 如何编译器 or 解释器 turns code 到操作

概念讲解

What Is Code?

Code (or source code) is the text a programmer writes. It is a list of instructions written in a programming language — a precise, unambiguous language that both humans and computers can work with.

Source Code vs. Machine Code

A CPU only understands machine code — raw binary numbers like 01101000 10111000. Writing programs directly in binary is nearly impossible for humans. So we write source code in a readable language like JavaScript or Python, and a tool translates it into machine code for us.

  • Source code — human-readable text (what you write).
  • Machine code — binary instructions the CPU executes.

Compilers and Interpreters

Two kinds of tools perform the translation:

  • A compiler reads your whole program and converts it into machine code *before* it runs. C, Rust, and Go are compiled.
  • An interpreter reads and runs your program line by line while it executes. JavaScript and Python are interpreted.

The end result is the same: your instructions become actions. The difference is *when* the translation happens.

Why Many Languages?

Different languages are optimized for different goals. Python prioritizes readability; C prioritizes speed; JavaScript runs in every browser. The concepts you learn in this course — variables, loops, functions — exist in nearly every language, so once you learn them, you can switch languages with ease.

示例代码

              // Source code (what you write):
const score = 95;
if (score >= 90) {
  console.log("Grade: A");
}

// The interpreter reads this line by line:
// 1. Create a variable named score with value 95
// 2. Check: is 95 >= 90? Yes.
// 3. Print "Grade: A" to the console
            

comments 描述如何解释器处理每个行. computer 从不 sees comments — 它们 exist 仅到 help humans 读取 code.

动手试一试

  • 情况 Converter

    真实 tool 构建从 源 code. 它 takes 文本 (输入), applies transformation (处理), and 返回 converted 文本 (输出).

常见错误

错误写法

Confusing 源 code 使用 machine code.

正确做法

源 code 是 human-readable 文本你 编写. Machine code 是 binary CPU 运行. 编译器/解释器 bridges two.

错误写法

Thinking one language 是 ' best'.

正确做法

Languages 是 tools for 不同作业. 学习概念首先 — 它们 transfer 之间 languages 容易地.

相关速查表

查阅不认识的术语

新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。

查看术语表

动手做项目

通过引导式项目应用所学,含起始代码与解决方案。

查看项目

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误