How To Code: Simple Data Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

How to Design Functions (HtDF) recipe

A
Signature, purpose, stub
Examples (wrapped in check-expect)
Inventory - template and constants
Code body
Test and debug
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

HtDF - Signature

A

Declares what type of data a function consumes and produces

Type … -> Type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

HtDF - Purpose

A
1 line description of what the function produces in terms of what it consumes
Example:
//produce 2 times the given number
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

HtDF - Stub

A
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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

HtDF - Examples/Tests

A

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’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

HtDF - Template

A

A function with a ‘template’ for its behaviour. Think pseudo-code
Example:
(define (double_function n)
(… n))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

HtDF - Code Body

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

HtDF - Test and Debug

A

Run the tests!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

True or False - The HtDF recipe should be followed in a waterfall style, strict order

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

HtDD Recipe

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Inherent Data Structure = Atomic

A

Data Definition = Simple Atomic Data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Inherent Data Structure = numbers within a range

A

Data Definition = Interval

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Inherent Data Structure = fixed number of distinct items

A

Data Definition = Enumeration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Inherent Data Strcture = 2 or more subclasses, at least 1 is not a distinct item

A

Data Definition = Itemization

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Inherent Data Structure = items that naturally belong together

A

Data Definition = Compound Data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Inherent Data Structure = naturally composed of different parts

A

Data Definition = references to other defined type

17
Q

Inherent Data Structure = arbitrary/unknown size

A

Data Structure = self-referential or mutually referencial

18
Q

HtDD - Simple Atomic Data

A

the information to be represented is atomic (can’t be divided in more parts)

Example: time, names…

19
Q

HtDD - Intervals

A

Use an interval when the information to be represented is numbers within a certain range. ‘[’ and ‘]’ mean that the end of the interval includes the end point; ( and ) mean that the end of the interval does not include the end point.

20
Q

HtDD - Intervals: Tests

A

Be sure to test closed boundaries as well as midpoints.

21
Q

HtDD - Enumerations

A

The information to be represented consists of a fixed number of distinct items

22
Q

HtDD - Enumerations: Tests

A

At least as many tests as there are cases in the enumeration

23
Q

HtDD - Itemization

A

Data comprised of 2 or more subclasses, at least one of which is not a distinct item.

24
Q

HtDD - Itemization: Tests

A

At least as many tests as there are cases in the itemization.

25
Q

How important is designing data in designing programs?

A

Designing data is a very high point of leverage for designing programs.
There are some programs for which that’s less true.
But for a very many programs this approach

26
Q

What is the ‘!!!’ marker used for?

A

The ‘!!!’ marker in stubs makes it easy to find pending wishes

27
Q

What is a wishlist?

A

A signature comment, a purpose and a stub (marked with a ‘!!!’)

28
Q

HtDW - Domain Analysis

A
  • Sketch program scenarios
  • Identify constant information
  • Identify changing information
  • Identify big-bang options
29
Q

HtDW - Build the program

A
  • Constants (based on domain constants)
  • Data definitions using HtDD (based on
    domain ‘changing information’)
  • Functions using HtDF
    • main first (based on ‘changing information’,
      big-bang options and data definitions)
    • wish lists entries for big-bang handlers
  • Work through wish list until done
30
Q

HtDW - Recipe

A
Domain Analysis (best on paper)
Build the program (based on the analysis)
31
Q

HtDD - Compound

A

Consists of 2 or more items that naturally fit together

32
Q

HtDD - Compound: Test

A

All selectors -> (… (firework-X fw)
(firework-Y fw) )

Inside cond –> predicate (firework?)

33
Q

Well formed self-reference

A

At least one base case (with no self-reference)
At least one self reference case

(there can be more than one of each)

34
Q

Self-reference: Tests

A

Test should include all base and self-referencial cases

35
Q

Self-reference: When to use?

A

For arbitrary sized data