Introduction to Systematic Programming - Part 1
Join the DZone community and get the full member experience.Join For Free
for those of you just tuning in, check out the “intro” to the introduction to systematic programming series here for some more background on what we’re about to get into.
if you’ve been here since last week, i’m sure you’re waiting with bated breath to hear how the first week of classes went. well, the wait is over!
week 1 consisted of 9 lessons centered around the topic of primitives in dr. racket . i’ll go through each lesson here one by one, giving a quick description of the main topic points we covered and any interesting additional tidbits i may have picked up. please remember that some terms in this class, as mentioned in post 1, are used in a different manner than most traditional programming. i’ll try to note this when i can, but in some cases, i may not even be aware of how it is used traditionally, since a lot of this is new to me as well!
lesson 1: introduction to systematic program design
the primary point covered in this first lesson is that, “computation is what makes ‘things’ happen!” this course is based on the idea that programs, and the design of programs, is what makes the majority of our “typical” 1 st world interactions possible. from food to transportation, a computer program was likely involved somewhere in the process of the product getting from production to the end user, regardless of whether the product is regarded as “technology”.
next, we reviewed the question, “what’s the ‘design method’?” in this class, the design method is defined as a structure that takes you from a poorly defined problem all the way to a well-structured solution. to me, this transcends just software development, and can be used throughout one’s daily existence if applied in a thoughtful manner.
lesson 2: expressions
dr. racket is set up such that the definitions area is above the interactions area, as you can see here:
in dr. racket, expressions are evaluated to produce values. in order to create an expression, one should utilize the following recipe:
for example, to have dr. racket compute “3+6”, you would input the following into its definitions area:
(+ 3 6)
additional notes from this section:
; designates a line to be commented out
#i designates an inexact number
lesson 3: evaluation
the rules in dr. racket to evaluate expressions are:
- an expression is a “primitive call” when it begins as (*……
with * standing for any of the primitive operators, including, but not limited to: +, -, /, *
- all the items after the operator are designated as operands
- the first step in evaluation is to reduce all operands to values
- operands are reduced to values from left to right, and from inside to outside
additional notes from this session:
remember to include spaces before operands and numbers or else your expression won’t be able to be evaluated.
lesson 4: strings & images
this lesson covered how to define strings and images, as well as some of their basic functions that the course will be using. here are some of the highlights:
“this is a string in dr. racket”
strings are considered values, and are not numbers, even if the string contains a number or numeric value.
(string-append “ada” “lovelace”) will evaluate to “adalovelace”
(string-length “apple”) will evaluate to 5
(substring “caribou” 2 4) will evaluate to ri
substring uses zero based indexing, which in layman’s terms, means that it begins counting from 0. thus, caribou would be numbered c – 0, a- 1, r-2, i-3, b-4, o-5, u-6.
substring takes the portion of the string beginning with the first operand, as well as the rest of the middle numbers, but does not include the closing operand.
in order to utilize images in the dr. racket language, the top of the program must include the line (require 2ndp/image). this references the second edition of the how to design book’s image rules.
to generate a circle
to generate a rectangle
lesson 5: constant definitions
the idea of defining a constant in dr. racket is similar, if not identical, to what i have experienced in other programming languages. generically speaking, defining a constant means giving a name to a value (that has been hard coded) to be used in the future. constants are usually defined in upper case, to differentiate them from other types of defined values.
to define a constant in dr. racket, one would use the expression: a functional example of this would be: (define width 400). this would create a named value called width that would evaluate to the number 400 when used in an expression.
additional notes from this section:
defining a constant does not equal an output value.
constants can be images. for example, (rotate 10 constant) will rotate a constant by 10 degrees.
lesson 6: function definitions
functions are the mechanism that lets you produce a different result each time you run a program, and they can be used repeatedly with any (valid) value. in my experience, similar to defining constants, this definition is true across many, if not all, programming languages. across languages, a parameter is the changeable value that is passed into the function.
using functions allows programmers to avoid the “cut and paste” trap that they may be inclined to fall into in order to review multiple values, and allows for cleaner, more concise code.
to write a function in dr. racket, the following recipe is used:
lesson 7: boolean & if expressions
boolean values are expressions that evaluate to either true or false; this result is also known as a predicate. there’s no in-between for booleans, and this is also true across the majority of programming languages.
if expressions rely on this predicate in order to branch its responses. if statements ask the program, “is this true? if so, do this. if not, do this!”. in dr. racket, an if statement is expressed as follows:
lesson 8: using the stepper
lesson 8 reviewed how to utilize a dr. racket tool called “the stepper”. this program allows the developer to evaluate their program step by step, to determine where an error may lie. it’s a great tool for those using the class, but i don’t think it’s necessary to get into too much detail here.
lesson 9: discovering primitives
what i found really interesting about lesson 9 was that its basic principles seemed counterintuitive to most other types of learning, but very indicative of how i feel about memorizing theorems and methods. as this class has its own “made up” programming language for us to use, no one is intimately familiar with the primitives (or anything, really!) we have available. the advice for this is twofold. first, we’re encouraged to “take a guess!” because the likelihood is that since programming is intuitive, we just might be right. the second suggestion is to “search & scroll”, which is explained as looking up a similar primitive and seeing what else related is available in our guidebook. as i said, i’m a huge fan of this approach, because it does not force the student to memorize countless hours of specifics, but rather allows them to dive right into the interactive work and learn along the way.
that’s it for the week 1 lessons. i think it was a really great start because i was able to refresh a lot of basic concepts, but also get a general feel for how dr. racket works. the homework assignments were pretty basic and i was able to get through them with relative ease. what i did get stuck on, for those of you who are following along as fellow course students, is that when putting in evaluation results, do not forget the “s surrounding your strings! i forgot this and i almost failed the homework quiz because of it. luckily, our week 1 quiz allows a retake, so i was able to fix my mistake and i’m happy to say i scored 100%.
Published at DZone with permission of Josh Anderson, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.