Department of Computer Science Roger Andersson Patrick Jungner Programming by Contract vs. Defensive Programming: A Comparison of Run-time Performance and Complexity Master’s Thesis 2003:03 Programming by Contract vs. Defensive Programming: A Comparison of Run-time Performance and Complexity Roger Andersson Patrick Jungner (cid:13)c 2003 The authors and Karlstad University This thesis is submitted in partial ful(cid:12)llment of the requirements for the Masters degree in Computer Science. All material in this thesis which is not my own work has been identi(cid:12)ed and no mate- rial is included for which a degree has previously been conferred. Roger Andersson Patrick Jungner Approved, June 17, 2003 Advisor: Donald F. Ross Examiner: Anna Brunnstro(cid:127)m iii Abstract Wehaveusedtwoknownprinciplesintodayssoftwaredevelopmentscene,namely: contract basedprogramming, advocatedbyBertrandMeyerasthecreatorofDesignbyContractTM, and Defensive Programming, described by Barbara Liskov et al. We compared two com- pilers implemented by using Programming by Contract, a contract based programming principle, and Defensive Programming. The size of each compiler is in the region of 4500 lines of code. The comparison is made by performing measurements on the code. After completion of the experiment we found no discernible di(cid:11)erence in the size or complexity of the source code of the two compilers. We did however come to the con- clusion that contract based programming should not be used without automated support. Neither of the two principles could be said to be part of the solution for creating reliable software systems unless the programmers have the discipline to follow the ideas behind the principles. v Acknowledgements We would like to thank our supervisor Donald F. Ross for all his help and guidance during the project. vii
Description: