coding_fun Computer Science

19 个科学问题 · 计算机 Computer Science

本页目录

编程里的“变量”是什么?

What is a 'variable' in programming?

变量就像一个贴了名字的盒子,里面可以装数字、文字等会变化的值。程序运行时往盒子里存、取东西,名字不变、内容可变,方便反复使用。
A variable is a named box holding a value that can change—numbers, text, etc. The program stores and reads from it; the name stays, the content varies, easing reuse.
难度 专业 · 适合 初中(12-15) CC BY 4.0 · 已核验 · Verified 2026-08-23
来源 · Source

Charles Petzold,《Code: The Hidden Language of Computer Hardware and Software》第2版,Microsoft Press,2022

C. Petzold, Code, 2nd ed., Microsoft Press, 2022; Chinese ed.《编码》

#变量 #存储 #编程

什么是“开源硬件”(如树莓派)?

What is 'open-source hardware' like Raspberry Pi?

开源硬件把电路设计和零件清单公开,谁都能照着做、改、学。树莓派就是一块便宜的小电脑板,常用来学编程、做机器人,因为资料全、门槛低。
Open-source hardware publishes its circuit designs and parts list so anyone can build, modify and learn. Raspberry Pi is a cheap mini-board for learning coding and robots—full docs, low barrier.
难度 专业 · 适合 高中(15-18) CC BY 4.0 · 已核验 · Verified 2026-08-23
来源 · Source

Charles Petzold,《Code: The Hidden Language of Computer Hardware and Software》第2版,Microsoft Press,2022

C. Petzold, Code, 2nd ed., Microsoft Press, 2022; Chinese ed.《编码》

#开源硬件 #树莓派 #DIY

“算法”和“程序”有什么不同?

How do 'algorithm' and 'program' differ?

算法是解决问题的思路或步骤(比如怎么排序),程序是把算法用某种语言真正写出来、能在电脑上跑的代码。先有思路,再写成程序。
An algorithm is the idea or steps to solve a problem (how to sort); a program is that algorithm written in a language and runnable on a computer. Idea first, then code.
难度 专业 · 适合 初中(12-15) CC BY 4.0 · 已核验 · Verified 2026-08-23
来源 · Source

Charles Petzold,《Code: The Hidden Language of Computer Hardware and Software》第2版,Microsoft Press,2022

C. Petzold, Code, 2nd ed., Microsoft Press, 2022; Chinese ed.《编码》

#算法 #程序 #区别

为什么有人愿意免费写开源代码?

Why do people write open-source code for free?

有人为了学本事、有人想解决自己的问题顺手分享,也有公司靠周边服务赚钱。社区里互相帮忙、署名和成就感,让很多人乐意免费贡献。
Some learn, some solve their own problem and share, some companies earn from related services. Mutual help, credit and satisfaction keep many contributing for free.
难度 专业 · 适合 初中(12-15) CC BY 4.0 · 已核验 · Verified 2026-08-23
来源 · Source

Charles Petzold,《Code: The Hidden Language of Computer Hardware and Software》第2版,Microsoft Press,2022

C. Petzold, Code, 2nd ed., Microsoft Press, 2022; Chinese ed.《编码》

#开源 #社区 #动机

什么是“条件判断”(如果……就……)?

What is a 'conditional' (if… then…)?

条件判断让程序做选择:满足某个条件就走一条路,否则走另一条。比如“如果下雨就提醒带伞,否则不用”。这是让程序“会思考”的基本方式。
A conditional makes the program choose: if a condition holds, do one thing, else another—like 'if raining, remind umbrella'. It's how programs 'decide'.
难度 进阶 · 适合 大众 CC BY 4.0 · 已核验 · Verified 2026-08-23
来源 · Source

Charles Petzold,《Code: The Hidden Language of Computer Hardware and Software》第2版,Microsoft Press,2022

C. Petzold, Code, 2nd ed., Microsoft Press, 2022; Chinese ed.《编码》

#条件 #判断 #逻辑

编程里的“函数”像食谱里的步骤吗?

Is a programming 'function' like a step in a recipe?

