Programming paradigms
導入済み
13:52
プログラミングのパラダイム
ここで一つのタスクがあります:A gradeを取得した生徒をすべてリストアップすることです。あるプログラマーはループを書きます——最初のレコードから始め、gradeを確認し、名前をリストに加え、移動します…
英語のナレーション・英語と中国語の字幕を切り替え可能
このレッスンの内容
| English | 意味 |
|---|---|
| loop/luːp/ | A structure that repeats a sequence of instructions. |
| array/əˈreɪ/ | An indexed collection of elements arranged in one or more dimensions. |
| filter/ˈfɪltə/ | A function that selects items from a collection using a given condition. |
| state/steɪt/ | The saved information needed to continue a program from its current point. |
| rule/ruːl/ | A logic-program statement deriving a conclusion when its conditions hold. |
| SQL/ˌes kjuː ˈel/ | Structured Query Language, used to define, query and manipulate data in relational databases. |
| index/ˈɪndeks/ | A position marker or lookup structure used to locate data within a collection or database. |
| cores/kɔːz/ | Independent processing units within a processor that can execute instructions. |
| paradigm/ˈpærədaɪm/ | パラダイム |
| low-level/ləʊ ˈlevl/ | 低レベル |
| imperative/ɪmˈperətɪv/ | 命令型 |
| declarative/dɪˈklærətɪv/ | 宣言型 |
| hardware/ˈhɑːdweə/ | The physical parts of a computer system that can be touched. |
| machine code/məˈʃiːn kəʊd/ | Instructions encoded in binary form that a processor can execute directly. |
| assembly language/əˈsemblɪ ˈlæŋɡwɪdʒ/ | A low-level programming language using symbolic names for machine instructions and their operands. |
| direct/daɪˈrekt/ | An addressing method where the instruction contains the memory address of the data. |
| registers/ˈredʒɪstəz/ | A small, fast storage location within a processor used to hold data, addresses or instructions temporarily. |
| memory addresses/ˈmeməri əˈdresɪz/ | Identifiers of locations in an addressable memory space, used to access stored instructions or data. |
| instructions/ɪnˈstrʌkʃnz/ | Commands that tell a computer what actions to perform. |
| memory/ˈmeməri/ | The part of a computer that holds data and programs currently in use. |
| processor/ˈprəʊsesə/ | The component that executes instructions and performs the operations of a computer or similar system. |
| device drivers/dɪˈvaɪs ˈdraɪvəz/ | Programs that allow an operating system to control hardware devices. |
| firmware/ˈfɜːmweə/ | Software stored in a device to control its hardware and basic operation. |
| embedded controllers | Computers built into larger devices to control their operation. |
| real-time system | A system that must respond to events within a required time. |
| immediate/ɪˈmiːdɪət/ | An addressing method where the data value is part of the instruction. |
| indirect/ɪndaɪˈrekt/ | An addressing method where the given address holds the address of the data. |
| indexed/ˈɪndekst/ | An addressing method that adds an index value to an address to find the data. |
| relative addressing/ˈrelətɪv əˈdresɪŋ/ | An addressing mode that adds an offset to the program counter. |
| operand/ˈɒpərænd/ | A value, register or memory location that an instruction operates on. |
| procedural/prəˈsiːdʒərəl/ | Describes programming that uses a sequence of commands to change program state. |
| sequence/ˈsiːkwəns/ | A set of things arranged in a particular order. |
| commands | Instructions that tell a computer or program to perform actions. |
| assignments | Statements that give values to variables in a program. |
| conditionals | Statements that choose which actions to perform based on a condition. |
| procedures | Named sets of instructions that perform tasks when called. |
| variables/ˈveərɪəblz/ | A quantity or named value that can change or take different values. |
| pseudocode/ˈsuːdəʊkəʊd/ | A language-independent description of an algorithm using structured, programming-like statements. |
| runtime | The software environment that manages and carries out a program while it runs. |
| Functional/ˈfʌŋkʃənl/ | Describes programming that builds results by combining functions. |
| pure functions/pjʊə ˈfʌŋkʃnz/ | 純粋関数 |
| side effects/saɪd ɪˈfekts/ | Observable effects beyond a routine's returned value, such as modifying an argument, changing shared state or writing output. |
| Logic/ˈlɒdʒɪk/ | Describes programming that uses facts and rules to answer questions. |
| facts/fækts/ | Statements treated as true within a logic program. |
| engine | Software that uses facts and rules to work out answers to queries. |
| inference/ˈɪnfərəns/ | The use of a trained model to make a prediction from new input. |
| query/ˈkwɪərɪ/ | A request to retrieve or manipulate information, especially data in a database. |
| rows | Horizontal lines in a table, each containing one record. |
| database/ˈdeɪtəbeɪs/ | An organised collection of data that can be accessed and managed. |
| memory locations | Places in memory where data is stored, each identified by an address. |
| data transformation | The process of changing data from one form into another. |
| parallel/ˈpærəlel/ | Describing operations that take place concurrently rather than one after another. |
| cached | Stored for a time so that it can be used again quickly. |
| global variable/ˈɡləʊbl ˈveərɪəbl/ | A variable declared outside a routine's local scope and accessible wherever the language's program or module scope rules permit. |
| bugs/bʌɡz/ | Mistakes in software that can make it work incorrectly. |
同一プログラムを4つの方法で記述
- イギリスの全顧客を取得する場合、Cプログラマは配列に対するループを記述する。Haskellプログラマはフィルタを記述する。Prologプログラマはルールを宣言してクエリを発行する。SQLユーザーは
SELECT * FROM Customer WHERE Country = 'UK'を記述する。 - 最初の手法だけがどのように行うかを指定する。他の手法は何が望まれているかだけを指定し、実行環境に「どのように」を行うかを任せる。これにより、処理順序の再構成、インデックスの使用、または8コアでの並列実行が可能になる。
- 一般的にどちらが優れているわけではない。異なるのは、どの意思決定を言語側が代行するかであり、これがまさにパラダイムとは何かである。
- このレッスンはシラバスで名称されるパラダイムである:低レベル、命令形( Imperative)、および**宣言形(Declarative)**である。

