02-design-post3up[1]

02-design-post3up[1] - The design recipe Readings: HtDP,...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: The design recipe Readings: HtDP, sections 1-5 (ordering of topics is different in lectures, different examples will be used) Survival, Style, and Submission Guides CS 135 Winter 2012 02: The design recipe 1 Programs as communication Every program is an act of communication: Between you and the computer Between you and yourself in the future Between you and others Human-only comments in Scheme programs: from a semicolon ( ; ) to the end of the line. CS 135 Winter 2012 02: The design recipe 2 Some goals for software design Programs should be: compatible, composable, correct, durable, efficient, extensible, flexible, maintainable, portable, readable, reliable, reusable, scalable, usable, and useful. CS 135 Winter 2012 02: The design recipe 3 The design recipe Use it for every function you write in CS 135. A development process that leaves behind written explanation of the development Results in a trusted (tested) function which future readers (you or others) can understand CS 135 Winter 2012 02: The design recipe 4 The five design recipe components Contract: Describes what type of arguments the function consumes and what type of value it produces. Purpose: Describes what the function is to compute. Examples: Illustrating the use of the function. Definition: The Scheme definition (header and body) of the function. Tests: A representative set of inputs and expected outputs. CS 135 Winter 2012 02: The design recipe 5 Order of Execution The order in which you carry out the steps of the design recipe is very important. Use the following order: Write Purpose Write Examples (by hand, then code) Write Definition Header & Contract (and refine purpose with parameter names) Write Definition Body Write Tests CS 135 Winter 2012 02: The design recipe 6 Using the design recipe Well write a function which squares two numbers and sums the results. Mathematically: sum-of-squares: R R R ;; sum-of-squares: Num Num Num ;; Purpose: produces sum of squares of arg1 and arg2 ;; Examples: ( check-expect ( sum-of-squares 3 4 ) 25 ) ( check-expect ( sum-of-squares 0 2.5 ) 6.25 ) ( define ( sum-of-squares arg1 arg2 ) ( + ( * arg1 arg1 ) ( * arg2 arg2 ))) CS 135 Winter 2012 02: The design recipe 7 Contracts We will be more careful than HtDP. Num : any Scheme numeric value Int : restriction to integers Nat : restriction to natural numbers (including 0) Any : any Scheme value We will see more types soon. CS 135 Winter 2012 02: The design recipe 8 Purpose, Definition, Examples This slide has been superseded by Slide 6. CS 135 Winter 2012 02: The design recipe 9 Tests Tests should be written later than the code body....
View Full Document

This note was uploaded on 04/02/2012 for the course CS 135 taught by Professor Vasiga during the Winter '07 term at Waterloo.

Page1 / 17

02-design-post3up[1] - The design recipe Readings: HtDP,...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online