很像。函数把一段常用操作打包,起个名,需要时喊一声就执行,还能传入不同材料(参数)做出不同结果。比如“加水(杯数)”就能重复用。
Very much. A function packs a reusable action under a name; call it and it runs, taking inputs (parameters) for different results—like 'addWater(cups)' reused anywhere.
难度 进阶 · 适合 初中(12-15) CC BY 4.0 · 已核验 · Verified 2026-08-23
来源 · Source

Charles Petzold,《Code: The Hidden Language of Computer Hardware and Software》第2版,Microsoft Press,2022

C. Petzold, Code, 2nd ed., Microsoft Press, 2022; Chinese ed.《编码》

#函数 #复用 #编程

什么是“调试”(debug)?

What is 'debugging'?

调试就是找出并修好程序里的 bug。像侦探一样,看哪里出错、为什么出错,再改代码让程序正常。写代码一半时间可能都在调试。
Debugging finds and fixes bugs—like a detective spotting what broke and why, then editing code. Half of coding time can be debugging.
难度 进阶 · 适合 初中(12-15) CC BY 4.0 · 已核验 · Verified 2026-08-23
来源 · Source

Charles Petzold,《Code: The Hidden Language of Computer Hardware and Software》第2版,Microsoft Press,2022

C. Petzold, Code, 2nd ed., Microsoft Press, 2022; Chinese ed.《编码》

#调试 #bug #排错

编程里的“循环”是什么?

What is a 'loop' in programming?

循环是让电脑把同一件事重复做很多次,不用你一句句写。比如“把 1 到 100 都加一遍”,写个循环比抄一百行省力多了。
A loop repeats an action many times without writing it out. To 'add 1 through 100', a loop beats typing a hundred lines.
难度 进阶 · 适合 初中(12-15) CC BY 4.0 · 已核验 · Verified 2026-08-23
来源 · Source

Charles Petzold,《Code: The Hidden Language of Computer Hardware and Software》第2版,Microsoft Press,2022

C. Petzold, Code, 2nd ed., Microsoft Press, 2022; Chinese ed.《编码》

#循环 #重复 #编程

为什么程序员要在代码里写“注释”?

Why do programmers write 'comments' in code?

注释是写给读代码的人看的说明,电脑会跳过它不执行。它能讲清这段代码想干啥,半年后自己或同事一看就懂,省得猜。
Comments are notes for human readers; the computer ignores them. They explain what code intends, so you or a teammate understand it months later without guessing.
难度 进阶 · 适合 大众 CC BY 4.0 · 已核验 · Verified 2026-08-23
来源 · Source

Charles Petzold,《Code: The Hidden Language of Computer Hardware and Software》第2版,Microsoft Press,2022

C. Petzold, Code, 2nd ed., Microsoft Press, 2022; Chinese ed.《编码》

#注释 #代码 #协作

学编程一定要先学好数学吗?

Must you be good at math before learning to program?

入门做网站、小游戏,普通加减乘除就够。但做图形、AI、加密这些,数学会帮大忙。所以先能写、再按需补数学,不用被吓退。
For websites and simple games, basic arithmetic suffices. Graphics, AI and crypto need more math. Start coding, then learn math as needed—don't be scared off.
难度 进阶 · 适合 初中(12-15) CC BY 4.0 · 已核验 · Verified 2026-08-23
来源 · Source

Charles Petzold,《Code: The Hidden Language of Computer Hardware and Software》第2版,Microsoft Press,2022

C. Petzold, Code, 2nd ed., Microsoft Press, 2022; Chinese ed.《编码》

#编程 #数学 #入门

游戏里的“外挂/作弊代码”是用代码改游戏吗?

Are game 'cheats' made by changing code?

是的,外挂常利用或改写游戏代码,让自己刀枪不入、看穿墙壁,破坏了公平。多数游戏会封号,所以作弊既不对也不划算。
Yes, cheats exploit or alter game code for invincibility or x-ray vision, breaking fairness. Most games ban such accounts, so cheating is both wrong and risky.
难度 入门 · 适合 大众 CC BY 4.0 · 已核验 · Verified 2026-08-23
来源 · Source

Charles Petzold,《Code: The Hidden Language of Computer Hardware and Software》第2版,Microsoft Press,2022

C. Petzold, Code, 2nd ed., Microsoft Press, 2022; Chinese ed.《编码》

#外挂 #游戏 #代码

「橡皮鸭调试法」是什么,对着一只玩具鸭子讲话为什么真能找出 bug?

