2b: How to Design Data Flashcards
What is a data definition?
It’s a new kind of design element.
Suppose you’re working on a program that somebody else wrote, and the program has to do with simulating traffic. What’s reasonable to expect from that code?
The code has to do with traffic lights, and cars, and trucks, and things like that.
Suppose you’re working on a program that somebody else wrote, and the program has to do with simulating traffic. What’s reasonable to expect from that code?
The code has to do with traffic lights, and cars, and trucks, and things like that.
If you came across this function while reading the program, would you think it’s clear?
(define (next-color c)
(cond [(= c 0) 2]
[(= c 1) 0]
[(= c 2) 1]
No. It’s not very clear what the function does from just looking at it (even if you followed the HtdF recipe, it wouldn’t be clear).
To understand this problem we have to understand something important about data in programs called the PROBLEM DOMAIN.
What is the problem domain?
The problem domain is the AREA where the PROBLEMS your application is intended to SOLVE, belong to. It is simply looking at only the topics you are interested in, and excluding everything else.
It is all information that defines the problem and constrains the solution (the constraints being part of the problem).
It is anything and everything that is needed to define the area under analysis, fully understand the inputs and outputs of its processes, and achieve the goals of the area under analysis, but nothing more.
What’s going on between the problem domain and the program when we design a program?
We’re playing a game where we represent information in the problem domain using data in the program.
What is a DATA DEFINITION? And where is it placed location wise?
Data Definition tells us everything we need to know about how we represent information as data. It is placed in the beginning as a first section before the 2nd section on Functions.
1- Start with a type_comment.
2- Template skeleton for 1-argument functions.
IT shows how to form data of a new type.
How to represent information as data.
How to interpret data as information.
Template for operating on data.
IT shows restrictions of data consumed and what data can be produced.
Helps generate examples.
Provides templates.
Relationship between information and data.
How is the template for a function determined?
By the TYPE of data it CONSUMES.
What is the “interpretation” step?
The interpretation should describe the correspondence between the information and data.
What should the examples do?
The examples should help us understand what the data definition represents.
How do you write the data-driven TEMPLATE?
From the Data Driven Templates page, the body of the template for atomic non-distinct data should include the parameter name after the dots. In this case, the template body should be (… cn).
How do you name predicate functions that produce a boolean value?
YOU name the predicates with a ? mark.