Presentation is loading. Please wait.

Presentation is loading. Please wait.

WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010.

Similar presentations


Presentation on theme: "WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010."— Presentation transcript:

1

2 WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010. They may not show up well on other PowerPoint versions. You can download PowerPoint 2010 viewer from here.here These slides contain a lot of animations. For optimal results, watch in slideshow mode.

3 ARIANE 5 launch

4 Here’s an error message Navigation instructions?

5 Here’s an error message Navigation instructions? Your teammate’s code Your code

6 Your teammate’s code Putting up defences to protect our code. CS2103/T, Lecture 7, Part 2, [Sep 30, 2016]

7 Your code Your teammate’s code Putting up defences to protect our code.

8 Lecture 7: Putting up defences to protect our code.

9 GO!

10 … int size = Config.getSize(); if( 0 < size < 5) setSizeAsSmall(); else setSizeAsBig(); … if(sizeFound()) return readSize(); else return 0; … // size > 0

11 … int size = Config.getSize(); if( 0 < size < 5) setSizeAsSmall(); else setSizeAsBig(); … if(sizeFound()) return readSize(); else return 0; … assert (size > 0)

12 … int size = Config.getSize(); if( 0 < size < 5) setSizeAsSmall(); else setSizeAsBig(); … if(sizeFound()) return readSize(); else return 0; … assert (size > 0) Make your assumptions explicit. Get the runtime to confirm them. These are different from JUnit assertions!

13

14 GO!

15

16

17 What if age is invalid? void processAge(int age); //do stuff with age } bug? Handle or raise an Exception Verify using assertion e.g. assert(isValid(age)) void foo(String fileName); openFile(fileName); } File corrupted

18 Handle or raise an Exception Developer User/environment Environment mishap? Verify using assertion e.g. assert(isValid(age)) Programmer mistake?

19 GO!

20

21 Your ToDo manager software tries to interact with Google calendar, but finds Google servers are down. This should be handled using, a)Assertions b)Exceptions c)It depends google {a|b|c} e.g. google b google {a|b|c} e.g. google b

22 Your ToDo manager software tries to interact with Google calendar, but finds Google servers are down. This should be handled using, a)Assertions b)Exceptions c)It depends

23 GO!

24 My computer crashes when I flush the toilet!

25 … int size = Config.getSize(); // size > 0 if( 0 < size < 5) log(LEVEL_INFO, “Setting size to small”); setSizeAsSmall(); else if( size > 5) setSizeAsBig(); else log(LEVEL_WARN, “size not recognized”); …

26

27

28 GO!

29

30

31 class Man{ Woman girlfriend; void setGirlfriend(Woman w){ girlfriend = w; } … class Woman{ Man boyfriend; void setBoyfriend(Man m){ boyfriend = m; } … Man Woman girlfriend boyfriend

32 class Man{ Woman girlfriend; void setGirlfriend(Woman w){ girlfriend = w; } … class Woman{ Man boyfriend; void setBoyfriend(Man m){ boyfriend = m; } … Man harry, ron; Woman hermione; ron.setGirlfriend(hermoine); hermione.setBoyfriend(harry); … ron:Man hermione :Woman harry:Man girlfriend boyfriend

33 32 What do you do when it is green light?

34 Defensive driving can save your life Assume other drivers are idiots

35 Defensive driving can save your life Assume other drivers are idiots coding career coders

36 class Man{ Woman girlfriend; void setGirlFriend(Woman w){ if(girlfriend!=null) girlfriend.breakupWith(this); girlfriend = w; girlfriend.setBoyFriend(this); } …

37

38

39

40 Bertrand Meyer, Design by Contract and the Eiffel Language

41

42 GO!

43 AssertionsExceptionsLoggingDefensive All 4 used in Sample Project. Use them more in your project.

44


Download ppt "WARNING These slides are not optimized for printing or exam preparation. These are for lecture delivery only. These slides are made for PowerPoint 2010."

Similar presentations


Ads by Google