What is rubber duck debugging, and why does explaining code to a toy duck actually find bugs?

做法很简单:把代码逐行讲给桌上的橡皮鸭,或者任何不会回话的东西听,要求把每一步打算做什么说清楚。人在心里默读代码时会自动跳过和补全细节,一旦被迫用自然语言说出来,隐含假设就必须变成明确的句子,你以为成立的前提和实际写下的逻辑之间的差距随之暴露。这个名字出自《The Pragmatic Programmer》里的一则轶事,而同事之间「刚讲一半就自己想通了」的现象正是同一个原理。
The method is literally to explain your code line by line to a rubber duck on your desk — or anything else that cannot answer — stating aloud what each step is supposed to accomplish. Reading code silently, the mind skims and auto-completes; forcing it into natural language turns hidden assumptions into explicit sentences, and the gap between what you believed the code does and what it actually does becomes visible. The name comes from an anecdote in the book "The Pragmatic Programmer", and it is the same mechanism behind solving a problem halfway through describing it to a colleague.
难度 入门 · 适合 小学低段(6-8) CC BY 4.0 · 已核验 · Verified 2026-11-03
来源 · Source

Andrew Hunt 与 David Thomas《The Pragmatic Programmer》(1999) 第 3 章 Debugging 一节

Andrew Hunt & David Thomas, "The Pragmatic Programmer" (1999), ch. 3, on debugging

#橡皮鸭调试 #调试方法 #显式表达 #认知偏差

程序员数东西为什么常常从 0 开始,而不是从 1 开始?

Why do programmers usually start counting from 0 instead of 1?

数组下标从 0 开始时,元素地址正好等于起始地址加上下标乘元素大小,不用每次减一,早期语言这样设计既省一次运算也贴近硬件寻址方式。更重要的是它让区间表示变漂亮:用含头不含尾的 [0, n) 表示 n 个元素,长度恰好等于 n,两个相邻区间 [0,k) 与 [k,n) 首尾正好衔接、既不重叠也不留缝,切片和循环边界都不容易写错。Dijkstra 在 1982 年一篇短文里正是用这个论证说明从零开始最自然。
With zero-based indexing an element's address is exactly the base address plus index times element size, with no subtraction, which saved an operation and matched hardware addressing in early languages. The deeper reason is that it makes ranges elegant: writing n elements as the half-open interval [0, n) makes the length exactly n, and two adjacent ranges [0, k) and [k, n) meet with neither overlap nor gap, so slices and loop bounds are far harder to get wrong. Dijkstra made precisely this argument in a short 1982 note titled "Why numbering should start at zero".
难度 入门 · 适合 小学低段(6-8) CC BY 4.0 · 来源待核验 · Source pending review
来源 · Source

出处备注:著录含书名,但缺版次 / 出版社 / 年份中的一部分,需编辑补全后才能做独立比对。

Edsger W. Dijkstra《Why numbering should start at zero》(手稿 EWD 831, 1982)

Edsger W. Dijkstra, "Why numbering should start at zero" (manuscript EWD 831, 1982)

#零基索引 #半开区间 #数组下标 #编程约定

什么是“黑客”,他们都是坏人吗?

What is a 'hacker', and are they all bad?

黑客原指爱钻研技术、找系统漏洞的人。有人用来做好事(帮公司找漏洞),也有人用来干坏事(偷东西),后者更准确叫“黑帽”。所以不能一概说黑客是坏人。
A hacker originally means someone who tinkers and finds system flaws. Some do good (report bugs); some do harm (theft)—better called 'black hats'. So not all hackers are bad.
难度 入门 · 适合 大众 CC BY 4.0 · 已核验 · Verified 2026-08-23
来源 · Source

Charles Petzold,《Code: The Hidden Language of Computer Hardware and Software》第2版,Microsoft Press,2022

C. Petzold, Code, 2nd ed., Microsoft Press, 2022; Chinese ed.《编码》

#黑客 #安全 #误解

什么是“编程语言”?

What is a 'programming language'?

编程语言是人和电脑之间的“共同语言”,像 Python、Scratch。它比日常话更死板、更讲规矩,电脑才能准确照做。不同语言适合不同活。
A programming language is a shared language between people and computers, like Python or Scratch. Stricter than speech so the computer follows exactly; different ones suit different jobs.
难度 入门 · 适合 小学低段(6-8) CC BY 4.0 · 已核验 · Verified 2026-08-23
来源 · Source

