{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

02-design-post3up[1]

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

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

View Full Document Right Arrow Icon
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
Image of page 1

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

View Full Document Right Arrow Icon
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
Image of page 2
Using the design recipe We’ll 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
Image of page 3

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

View Full Document Right Arrow Icon
Tests Tests should be written later than the code body. Tests can then handle complexities encountered while writing the body. Tests don’t need to be “big”. In fact, they should be small and directed. The number of tests and examples needed is a matter of judgement.
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern