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'. - فقط الأول يقول كيف القيام بذلك. والباقي يقولون ماذا هو مطلوب ويتركون الطريقة للجهاز، وهو حر لإعادة ترتيب العمل، أو استخدام فهرس، أو تشغيله على ثمانية أنوية.
- لا يوجد منهما أفضل بشكل عام. الاختلاف يكمن في القرارات التي تسحبها اللغة منك، وهذا بالضبط ما يعنيه النمط البرمجي.
- هذه الدرس هي الأنماط البرمجية التي يسميها المنهج الدراسي: منخفض المستوى، الأمرية والإعلانية.

البرمجة منخفضة المستوى
- البرمجة منخفضة المستوى تعمل قريبًا من الأجهزة الصلبة، في كود الآلة أو لغة التجميع، مع وصول مباشر إلى المسجلات وعناوين الذاكرة والتعليمات الفردية.
- فوائد: أقصى تحكم وسرعة، وأصغر كود ممكن، وهو أمر مهم عندما يكون هناك كيلوبايتات فقط من الذاكرة.
- عيوب: إنه محدد للمعمارية، لذا يجب إعادة كتابته لمعالج مختلف، وهو بطيء الكتابة وصعب الصيانة.
- يستخدم حيث يجب توجيه الأجهزة الصلبة بدقة: تعريفات الأجهزة، البرمج الثابتة، المتحكمات المدمجة، والحلقة التكرارية الداخلية لأنظمة الوقت الفعلي.
- تدرب على التح addressing المباشر وغير المباشر والمؤشر والنسبي في درس لغة التجميع. يظهر تتبع الأمثلة المحلولة لماذا يمكن أن ينتج نفس المعامل نتائج مختلفة.

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.
البرمجة الأمرية
- البرمجة الأمرية، المعروفة أيضًا بالإجرائية، هي تسلسل من الأوامر التي تغير حالة البرنامج: assignments (التعيينات)، شروط if، حلقات تكرار واستدعاءات للوحدات الفرعية.
- يحدد المبرمج كيف سيتم حساب النتيجة، خطوة بخطوة. المتغيرات التي تحمل الحالة هي النقطة المحورية.
- إنه نمط 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.
مثال محلول: لماذا الآثار الجانبية مهمة
- الدالة النقية ليس لها آثار جانبية. اشرح فائدة واحدة.
- نظرًا لأن المدخلات نفسها تعطي دائمًا نفس المخرجات ولا شيء خارجي يتغير، يمكن اختبار الدالة النقية بعزل: بدون إعدادات مسبق، وبدون حالة مخفية لتنظيمها.
- يمكن أيضًا تشغيلها في متوازي بأمان، لأن الاستدعاءين لا يمكن أن يتداخلا مع بعضهما البعض، ويمكن تخزين نتيجتها في ذاكرة مؤقتة.
- التناقض: روتين أمرية تقوم بتحديث متغير عالمي تتصرف بشكل مختلف اعتمادًا على ما تم تشغيله قبلها، وهذا ما يجعل مثل هذه الأخطاء صعبة الكشف.

علامات ضائعة
- الأمرية تقول كيف؛ والإعلانية تقول ماذا. هذا التناقض هو إجابة معظم الأسئلة هنا.
- عيب منخفض المستوى هو أنه محدد للمعمارية وصعب الصيانة، وليس لأنه "قديم".
- الدالة النقية ليس لها آثار جانبية وتعطي نفس المخرجات للمدخلات نفسها. كلا الجزأين مطلوبان.
- SQL إعلانية. هو المثال الذي يستخدمه الامتحان أكثر من غيره، لذا اعرفه.
لقد فهمت الأمر
- النمط البرمجي هو أسلوب لهيكلة الكود، واللغات الحديثة تمزج عدة أنماط
- منخفض المستوى: كود الآلة أو التجميع، وصول مباشر للأجهزة الصلبة، أقصى تحكم وسرعة، لكنه محدد للمعمارية وصعب الصيانة
- أمرية: تسلسل من الأوامر يغير الحالة، يحدد كيف؛ نمط Python وC والكود الوهمي
- إعلانية: تنص على ماذا مطلوب وتترك الطريقة لوقت التشغيل، كما في البرمجة الوظيفية بـ الدوال النقية، والبرمجة المنطقية بالحقائق والقواعد، وSQL
ما المشكلة؟ لا يرى ذلك سوى فريق الموقع.