05 - Anticipating and Dealing with Errors.pptx

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

Computational Thinking and Problem Solving (SE1101) Lecture 5: Anticipating and Dealing with Errors ‫توقع األخطاء‬ ‫والتعامل معها‬ Sabir I. Basnan 2024 ‫‪Recap‬‬ ‫التعرف‬ ‫على‬ ‫األنماط‬ ‫التحلـل‬ ‫التجريد‬ ‫...

Computational Thinking and Problem Solving (SE1101) Lecture 5: Anticipating and Dealing with Errors ‫توقع األخطاء‬ ‫والتعامل معها‬ Sabir I. Basnan 2024 ‫‪Recap‬‬ ‫التعرف‬ ‫على‬ ‫األنماط‬ ‫التحلـل‬ ‫التجريد‬ ‫التصميم‬ ‫الخوارزمي‬ Objectives Explain techniques for preventing errors being introduced into your solution ‫شرح التقنيات التي تمنع األخطاء التي قد تظهر‬. Discuss how to mitigate the effects of errors that are introduced. ‫مناقشة كيفية التخفيف من آثار األخطاء التي تظهر‬. Introduce a systematic approach to testing via top-down and bottom-up strategies. ‫تقديم نهج منظم لالختبار من خالل استراتيجيات‬ ‫من أعلى إلى أسفل ومن أسفل إلى أعلى‬. Objectives Show how to test individual parts of a solution in isolation. ‫إظهار كيفية اختبار أجزاء فردية من الحل بمعزل عن بعضها البعض‬. Discuss a number of debugging strategies. ‫مناقشة عدد من‬ ‫استراتيجيات التصحيح‬. Explain how to manage the bugs found in your solution. ‫شرح‬ ‫كيفية إدارة األخطاء التي تم العثور عليها في الحل الخاص بك‬. Bug and Error ‫األخطاء والخلل‬ Solutions you create will not work flawlessly. They will contain bugs somewhere, despite your very best efforts. Even the most talented programmers and computer scientists in the world produce software that contains bugs, even if some are loath to admit it. Bugs can be simple typos or major misunderstandings. ‫إن الحلول التي تبتكرها لن تعمل بشكل خاٍل‬ ‫ حتى أكثر المبرمجين وعلماء الكمبيوتر‬.‫ بل سيكون هناك أخطاء في مكان ما‬.‫من العيوب‬ ‫ حتى وإن كان البعض منهم يكرهون‬،‫موهبة في العالم ينتجون برامج تحتوي على أخطاء‬ ‫ كتابية بسيطة أو أخطاء سوء‬/ ‫ قد تكون األخطاء عبارة عن أخطاء مطبعية‬.‫االعتراف بذلك‬ ‫فهم كبيرة‬. Bug - a fault in a solution that can cause erroneous behaviour. Error - any behaviour observed when executing a solution that does not match the expected behaviour. Designing Out The Bugs ‫تصميم خاِل من الخلل‬ Various types of bugs can cause erroneous behaviour: Typos ‫األخطاء المطبعية‬ Poor grammar and ambiguities ‫ضعف القواعد النحوية والكلمات‬ ‫غير المفهومة‬ Inconsistencies ‫التناقضات‬ Logical and mathematical errors ‫األخطاء المنطقية والرياضية‬ Being exhaustive ‫الشمولية‬ Typos ‫األخطاء المطبعية‬ Your solution exists in various design forms, documents, notes, diagrams, and algorithm outlines. Any typos could cause problems. ‫يتوفر الحل الخاص بك في أشكال تصميم مختلفة ومستندات ومالحظات ومخططات‬ ‫ وأي أخطاء مطبعية قد تسبب مشاكل‬.‫ومخططات خوارزمية‬. Typos include: spelling errors; ‫أخطاء إمالئية‬ incorrect capitalisations; ‫أحرف كبيرة غير صحيحة‬ missing words; ‫كلمات مفقودة‬ wrong words (for example, ‘phase’ instead of ‘phrase’); ‫كلمات‬ ‫خاطئة‬ numbered lists with incorrect numbering, and so on. ‫قوائم مرقمة‬ ‫بترقيم غير صحيح‬ Poor grammar and ambiguities ‫ضعف‬ ‫القواعد النحوية والكلمات غير المفهومة‬ Some grammatical errors are quite subtle. ‫بعض األخطاء النحوية‬ ‫دقيقة للغاية‬. Example: After having a coin inserted, the user will be able to push the turnstile. What or who exactly is having a coin inserted here? Ambiguities can appear in sentences that are grammatically fine. ‫يمكن أن يظهر الغموض في الجمل التي تكون جيدة نحوًيا‬. Example: After the login process fails a number of times in a row, the incident should be reported in an email to the security administrator. The intention behind this statement is fine, but what does ‘a number of times’ actually mean? Two, five, a hundred? Inconsistencies ‫التناقضات‬ An inconsistency arises when parts of a solution separately make statements that make no sense when considered together. These bugs are harder to locate because each part of the inconsistency might appear. in very different contexts ‫ينشأ التناقض عندما تصدر أجزاء من الحل بشكل منفصل بيانات ال معنى لها ومن ثم‬ ‫ يصعب تحديد هذه األخطاء ألن كل جزء من التناقض قد يظهر في سياقات مختلفة تماًما‬,‫عند النظر إليها مًعا‬. Consider the example of the login process (above) rewritten as follows: After the login process fails five times in a row, this incident should be reported in an email to the security administrator. Also imagine that a different part of the solution contains the following statement: After the login process fails three times in a row, the login screen should automatically lock and refuse further login attempts. If a login attempt fails three times consecutively, the user cannot attempts. Consequently, they can never perform five login attempts in a row, so the first statement is redundant. Logical and mathematical errors ‫األخطاء الحسابية‬ Simple bugs might be found in logical expressions. Example: If x > y, then print y Otherwise if y > x, then print x Two bugs: 1. algorithm prints the minimum instead of the maximum. 2. what happens if both numbers are equal? Being exhaustive ‫الشمولية‬ Algorithms should be exhaustive and contain instructions for all conceivable outcomes. If you fail to account for any of them, the computer’s behaviour becomes unpredictable, it might : take an unwanted action or do nothing when it should do something. How to avoid some common errors: Think critically; what might go wrong Look especially at conditionals; if X is the case, what happens if X is not the case? Look especially at loops; Make sure the loop cannot go on endlessly. Mitigating Errors ‫التخفيف من االخطاء‬ What you can do to mitigate error effects: Getting defensive ‫الحصول على الدفاع‬ Reacting to problems ‫الرد على المشاكل‬ Checking user input ‫التحقق من إدخال المستخدم‬

Use Quizgecko on...
Browser
Browser