Charles Petzold,《Code: The Hidden Language of Computer Hardware and Software》第2版,Microsoft Press,2022

C. Petzold, Code, 2nd ed., Microsoft Press, 2022; Chinese ed.《编码》

#编程语言 #代码 #基础

学编程的第一个程序为什么几乎总是打印一句「hello, world」?

Why is the very first program in almost every course one that prints hello, world?

这个惯例来自贝尔实验室:Brian Kernighan 在 1972 年为 B 语言写的教程里首次用它做例子,1978 年 Kernighan 与 Ritchie 的《The C Programming Language》把它放在全书第一页,随 C 语言传遍全世界。它之所以合适,是因为它是最小的端到端验证:这句话能打印出来,就说明编译器、链接器、运行环境和输出通道全都配好了;万一失败,可能的原因也少得可以逐一排查。今天几乎所有语言的入门文档仍沿用它,本质上是一次环境自检。
The convention began at Bell Labs: Brian Kernighan first used it in a 1972 tutorial for the language B, and the 1978 Kernighan and Ritchie book on C put it on the opening page, from which it spread worldwide along with the language. It works so well because it is the smallest possible end-to-end check: if the line appears, the compiler, linker, runtime and output path are all correctly configured, and if it fails the set of possible causes is small enough to check one by one. Nearly every language's getting-started guide still opens with it, essentially as an environment smoke test.
难度 入门 · 适合 小学高段(9-12) CC BY 4.0 · 已核验 · Verified 2026-11-03
来源 · Source

Kernighan 与 Ritchie《The C Programming Language》(1978) 第 1 章;Kernighan《A Tutorial Introduction to the Language B》(Bell Laboratories, 1972)

Kernighan & Ritchie, "The C Programming Language" (1978), ch. 1; Kernighan, "A Tutorial Introduction to the Language B," Bell Laboratories (1972)

#hello world #入门程序 #C语言 #环境验证

机器人能自己写程序吗?

Can a robot write its own programs?

现在有些聪明的 AI 能根据要求写出简单代码,但大多还要人检查、修改。真正“完全自己发明程序”的机器人还没有,人还是总指挥。
Some smart AI can write simple code from a request, but a human still checks and fixes it. No robot fully invents programs alone yet—people stay in charge.
难度 入门 · 适合 幼儿(3-6) CC BY 4.0 · 已核验 · Verified 2026-08-23
来源 · Source

Charles Petzold,《Code: The Hidden Language of Computer Hardware and Software》第2版,Microsoft Press,2022

C. Petzold, Code, 2nd ed., Microsoft Press, 2022; Chinese ed.《编码》

#AI #代码 #机器人

什么是“bug”(程序里的小虫子)?

What is a 'bug' in a program?

bug 就是程序写错了,导致它做错事或卡住,比如游戏突然闪退。程序员要找出 bug 修好它,让程序乖乖听话。
A bug is a mistake in the program that makes it misbehave or freeze, like a game crashing. Programmers find and fix bugs so the program behaves.
难度 入门 · 适合 幼儿(3-6) CC BY 4.0 · 已核验 · Verified 2026-08-23
来源 · Source

Charles Petzold,《Code: The Hidden Language of Computer Hardware and Software》第2版,Microsoft Press,2022

C. Petzold, Code, 2nd ed., Microsoft Press, 2022; Chinese ed.《编码》

#bug #错误 #调试

什么是“代码”?

What is 'code'?

代码是用编程语言写给电脑看的“说明书”,一行行告诉它该做什么。人把想法写成代码,电脑照着做,于是有了游戏、App 和网站。
Code is a set of instructions written in a programming language telling the computer what to do. People write code; computers follow it to make games, apps and websites.
难度 入门 · 适合 大众 CC BY 4.0 · 已核验 · Verified 2026-08-23
来源 · Source

Charles Petzold,《Code: The Hidden Language of Computer Hardware and Software》第2版,Microsoft Press,2022

C. Petzold, Code, 2nd ed., Microsoft Press, 2022; Chinese ed.《编码》

#代码 #编程 #基础