Introduction to Systematic Programming – Part 3
Join the DZone community and get the full member experience.Join For Free
originally authored by
week 3 of introduction to systematic program design was definitely a lot more video content than i was used to from before, and i can safely say that having started watching the videos from week 4 already, it’s only going to get crazier from here on out!
that said, as always, here are the links to the starting posts from this series, in case you missed out on them:
so week 3 of class focused primarily on learning how to design data and i’ll walk you through each lesson we learned step by step as best i can. interestingly, i’ve also found that writing up these summaries assists with my own learning as well, so i hope that reading them does something similar for those of you who are my classmates!
lesson 1: cond expressions
it’s made clear to the class in this lesson that the designing of data is a point of leverage in designing programs. this is because when we each design the data, we are making, knowingly or unknowingly, decisions about how all of the functions that later operate on that data will operate.
conditional expressions, or cond expressions, allow us to program conditional behavior when there are two or more cases. this allows cond expressions to be considered “multi-armed conditionals.”
standard cond expression template:
to form a cond qa expression:
where expression 1 is the question and expression 2 is the answer.
using cond expression template to make a cond example:
the rules to evaluate conds are:
- no question/answer pair? signal an error.
- if the first question is not a value, evaluate it, replace it with its value. replace entire cond with new cond in which the first question is replaced by its value.
- if the first question is a boolean that evaluates to true, or is a statement that evaluates to else, replace the entire cond with the first answer.
- if the first question is false, drop the first question /answer pair and replace it with a new cond that does not have the first question /answer pair.
- since 1 st question is not true or false, signal an error.
additional notes from this lesson:
 are visual conventions – dr. racket processes ()s and s in the same way, but using s allows us to not get overwhelmed.
lesson 2: data definitions
first and foremost in this lesson, it’s explained that a data definition is a design element. in any program, there is a problem domain as well as data. it’s the realm of the data to take the information that is housed within the problem domain and represent it with data. essentially, data definitions describe how we represent information as data in our program. when i was watching this lesson’s video, it really reminded me of a color key that i would create in excel – taking a symbol, or color, and defining what it means to the user, or in this case, the computer, so it can interpret what the designer (me) meant.
here’s an example of a dr. racket data definition:
lesson 3: atomic non-distinct data definitions
this lesson provided a direct example of how data definitions work in practice, using the premise of designing a data definition to represent the name of a city.
points to remember:
- the parts of a data definition are in the recipe list
- there are different kinds of data definitions
- atomic means that you can’t take it apart and have it still retain any meaning in the spectrum of the problem information.
example of a data definition for atomic non-distinct:
;; cityname is string
;; interp the name of a city
(define cn1 “boston”)
(define cn2 “vancouver”)
data driven templates were covered next in the lesson, and for this same example, we would continue as follows:
lesson 4: htdf with data definition
the purpose of this lesson was to teach us how to design a function that consumes non-primitive data.
from this lesson, there were really just a few quick tips that i gleaned and i’d like to share with you:
- in the case of boolean expressions, predicates should end in a ?
- when you design with the data definition, use your examples as your guidelines.
- when a function has two cases, flesh out your template by wrapping an if statement around the template
- (most importantly!!!) don’t forget to comment out your stub when you start your code!
lesson 5: htdf x structure of data orthogonality
first of all, when i saw the title of this lesson i had no idea what it was going to be about – i pride myself on a pretty decent english vocabulary, but orthogonality was a completely new term to me. for those of you who are in the same boat, let me explain: orthogonal simply means “mostly independent”. in this case it is important because the htdf method is structured with the assumption that the data types it is working with are orthogonal, so as we learn more types of data we can implement them in our previously written functions without error. i haven’t tested this theory, mind you, but that’s what i understand it to be based on the lessons provided here!
the rest of this lesson was based around explaining this data type chart, which i think is actually pretty neat:
this chart basically walks through all the different data types and prepares us for the upcoming lessons that talk about interval, enumeration and itemization.
lesson 6: interval data definitions
interval data definitions are used when the numbers to be represented are within a certain range. key to appropriately representing this are the nuances of inclusivity and exclusivity. for example:
[1, 7] is inclusive, meaning that the numbers included in the interval are 1, 2, 3, 4, 5, 6, 7.
[1, 7), however, is exclusive, meaning that the numbers included in this interval are 1, 2, 3, 4, 5, 6.
as opposed to with cond expressions, in the case of interval data definitions,  and () produce different results.
additionally, when using interval data definitions, it’s important to utilize the following two rules:
- use the data chart to find the most appropriate recipe. go for the most specific.
- use the data definitions templates page to find the template!
lesson 7: enumeration data definitions
enumerations are used when crafting a function/program that has domain information for a fixed number of two or more distinct values. in a more real world example, because i prefer those, think of the difference between tracking grades as letter values or as percentages. letter values are much easier to represent in that there are less and they are exactly defined. however, percentages are inexact and thus cannot be defined with enumerations.
the main points to keep in mind when working with enumerations are that enumerations use the “one of” phrase in their data definition, and these items indented within the “one of” section are known as subclasses. additionally, examples become completely redundant in enumerations, because the example would literally repeat the definition itself.
lesson 8: itemization data definitions
itemization data definitions are utilized when categories with different states, with varying values and types are needed for a function/program. there must be 2 or more subclasses, at least one of which is not a single, distinct value.
it’s super important to note that when you are working with mixed data itemizations to guard the subclasses appropriately so that your function is able to run. this is necessary because a subclass that’s a boolean cannot be evaluated in the same way that a natural would be, so if you do not tell the program to check what kind of data it’s looking at, it can become confused and your program will break down. to do this, you set up a “guard”. if you’re guarding for a number, for example, you would put the following before your actual evaluation expression: (number? c).
this is used in dr. racket the same way a compiler in a more advanced language would just naturally go in and check the data type. however, in dr. racket, we have to do this manually.
lesson 9: htdf with intervals
testing when using interval data definitions is a bit more complicated than how we’ve previously been taught to write check-expects in the course so far. in the case of intervals, making sure to test both of the interval’s boundaries, as well as a midpoint, is the most important lesson disseminated in this section.
lesson 10: htdf with enumeration
as far as testing with enumerations, the key here is to test at least as many check-expects as you have subclasses. if you don’t, you’re not covering all of your possibilities!
also noted in this lesson is that you don’t need separate data definitions for separate functions, if they reside in the same program. you can reuse your data definitions!
lesson 11: htdf with itemization
in the case of itemization testing, unfortunately you have to do a bit more thinking in order to cover your bases. it’s integral to test all of your points of variance in itemizations, as well as checking any boundaries of adjoining definitions, to make sure that their behavior is as you would expect. it’s much better for you to test thoroughly and include any corner-cases that you can think of, as opposed to finishing your program, sending it to users, and then having to retroactively fix something they found that you were “too busy” to test for!
lesson 12: structure of information flow
identifying the structure of your information is a key step in your program design, because, as we said at the start of this week’s notes, the choices you make in how you craft your data will ultimately impact the options you have when crafting the code of your entire function/program.
wrapping up week 3
so in the class forums, a lot of people said this week was when class “got real.” frankly, i disagree. i think that week 3 in a lot of moocs is when there’s a pretty steep dropoff because what’s being presented goes from generalist knowledge and becomes slightly more in depth. however, again as i mentioned, i started watching the videos from week 4 and i can say with confidence that week 4 is where it’s going to “get real.” interactive programs? that’s something i can get excited about.
stay tuned for next week and you can see if i’m still hanging in with class! there’s double the video content and i’m preeeeeetty sure the homework is going to be intense!
Published at DZone with permission of Josh Anderson, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.