Programming paradigms
הוצג
13:52
פרדיגמות תכנות
הנה משימה אחת: רשימת כל התלמידים עם ציון A. תוכנתן כותבת לולאה — מתחילה מהרקורד הראשון, בודוק את הציון, הוסף את השם לרשימה, עבור…
קריינות באנגלית · כתוביות באנגלית ובסינית 中文 שאפשר להחליף ביניהן
בשיעור הזה
| 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. |
אותו תוכנית, כתובה בארבעה אופנים
- לבקש את כל הלקוחות בבריטניה ופרוגרמר C כותב לולאה על מערך. פרוגרמר Haskell כותב פילטר. פרוגרמר Prolog מגדיר כלל ושואל שאלה. משתמש SQL כותב
SELECT * FROM Customer WHERE Country = 'UK'. - רק הראשון אומר איך לעשות זאת. האחרים אומרים מה נדרש ומשאירים את ה"איך" למכונה, שיכולה לחזור על סדר העבודה, להשתמש באינדקס או לייצר אותה בשמונה ליבות.
- אף אחד מהם אינו טוב יותר באופן כללי. מה שמשתנה הוא אילו החלטות השפה לוקחת ממך, והעניין הוא בדיוק מהו פאראדיגמה.
- שיעור זה עוסק בפאראדיגמות שהסילבוס מציין: נמוכה-רמה, אימפרטיבית ו-דקלארטיבית.

תכנות נמוך-רמה
- תכנות נמוך-רמה עובד קרוב ל-hardware, בקוד מכונה או בשפת אסמבלר, עם גישה ישירה לרישומים, כתובות זיכרון והוראות יחידיות.
- יתרונות: בקרה מקסימלית ומהירות, וגודל קוד מינימלי ככל האפשר, דבר שחשוב כאשר יש רק קילובייטים של זיכרון.
- חסרונות: היא ספציפית לארכיטקטורה, ולכן יש לכתוב מחדש עבור מעבד אחר, והיא איטית בכתיבה וקשה בתחזוקה.
- משמשת במקום שבו יש לפקד את ה-hardware במדויק: דרייברים, firmware, בקרים מובנים ולולאה הפנימית ביותר של מערכת בזמן אמת.
- תרגלו כתובות מידיות, ישירות, עקיפות, אינדקסיות ויחסיות בשיעור שפת האסמבלי. הניתוח המפורט שלו מראה מדוע אותה ארגומנט יכול לייצר תוצאות שונות.

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 ו-pseudocode, והוא מה שכמעט כולם לומדים תחילה.

הוראה אחרי הוראה, כל אחת משנה מה שנשמר

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.
דוגמה מופת: למה אפקטים משניים חשובים
- פונקציה טהורה אין לה אפקטים משניים. הסבר יתרון אחד.
- מכיוון שאותו קלט תמיד נותן אותו תוצאה ואין שינוי בחוץ, פונקציה טהורה ניתנת לבדיקה בידוד: ללא הכנה, ללא מצב נסתר לסידור.
- היא יכולה גם לרץ ב-מקביל בבטחה, מכיוון ששתי קריאות לא יכולות להתערב אחת בשנייה, ותוצאתה ניתנת לשמירה במטאבוקס (cache).
- ההבדל: שגרת אימפרטיבית שעדכנית משתנה גלובלית מתנהגת אחרת בהתאם למה רץ לפניה, וזה מה שהופך באגים כאלה לקשים לאיתור.

סימונים נופלים מהיד
- אימפרטיבי אומר איך; דקלרטיבי אומר מה. הבדל זה הוא התשובה לרוב השאלות כאן.
- החיסרון של נמוך-רמה הוא שהוא תלוי בארכיטקטורה וקשה לתחזוקה, ולא שהוא "ישן".
- פונקציה טהורה אינה גורמת לתוצרי לוואי ומחזירה את אותו תוצר עבור אותה קלט. שני החלקים נדרשים.
- SQL היא דקלראטיבית. זו הדוגמה שהמבחן משתמש בה הכי הרבה, לכן זיהו אותה.
הבנתך מושלמת
- פרדיגמה היא סגנון במבנה הקוד, ושפות מודרניות משלבות מספר פרדיגמות
- רמת-תחתונה: קוד מכונה או אסמבלי, גישה ישירה לחומרה, שליטה ומהירות מקסימליות, אך תלויות בארכיטקטורה וקשות לתחזוקה
- אימפרטיבית: רצף של פקודות המעבירות מצב, המפרש איך; הסגנון של Python, C וקוד פסאודו
- דקלראטיבית: מציגה מה נדרש ומשאירה את ה"איך" למערכת ההפעלה, כפי שמופיע בתכנות פונקציונלי עם פונקציות טהורות, תכנות לוגיקלי עם עובדות וחוקים, וב-SQL
מה השתבש? רק צוות האתר רואה זאת.