低レベルプログラミング
- 低レベルプログラミングは、機械語またはアセンブリ言語を用いてハードウェアに近い操作を行い、レジスタ、メモリアドレス、個別の命令への直接アクセスを可能にする。
- 利点: 最大限の制御性と速度、そして可能な限り小さなコードです。メモリが数キロバイトしかない場合に重要です。
- 欠点: アーキテクチャ固有であるため、異なるプロセッサでは書き直しが必要であり、記述に時間がかかり、保守も困難である。
- ハードウェアを正確に指令する必要がある場所、すなわちデバイスドライバ、ファームウェア、組み込みコントローラ、リアルタイムシステムの最も内側のループなどで使用される。
- アセンブリ言語のレッスンにおいて、即座の、直接的な、間接的な、インデックス付き、および相対的なアドレス指定を練習してください。そのトレース例は、同じ演算子でも異なる結果が生じる理由を示しています。

Which are true of low-level programming? Select すべて that apply.
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
Control is bought with effort: assembly is slow to write and hard to maintain, which is why it is confined to drivers and firmware.
命令形プログラミング
- 命令形プログラミング(手続型とも呼ばれる)は、代入、条件分岐、ループ、手続き呼び出しといったプログラムの状態を変更する一連の命令である。
- プログラマは、結果がどのように計算されるかを段階的に指定する。状態を保持する変数がその中心となる。
- Python、C、Java、擬似コードのスタイルであり、ほぼすべての人が最初に学ぶものである。

一つ一つの命令が格納されている内容を変えていく

Imperative (procedural) programming is based on:
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Imperative code gives step-by-step commands (assignments, loops, calls) that change state.
宣言形プログラミング
- 宣言形プログラミングは、どうやってではなく何が計算されるべきかを宣言する。実行環境がステップを決定する。
- 関数型プログラミングは、副作用のない純粋関数を組み合わせる。同じ入力に対して常に同じ出力が得られ、関数外では何も変化しない。HaskellとLispがその例である。
- ロジックプログラミングは事実とルールを宣言し、エンジンが推論によってクエリに回答する。Prologがその例である。
- SQLは、ほとんどの人が接したことがある宣言形言語である。クエリはどの行が必要かを指定し、データベースがどう見つけるかを決定する。
Programming concept lab
Connect examples to the programming idea they show.
Declarative programming means you specify:
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Declarative code (functional, logic, SQL) states the goal; the runtime decides the steps.
A pure function (functional programming):
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Purity means no side effects and a deterministic result, which makes functional code easy to reason about.
Declarative paradigms (functional, logic, SQL) state WHAT to compute and let the runtime decide how, whereas imperative code spells out every step.
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
A SQL query says which rows you want, not how to scan the tables — the opposite of step-by-step imperative code.
A pure function always gives the same output for the same input and has no ____.
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
That is what lets it be tested in isolation, run in parallel safely and have its result cached.
演習例:パラダイムの特定
FOR i ← 1 TO n : total ← total + A[i] : NEXT i— 命令形:totalに保持される状態を変化させる一連の命令である。SELECT Name FROM Customer WHERE Country = 'UK'— 宣言形: どの行が必要かを指定しているだけで、検索方法を指定していない。LDD 200 : ADD 201 : STO 202— 低レベル: メモリ位置に直接アクセスするアセンブリ命令である。parent(X, Y) :- father(X, Y).— 宣言形、具体的にはロジックプログラミング: エンジンが推論によって答えを導き出すルールである。- パラダイムを名指しし、それが示唆されるコードの特徴を記述せよ。
Match each fragment to its paradigm.
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
Commands changing state, a statement of what is wanted, instructions addressing memory, and a rule for inference.
比較
| パラダイム | 宣言内容 | 強み | 典型的な用途 |
|---|---|---|---|
| 低レベル | 正確な指示 | 制御、速度、サイズ | ドライバ、ファームウェア |
| 命令形 | 如何、段階的に | 直接的で親しみやすい | 一般的なプログラミング |
| 宣言形 | 何が望ましいか | 簡潔、実行環境が最適化する | クエリ、ルール、データ変換 |
- 現代の言語はこれらを混合する。Pythonは命令形だが関数的特徴を持ち、SQLは命令形で記述されたプログラム内に存在する。パラダイムはスタイルであり、壁ではない。
Match each paradigm to its core idea.
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
Imperative says how step by step; OO models objects; functional uses pure functions; declarative states the goal.
What is the essential difference between imperative and declarative programming?
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Because the declarative version does not fix the how, the runtime may reorder the work, use an index or parallelise it.
演習例:副作用の重要性
- 純粋関数は副作用を持たない。その利点の一つを説明せよ。
- 同じ入力で常に同じ出力が得られ、外部で何も変化しないため、純粋関数は孤立してテストできる。セットアップや整えるべき隠れた状態がないからである。
- また、2つの呼び出しが互いに干渉できないため、並列に安全に実行でき、その結果をキャッシュすることも可能である。
- 対照的に、グローバル変数を更新する命令形ルーチンは、以前に実行された内容によって挙動が変わり、これが此类のバグの発見を困難にする要因となる。

見落としやすいポイント
- 命令形は如何を、宣言形は何がを指定する。この対比が本問の多くの解答である。
- 低レベルの欠点は「古い」ことではなく、アーキテクチャ固有であることや保守の難しさである。
- 純粋関数は副作用を持たず、同じ入力に対して同じ出力を与える。両方の条件が必要である。
- SQLは宣言形である。試験で最も頻繁に例として用いられるため、認識しておくこと。
理解できましたか
- パラダイムはコードを構造化するスタイルであり、現代の言語は複数のものを混合する。
- 低レベル: 機械語またはアセンブリ、ハードウェアへの直接アクセス、最大限の制御と速度、ただしアーキテクチャ固有で保守が難しい。
- 命令形: 状態を変化させる命令の一連の操作、如何を指定する。Python、C、擬似コードのスタイル。
- 宣言形: 何が望ましいかを宣言し、如何を実行環境に任せる。関数型プログラミングの純粋関数、ロジックプログラミングの事実とルール、SQLなど。
何が問題でしたか?この内容はサイトの運営チームだけが確認します。