Developing Procedures
導入済み
9:10
アルゴリズムとプログラミング
1百万名の名前が入った電話帳を想像し、その中から1人を見つける必要があるとしよう。一つずつ確認していくと、一日中かかってしまうかもしれない。約…で見つける方法がある。
英語のナレーション・英語と中国語の字幕を切り替え可能
このレッスンの内容
| English | 意味 |
|---|---|
| define/dɪˈfaɪn/ | 定義する |
| parameters/pəˈræmɪtəz/ | 形式引数 |
| procedural abstraction/prəˈsiːdʒərəl əbˈstrækʃn/ | 手続抽象化 |
| readability/ˌriːdəˈbɪlɪti/ | 可読性 |
| duplication/ˌdjuːplɪˈkeɪʃn/ | コードの重複 |
独自のプロシージャの作成
- 独自のプロシージャを作成することは、プログラミングの基本的なスキルです。
- プロシージャを定義するには、明確な名前、パラメータ、そして指示のBodyを与えます。
- その後、そのタスクが必要な場所どこでも呼び出せる。
- 良いプロシージャは 1つ の明确な作业のみを行います。
To define a procedure you give it:
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Those three parts make a reusable procedure.
このカードは修正されたため、翻訳が更新されるまで英語で表示されます。
Parameters give flexibility
- Use parameters 形参 so a procedure can work with different input values.
greet(name)can greet anyone, because the caller supplies the name each time.- Without parameters, a procedure could obtain the name in another way, such as from user input.
- Parameters are what make one procedure reusable across many cases.

Decomposing a program into procedures and sub-procedures
Good candidate for a procedure?
Extract a procedure when a chunk of work has one clear purpose or repeats in several places; a unique one-off line does not need its own procedure.
Why does greet(name) use a parameter?
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
The caller supplies a different name each call.
Hiding the implementation details of a procedure behind its name and parameters is ______ abstraction.
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Procedural abstraction keeps big programs manageable.
このカードは修正されたため、翻訳が更新されるまで英語で表示されます。
Procedural abstraction
- Procedures support procedural abstraction 过程抽象 by hiding implementation details behind an interface; they also help break a large problem into smaller, manageable parts.
- Each part becomes a procedure with one clear job.
- You reason about the small parts, not the whole tangled program at once.
- This is how large programs stay understandable.
Putting repeated code inside one procedure mainly reduces:
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
One procedure replaces many copies of the same lines.
With a greet procedure, changing the greeting means editing one place, not three.
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Fewer places to edit means fewer chances for errors.
A well-named procedure like calculateTax() helps a reader understand the intent quickly.
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Good names improve readability and reuse.
二つの大きな利点
- 適切な名前が付けられたプロシージャは、可読性と再利用性を向上させます。読み手は
calculateTax()を見るだけで意図を理解できます。 - 繰り返しコードをプロシージャにまとめると、重複を減らせます。
重複の除去。 プログラムが同じ3行分の挨拶を3箇所で印刷している場合、それは重複である。それらを含む1つのgreet(name)を定義すれば、各箇所では単一の呼び出しで済む:greet("Ana")、greet("Bo")、greet("Cy")。挨拶を変更するのは一度だけで済み、3回繰り返す必要がない。
プロシージャを定義するには、名前、パラメータ、および本体を与えます。パラメータを使うことで、1つのプロシージャで多くの入力を処理できます(例:greet(name))。これは手続的抽象化であり、問題を小さなタスクに分割することを意味します。メリットは、より良い可読性と重複の減少です(多数のコピーではなく、1つのプロシージャを編集するだけ)。
何が問題でしたか?この内容はサイトの運営チームだけが確認します。