How To Code: Simple Data Flashcards
How to Design Functions (HtDF) recipe
Signature, purpose, stub Examples (wrapped in check-expect) Inventory - template and constants Code body Test and debug
HtDF - Signature
Declares what type of data a function consumes and produces
Type … -> Type
HtDF - Purpose
1 line description of what the function produces in terms of what it consumes Example: //produce 2 times the given number
HtDF - Stub
A function definition that: - Has correct name - Has correct number of parameters - Produces a dummy result of correct type Example: // Number -> Number (signature) // (define (double_function n) 0)
HtDF - Examples/Tests
Tests help us understand what a function must do
Multiple tests illustrate behaviour
Tests must be run to make sure the tests are well formed (tests should run but fail, thanks to the ‘stub’)
HtDF - Template
A function with a ‘template’ for its behaviour. Think pseudo-code
Example:
(define (double_function n)
(… n))
HtDF - Code Body
The function behaviour
Use everything written before to know how to complete the function body
Sometimes helps to elaborate the examples/tests to show how the expected value could have been produced
HtDF - Test and Debug
Run the tests!
True or False - The HtDF recipe should be followed in a waterfall style, strict order
False, the HtDF is a flexible process
Steps can be skipped if not sure which are the correct values/definitions
Also previous steps can be edited/ammended if we realize they were not correct when developing later steps
HtDD Recipe
The first step of the recipe is to identify the INHERENT STRUCTURE of the information.
Once that is done, a data definition consists of four or five elements:
1 - A STRUCTURE DEFINITION (if needed)
2- A TYPE NAME DEFINITION, to describe how to form data of that type.
3- An INTERPRETATION that describes the correspondence between info and data.
4- EXAMPLES of the data.
5- A TEMPLATE for a 1 argument function operating on data of this type.
Inherent Data Structure = Atomic
Data Definition = Simple Atomic Data
Inherent Data Structure = numbers within a range
Data Definition = Interval
Inherent Data Structure = fixed number of distinct items
Data Definition = Enumeration
Inherent Data Strcture = 2 or more subclasses, at least 1 is not a distinct item
Data Definition = Itemization
Inherent Data Structure = items that naturally belong together
Data Definition = Compound Data