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.

  1. Create your CCIS account and know your CCIS login.
  2. Start and exit Racket on your machine.
  3. Login to your CCIS GitHub account using your CCIS login.
  4. Create an empty repository in your CCIS GitHub account.
  5. Use Git to create and store a file in a repository in your CCIS GitHub account.
  6. Register with 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 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.

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:

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 and cond 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 Definitions:
(define-struct student (last first teacher))
;; A student is a (make-student Symbol Symbol Symbol)
;; INTERP: represents a student's first and last name 
;;         and the name of the their teacher

;;;; Data Examples:
;; (make-student 'Joe 'Doe 'Mary)
;; (make-student 'Mat 'Jones 'Fritz)

;;;; Deconstructor Template: 
;; student-fn: Student -> ???
;; (define (student-fn a-student a-teacher) 
;;   ... (student-last a-student) ...
;;   ... (student-first a-student) ...
;;   ... (student-teacher a-student) ...)

;; TeacherName is a Symbol
;; INTERP: represents a teacher's name 

;;;; Signature: 
;; subst-teacher : Student TeacherName -> Student

;;;; Purpose:
;; GIVEN: a student and a teacher's name 
;; RETURNS: a student structure with a new teacher name 
;;          if the teacher's name matches 'Fritz, else 
;;          return the student unchanged.

;;;; 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: 
(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:
(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))
  1. 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
    1. 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.
    2. 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. 
                
    3. 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.
                
    4. 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 a WHERE 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.
    
                     
  2. 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)
                                                                                   
  3. Deconstructor Templates. For Data Definitions that are not pre-defined or scalar you must provide a deconstructor template. As a naming convention, the deconstructor 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 deconstructor template must include:
    1. Signature: e.g., student-fn: Student -> ???
    2. The deconstructor template definition: e.g.,
       
      ;; (define (student-fn a-student a-teacher) 
      ;;   ... (student-last a-student) ...
      ;;   ... (student-first a-student) ...
      ;;   ... (student-teacher a-student) ...)
                                                                         
  4. 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.
    
    ;; subst-teacher : Student Symbol -> Student 
                            
    Your signatures is made up of
    1. The name of the function, e.g., subst-teacher, followed by a colon :.
    2. 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.
    3. An arrow -> that separates the function's inputs from the function's outputs.
    4. The Data Definition name of the output expected from calling this function.
  5. The Purpose Statement. This is a concise, two sentence English description of what the function does.
    
    ;;;; Purpose: to create a student structure with a new 
    ;;;; teacher name if the teacher's name matches 'Fritz
                            

    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 a WHERE comment. For example,
    
    ;;;; Signature:
    ;; list-sum: List<Natural> List <Natural> -> List<Natural>
    ;; WHERE: (= (length list1) (length list2))
    ;;;; Purpose:
    ;; Given two lists of the same size, adds corresponding numbers 
    ;; in list1 and list 2 and returns the results in a new list. 
    
    ;;;; Function Definition: 
    (define (list-sum list1 list2) 
      ...)
                                   
    The Argument Invariant itself can be written as a Racket expression or as an English sentence.
  6. 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)
                            
  7. 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]))
    
                            
  8. 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: represnets any Racket number excluding complex 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 is a String 
;; WHERE: if (image-color? s) then s is a valid 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)