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

2 Famous Software Disaster
This shutdown occurred 36.7 seconds after launch, when the guidance system's own computer tried to convert one piece of data -- the sideways velocity of the rocket -- from a 64-bit format to a 16-bit format. Ariane 5, June 4, 1996 [ TE3201 AY1516S2 Lecture 4a ]

3 Navigation instructions?
Here’s an error message

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

5 CS2103/T, Lecture 7, Part 2, [March, 2017]
Putting up defences to protect our code. Your code Your teammate’s code CS2103/T, Lecture 7, Part 2, [March, 2017]

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

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

8 MISUNDERSTANDINGS GO!

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

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

11 These are different from JUnit assertions!
MISUNDERSTANDINGS These are different from JUnit assertions! 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.

12 MISUNDERSTANDINGS

13 MISUNDERSTANDINGS GO!

14 MISUNDERSTANDINGS GO!

15 MISUNDERSTANDINGS MISHAPS
GO! GO!

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

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

18 MISUNDERSTANDINGS MISHAPS
GO! GO!

19 MISUNDERSTANDINGS MISHAPS
GO! GO!

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

21 MISUNDERSTANDINGS MISHAPS MYSTERIES
GO! GO! GO!

22 My computer crashes when I flush the toilet!
MISUNDERSTANDINGS MISHAPS MYSTERIES My computer crashes when I flush the toilet!

23 int size = Config.getSize(); // size > 0 if( 0 < size < 5)
MISUNDERSTANDINGS MISHAPS MYSTERIES 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”);

24 MISUNDERSTANDINGS MISHAPS MYSTERIES

25 MISUNDERSTANDINGS MISHAPS MYSTERIES
GO! GO! GO!

26 MISUNDERSTANDINGS MISHAPS MYSTERIES
GO! GO! GO!

27 MISUNDERSTANDINGS MISHAPS MYSTERIES MISUSE
GO! GO! GO! GO!

28 void setGirlfriend(Woman w){ girlfriend = w; } … class Woman{
MISUNDERSTANDINGS MISHAPS MYSTERIES MISUSE class Man{ Woman girlfriend; void setGirlfriend(Woman w){ girlfriend = w; } class Woman{ Man boyfriend; void setBoyfriend(Man m){ boyfriend = m; } girlfriend Man Woman boyfriend

29 void setGirlfriend(Woman w){ girlfriend = w; } … class Woman{
MISUNDERSTANDINGS MISHAPS MYSTERIES MISUSE 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

30 What do you do when it is green light?

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

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

33 void setGirlFriend(Woman w){ if(girlfriend!=null)
MISUNDERSTANDINGS MISHAPS MYSTERIES MISUSE class Man{ Woman girlfriend; void setGirlFriend(Woman w){ if(girlfriend!=null) girlfriend.breakupWith(this); girlfriend = w; girlfriend.setBoyFriend(this); }

34 MISUNDERSTANDINGS MISHAPS MYSTERIES MISUSE

35 MISUNDERSTANDINGS MISHAPS MYSTERIES MISUSE

36 Bertrand Meyer, Design by Contract and the Eiffel Language
MISUNDERSTANDINGS MISHAPS MYSTERIES MISUSE Bertrand Meyer, Design by Contract and the Eiffel Language

37 MISUNDERSTANDINGS MISHAPS MYSTERIES MISUSE

38 MISUNDERSTANDINGS MISHAPS MYSTERIES MISUSE
GO! GO! GO! GO!

39 All 4 used in Sample Project. Use them more in your project.
MISUNDERSTANDINGS MISHAPS MYSTERIES MISUSE GO! GO! GO! GO! Assertions Exceptions Logging Defensive All 4 used in Sample Project. Use them more in your project.


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