Liskov, who coined the term defensive programming, advocated for programs to be written with, in her words, “a streak of suspicion”, checking the validity of inputs in every procedure. Meyer, however, stresses that these checks are often not performed systematically and can be scattered in places. Hence, they can pollute codebases, hamper performance and increase complexity. Contracts to the rescue! By lifting the defensive checks to the interface level of a component, contracts concisely articulate and enforce obligations on communicating components, ensuring that each piece of a software system does its job and can rely on the others parts to do theirs.
Code written defensively remains prevalent, however, and its manual conversion to contracts is a time consuming process — but it doesn’t have to be. In this talk, I present a tool that automates the translation of legacy defensive checks in Racket programs to equivalent contracts. In particular, I will describe how the tool identifies and fixes a defensive Racket program: starting from the fully expanded form, the tool descends down the conditions looking for errors, constructs contracts from their test positions, and finally removes residual defensive code.
Bio: Peter Zhong is a rising sophomore studying computer science at Northwestern University. Thanks to his Covid-19 motivated return to home, he now gets to enjoy the beautiful Australian coastal sunrises, right before heading to bed.