This module is comprised of a set of tutorials and guides that will help you get setup with the tools used in the course, create your CCIS account, install Racket, install Git, and familiarize you with GitHub.
- Create your CCIS account and know your CCIS login.
- Start and exit Racket on your machine.
- Login to your CCIS GitHub account using your CCIS login.
- Create an empty repository in your CCIS GitHub account.
- Use Git to create and store a file in a repository in your CCIS GitHub account.
- Register with the Course's Piazza forum.
- Post a message on the Course's Piazza forum.
For the purposes of this class you will need to have a valid CCIS account. Please visit
CCIS
Account Creation. Click on the top right hand corner on the text Apply for an Account
and follow the instructions there in order to create your CCIS account.
Your CCIS account will provide you access to all student-available CCIS resources. See the CCIS Howto pages for information on how to access your CCIS email, create personal web pages, and the other resources available to you from the department.
For this class we will be using Racket. Download the appropriate binary for your platform (Windows, Mac, Linux) from the Racket Download site.
Once you have DrRacket intalled on your machine see the videos on DrRacket, specifically
We will be using Piazza for all email communication and online discussion. Visit the class's Piazza page and register.
If you have not used Piazza before, please read the documentation on how to use Piazza
Once you have registered on Piazza send a private message to the course staff and include the following information
- Your full name as it appears on your transcript.
- Your CCIS login name.
Be warned, if you do not send the staff this information we will not be able to confugure your account for homework assignments.
The department runs a local version of GitHub. When you created your CCIS account, you also received an acccount on the CCIS GitHub server. Use your CCIS login and password to access the CCIS GitHub Server.
We will be using Git throughout the course to both submit homework assignments and to keep track of your work. Please make sure you download and install Git for your machines:
- The Git command line tools. These do not come with a graphical application, but most documentation that you find online is based on the command line tools.
- GitHub provides a graphical program for Windows. You will have to configure GitHub for Windows to communicate with the CCIS GitHub server.
- GitHub provides a graphical program for Macs. You will have to configure GitHub for Mac to communicate with the CCIS GitHub server.
Git is a large piece of software and there are plenty of online resources about Git that you can read in order to learn Git in detail. For the purposes of this class we will use a subset of Git's features.
For a nice introduction to Git and dealing with Git conflicts, read Prof. Wand's slides on Introduction to Git and Dealing with Conflicts in Git. If you would like to learn more on Git you can read the the Git Book, available for free online.
Style Guide
Style and formatting conventions assist with writing readable and maintainable code. Following the same set of rules allows for common visual patterns that help programmers read and understand code, but also makes it easier for tools to manipulate and show differences between code without a lot of noise.
Every programming language has its own style conventions. Furthermore, groups of programmers that intend to work on a code base extend, or adapt, style conventions to better fit the programming language's syntax.
This document describes the style rules for this class. You are expected to follow the rules described here. Failure to do so will result in point deductions from your assignments.
General Style Rules
- All lines should not exceed 80 characters.
In DrRacket use
Edit -> Find Longest Line
; DrRacket will take you to the longest line in the Definitions Window, the length of the line is displayed in the bottom right corner of the DrRacket's window. -
Define global constants instead of using "magical" values.
Constants ✓
(define WIDTH 500) ;; pixels (define HEIGHT 700) ;; pixels (define BACKGROUND (empty-scene WIDTH HEIGHT))
✕
(define BACKGROUND (empty-scene 500 700))
Itemized data definitions with hardcoded values ✓
;; A TrafficLight is one of: ;; - "red" ;; - "yellow" ;; - "green" (define RED "red") (define YELLOW "yellow") (define GREEN "green") (define (red? tl) (string=? tl RED)) (define (yellow? tl) (string=? tl YELLOW)) (define (green? tl) (string=? tl GREEN)) (define (traffic-fn1 tl) (cond [(red? tl) ...] [(yellow? tl) ...] [(green? tl) ...])) (define (traffic-fn2 tl) (cond [(red? tl) ...] [(yellow? tl) ...] [(green? tl) ...])) ...
✕
;; A TrafficLight is one of: ;; - "red" ;; - "yellow" ;; - "green" (define (traffic-fn1 tl) (cond [(string=? tl "red") ...] [(string=? tl "yellow") ...] [(string=? tl "green") ...])) (define (traffic-fn2 tl) (cond [(string=? tl "red") ...] [(string=? tl "yellow") ...] [(string=? tl "green") ...])) ...
-
Simplify your code. Always strive to simplify your code.
Unnecessary if ✓
(empty? list-of-ages)
✕
(if (empty? list-of-ages) true false)
Unnecessary data structures ✓
(cons 1 some-list)
✕
(append (list 1) some-list)
-
One task, one function. Your functions should do one thing and do it well. Favour
creating smaller functions to deal with subtasks and use function composition to achieve
your final answer.
Favour small functions that perform one task ✓
(define (ball-tick b) (if (hitwall? b) (reflect (straight b SPEED)) (straight b SPEED)))
✕
(define (ball-tick b) (if (and (≤ YUP (where b) YLO) (or (≤ (ball-x b) XWALL (+ (ball-x b) (ball-dx b))) (>= (ball-x b) XWALL (+ (ball-x b) (ball-dx b))))) (make-ball (- (* 2 XWALL) (ball-x (straight b 3))) (ball-y (straight b 3)) (- (ball-dx (straight b 3))) (ball-dy (straight b 3))) (straight b 3)))
Racket Style Rules
-
Indent your code using DrRacket. Use
Racket -> Reindent All
. -
Line Breaks. The following should be on a line by themselves
- function headers
-
if
andcond
clauses
-
Parenthesis. Right (or close) parenthesis is never on a line by itself.
Right parenthesis stay on the same line as the expression they close ✓
(define (factorial n) (if (zero? n) 1 (* n (factorial (sub1 n)))))
✕
(define (factorial n) (if (zero? n) 1 (* n (factorial (sub1 n) ) ) ) )
-
Spacing. For parenthesis that do not start or end a line, always place a space
before an open parenthesis and after a closing parenthesis.
Spaces before open and after close parenthesis, unless we start or end a line ✓
(define (factorial n) (if (zero? n) 1 (* n (factorial (sub1 n)))))
✕
(define (factorial n) (if(zero? n) 1 (* n (factorial(sub1 n) ) ) ) )
Naming functions and variables
-
Always use descriptive names. You are writing code for other humans to read and
understand. Help other programmers by providing meaningful names for your functions and
variable names.
Use meaningful descriptive names ✓
(define (fahrenheit->celsius degrees-fahrenheit) (* (- degrees-fahrenheit 32) 5/9))
✕
(define (f->c d) (* (- d 32) 5/9))
-
Global Constant names are in capital letters. All of your global constants should
use all-caps for their names, e.g.,
HEIGHT
. -
Data Definition names are in CamelCase. All your Data Definition names start
with a capital letter and should be
written in CamelCase, e.g.,
TrafficLight
. -
Use hyphens to separate words in function and variable names. For function and
variable names use a hyphen ("-") to separate words, e.g.,
remove-all-out-of-bounds-rockets
-
Names of predicate functions should end with a "?". All your predicate functions
(functions that return a boolean) should have a questions mark as the suffix, e.g.,
out-of-bounds?
Design Recipe Rules
All programs that you will design in this course must follow the Program Design Recipe. These rules refine the steps by specifying how to order each step's output to improve readability.
Example program (adapted from the HtDP) designed using the Program Design Recipe |
---|
|
-
Data Analysis and Design. The first section to any program is Data Analysis and
Design. Data Definition names must be in CamelCase. All Data Definitions must be accompanied
by their interpretation. Provide your interpretation using an
INTERP
comment. Here are more specific guidelines for each kind of Data Definition-
Pre-defined Data Definitions. If
the information you are trying to capture
is already captured by a pre-defined Data
Definition, i.e., you are writing a
mathematical
function,
add1
, then you do not need to provide a new Data Definition. - Alias. When appropriate
define an alias to accurately convey the
information you are trying to capture, e.g.,
;; A Speed is a Natural ;; INTERP: represents the speed of a missile in pixels/sec. ;; A Bullet is a Posn ;; INTERP: represents the (x,y) location of a bullet in the game.
-
Structure Definitions. Data Definitions
for structures must provide the appropriate
Data Definition names for their slots. We use
the structure's constructor and assign the appropriate
Data Definition name for each slot by position, e.g.,
;; A Location is a Posn ;; INTERP: represents the (x,y) coordinate of an element on the canvas. (define-struct space-ship (location health ammunition)) ;; A SpaceShip is (make-space-ship Location Integer Natural) ;; INTERP: represents the game's space ship with ;; its current location (x,y) ;; its current health, and its current ammunition.
-
Enumerations. Enumerations must use the appropriate Data Definition names for their
items, e.g.,
;; A VisualElement is one of ;; - Bullet ;; - SpaceShip ;; INTERP: represents the two game elements, bullet and space ship, ;; that are visible on the canvas.
In some situations you will need to add a Data Invariant to your Data Definition. A Data Invariant is a condition over the data encompassed by your Data Definition. For a value to be a valid member of your Data Definition the Data Invariant must hold. You must specify and Data Invariant with aWHERE
comment. For example,(define-struct world (location width height)) ;; A Wold is (make-world Location PosInt PosInt) ;; INTERP: represents the state of the world with ;; the location of the car ;; the maximum width of the canvas ;; the maximum height of the canvas ;; WHERE: location's x coordinate is less than canvas max width, and ;; location's y coordinate is less than canvas max height.
-
Pre-defined Data Definitions. If
the information you are trying to capture
is already captured by a pre-defined Data
Definition, i.e., you are writing a
mathematical
function,
-
Data Examples. For Data Definitions that are not pre-defined, you must provide examples.
These examples will help you later on with tests and examples for your function(s).
;;;; Data Examples: ;; (make-student 'Joe 'Doe 'Mary) ;; (make-student 'Mat 'Jones 'Fritz)
-
Deconstructor Templates. For Data Definitions that are not pre-defined or scalar you must provide a
template. As a naming convention, the template name is typically the Data Definition name
of the input in lowercase, e.g.,
student
, and the suffix-fn
, e.g.,student-fn
. The template must include:-
Signature: e.g.,
student-fn: Student -> ???
-
The template definition: e.g.,
;; (define (student-fn a-student a-teacher) ;; ... (student-last a-student) ... ;; ... (student-first a-student) ... ;; ... (student-teacher a-student) ...)
-
Signature: e.g.,
-
The Function Signature. The first edition of the book calls this the contract; the
second edition of the book calls this the signature. We will be using signature.
Your signatures is made up of;; subst-teacher : Student Symbol -> Student
-
The name of the function, e.g.,
subst-teacher
, followed by a colon:
. -
The Data Definition name for each input consumed by the function separated by spaces,
e.g.,
Student Symbol
. Note that the names must match exactly with the Data Definition names. -
An arrow
->
that separates the function's inputs from the function's outputs. - The Data Definition name of the output expected from calling this function.
-
The name of the function, e.g.,
-
The Purpose Statement. This is a concise,
English description of what the
function does. Should be split into at least to parts GIVEN and RETURNS
;;;; Purpose: ;; GIVEN: a student and the substitute teacher's name ;; RETURNS: update the student's teacher if the student's ;; current teacher is Fritz, otherwise the student's ;; teacher remains unchanged
In some situations you will have to provide an Argument Invariant. An Argument Invariant is a condition over the function's inputs that must hold. We specify Argument Invariants with aWHERE
comment. For example,
The Argument Invariant itself can be written as a Racket expression or as an English sentence.;;;; Signature: ;; list-sum: ListOf
ListOf -> ListOf ;; WHERE: (= (length list1) (length list2)) ;;;; Purpose: ;; GIVEN: two lists containing numbers ;; WHERE: the two lists have the same length ;; RETURNS: a list with the result of adding elements ;; at the same index in the two lists -
Examples. You must have a number of examples of how to call your function with actual
inputs and expected outputs. A good idea is to reuse the Data Examples you already have.
;;;; Examples: ;; (subst-teacher (make-student 'Mat 'Jones 'Fritz) 'Elise) ;; = ;; (make-student 'Mat 'Jones 'Elise) ;; (subst-teacher (make-student 'Joe 'Doe 'Mary) 'Elise) ;; = ;; (make-student 'Joe 'Doe 'Mary)
-
Function Definition. The implementation of your function.
;;;; Function Definition: (define (subst-teacher a-student a-teacher) (cond [(symbol=? (student-teacher a-student) 'Fritz) (make-student (student-last a-student) (student-first a-student) a-teacher)] [else a-student]))
-
Tests. You must have ample tests for each function that you design and implement.
;;;; Tests: (check-expect (subst-teacher (make-student 'Mat 'Jones 'Fritz) 'Elise) (make-student 'Mat 'Jones 'Elise)) (check-expect (subst-teacher (make-student 'Joe 'Doe 'Mary) 'Elise) (make-student 'Joe 'Doe 'Mary))
Pre-defined Data Definitions
This is a list of pre-defined Data Definitions for the course.
;; Any
;; INTERP: represents any possible Racket value.
;; Number
;; INTERP: represents any Racket number, including imaginary and complex.
;; Real
;; INTERP: rational and irrational numbers
;; NonNegReal
;; INTERP: excludes negative reals, includes 0.
;; PosReal
;; INTERP: excludes negative reals and 0.
;; Integer
;; INTERP: represents integers, whole numbers.
;; NonNegInteger
;; INTERP: excludes negative integers, includes 0.
;; Natural
;; INTERP: same as NonNegInteger
;; PosInteger
;; INTERP: excludes negative integers and 0.
;; Boolean is one of
;; - #true
;; - #false
;; INTERP: represents true and false.
;; Char
;; INTERP: represents characters.
;; String
;; INTERP: represents strings.
;; Symbol
;; INTERP: represents symbols.
;; Image
;; INTERP: represents an image; any value for which
;; image? from 2htdp/image library returns true.
;; Color
;; INTERP: represents a color; any String value for which
;; image-color? from 2htdp/image library returns true
(define-struct posn (x y))
;; A Posn is (make-posn Real Real)
;; INTERP: represents a Cartesian Coordinate (x,y)